Skip to content

Encapsulate encryption code more in readers #7337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Mar 26, 2025

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-actions github-actions bot added the parquet Changes to the parquet crate label Mar 26, 2025
@alamb alamb force-pushed the alamb/encapsulate_encryption branch from 0a5e90f to c1dbf29 Compare March 26, 2025 19:27
@@ -698,32 +696,25 @@ impl<T: ChunkReader + 'static> Iterator for ReaderPageIterator<T> {
let total_rows = rg.num_rows() as usize;
let reader = self.reader.clone();

#[cfg(feature = "encryption")]
Copy link
Contributor Author

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
Contributor Author

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
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
Contributor Author

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

@@ -571,22 +571,51 @@ impl<R: ChunkReader> SerializedPageReader<R> {
/// Creates a new serialized page reader from a chunk reader and metadata
pub fn new(
reader: Arc<R>,
meta: &ColumnChunkMetaData,
column_chunk_metadata: &ColumnChunkMetaData,
Copy link
Contributor Author

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 Copilot March 26, 2025 19:31
Copy link

@Copilot Copilot AI left a comment

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.

File Description
parquet/src/file/serialized_reader.rs Refactored functions to set up encryption context and renamed parameter.
parquet/src/arrow/async_reader/mod.rs Updated page reader construction and streamlined encryption context setup.
parquet/src/arrow/arrow_reader/mod.rs Adjusted metadata reference and removed unused encryption imports.

Copy link
Contributor

@etseidl etseidl left a comment

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
Contributor Author

alamb commented Mar 27, 2025

Thank you for the review @etseidl and @adamreeve

@alamb alamb merged commit b30336d into apache:main Mar 27, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parquet Changes to the parquet crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants