Skip to content

Encapsulate encryption code more in readers - #7337

Merged
alamb merged 1 commit into
apache:mainfrom
alamb:alamb/encapsulate_encryption
Mar 27, 2025
Merged

Encapsulate encryption code more in readers#7337
alamb merged 1 commit into
apache:mainfrom
alamb:alamb/encapsulate_encryption

Conversation

@alamb

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

While trying to get the filter pushdown code in #6921 working, I keep hitting merge conflicts with encryption changes related to #cfg[encryption]

Also I had an idea described in #7111 (comment) but I don't think I did a good job explaining it and it didn't seem to work for @adamreeve (see #7111 (comment))

Thus I would like to propose a pattern of how to reduce some duplication and keep the encryption related code out of the main deocder logic

What changes are included in this PR?

Move adding CryptoContext into a method on SerializedPageReader

Are there any user-facing changes?

No, this is all internal code reorganization

@github-actionsgithub-actionsBot added the parquet Changes to the parquet crate label Mar 26, 2025
@alamb
alambforce-pushed the alamb/encapsulate_encryption branch from 0a5e90f to c1dbf29CompareMarch 26, 2025 19:27
let total_rows = rg.num_rows() as usize;
let reader = self.reader.clone();

#[cfg(feature = "encryption")]

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code I found especially hard to work with, so I was able to move it into a method called add_crypto_context and then introduce a stub that doesn't do anything by default


fn next(&mut self) -> Option<Self::Item> {
let rg_idx = self.row_groups.next()?;
impl<T: ChunkReader + 'static> ReaderPageIterator<T> {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the code that gets the next reader into its own function that returns Result<> so that I could use ? to check for errors. In the Iterator implementation, returning Option<Result<..>> meant it was akward to return the errors

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 this is so much nicer


#[cfg(feature = "encryption")]
let page_reader = page_reader.with_crypto_context(crypto_context);
let page_reader = page_reader.add_crypto_context(

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here, I removed the duplicated setup of the CryptoContext and put it in a method on the page reader

pub fn new(
reader: Arc<R>,
meta: &ColumnChunkMetaData,
column_chunk_metadata: &ColumnChunkMetaData,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed this variable for clarity (there are too many types of metadata floating around -- at least ParquetMetaData and ColumnChunkMetadata)

@alamb
alamb marked this pull request as ready for review March 26, 2025 19:31
@alamb
alamb requested a review from CopilotMarch 26, 2025 19:31

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR encapsulates the encryption context setup within the SerializedPageReader to reduce code duplication and improve maintainability for encryption-related code. Key changes include:

  • Renaming the metadata parameter from "meta" to "column_chunk_metadata" for clarity.
  • Consolidating the encryption context logic into a single method named add_crypto_context with conditional compilation.
  • Updating references to the metadata parameter across asynchronous and arrow reader modules.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

FileDescription
parquet/src/file/serialized_reader.rsRefactored functions to set up encryption context and renamed parameter.
parquet/src/arrow/async_reader/mod.rsUpdated page reader construction and streamlined encryption context setup.
parquet/src/arrow/arrow_reader/mod.rsAdjusted metadata reference and removed unused encryption imports.

@etseidletseidl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice! Thanks @alamb

@alamb

Copy link
Copy Markdown
ContributorAuthor

Thank you for the review @etseidl and @adamreeve

@alamb
alamb merged commit b30336d into apache:mainMar 27, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

parquetChanges to the parquet crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@alamb@adamreeve@etseidl