Skip to content

refactor: unify ParquetFileReader and CachedParquetFileReader - #24036

Merged
alamb merged 4 commits into
apache:mainfrom
alamb:alamb/unify-parquet-file-reader
Aug 4, 2026
Merged

refactor: unify ParquetFileReader and CachedParquetFileReader#24036
alamb merged 4 commits into
apache:mainfrom
alamb:alamb/unify-parquet-file-reader

Conversation

@alamb

@alamb alamb commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Upstream arrow-rs is deprecating the ParquetObjectReader (see apache/arrow-rs#10308)

Not using the deprecated code involves copying some code for each existing usage, and I found that CachedParquetFileReader and ParquetFileReader are almost the same

What changes are included in this PR?

  1. unify ParquetFileReader and CachedParquetFileReader
  2. make the fields non pub

Are these changes tested?

Yes by CI

Are there any user-facing changes?

There are breaking API changes, though I think for the better (things are now encapsulated more)

@alamb alamb added the api change Changes the API exposed to users of the crate label Jul 31, 2026
@github-actions github-actions Bot added the datasource Changes to the datasource crate label Jul 31, 2026
@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

Thank you for opening this pull request!

Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch).

Details
     Cloning apache/main
    Building datafusion-datasource-parquet v54.1.0 (current)
       Built [  53.754s] (current)
     Parsing datafusion-datasource-parquet v54.1.0 (current)
      Parsed [   0.032s] (current)
    Building datafusion-datasource-parquet v54.1.0 (baseline)
       Built [  48.041s] (baseline)
     Parsing datafusion-datasource-parquet v54.1.0 (baseline)
      Parsed [   0.032s] (baseline)
    Checking datafusion-datasource-parquet v54.1.0 -> v54.1.0 (no change; assume patch)
     Checked [   0.160s] 223 checks: 219 pass, 4 fail, 0 warn, 30 skip

--- failure constructible_struct_adds_private_field: struct no longer constructible due to new private field ---

Description:
A struct constructible with a struct literal has a new non-public field. It can no longer be constructed using a struct literal outside of its crate.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/constructible_struct_adds_private_field.ron

Failed in:
  field ParquetFileReader.store in /home/runner/work/datafusion/datafusion/datafusion/datasource-parquet/src/reader.rs:203
  field ParquetFileReader.metadata_cache in /home/runner/work/datafusion/datafusion/datafusion/datasource-parquet/src/reader.rs:206
  field ParquetFileReader.metadata_size_hint in /home/runner/work/datafusion/datafusion/datafusion/datasource-parquet/src/reader.rs:207

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/struct_missing.ron

Failed in:
  struct datafusion_datasource_parquet::CachedParquetFileReader, previously in file /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/f74bc4c946e79e9f9ad1a780c035c680ab2c1b24/datafusion/datasource-parquet/src/reader.rs:240

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/struct_pub_field_missing.ron

Failed in:
  field file_metrics of struct ParquetFileReader, previously in file /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/f74bc4c946e79e9f9ad1a780c035c680ab2c1b24/datafusion/datasource-parquet/src/reader.rs:98
  field inner of struct ParquetFileReader, previously in file /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/f74bc4c946e79e9f9ad1a780c035c680ab2c1b24/datafusion/datasource-parquet/src/reader.rs:99
  field partitioned_file of struct ParquetFileReader, previously in file /home/runner/work/datafusion/datafusion/target/semver-checks/git-apache_main/f74bc4c946e79e9f9ad1a780c035c680ab2c1b24/datafusion/datasource-parquet/src/reader.rs:100

--- failure struct_pub_field_now_doc_hidden: pub struct field is now #[doc(hidden)] ---

Description:
A pub field of a pub struct is now marked #[doc(hidden)] and is no longer part of the public API.
        ref: https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html#hidden
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.49.0/src/lints/struct_pub_field_now_doc_hidden.ron

Failed in:
  field ParquetFileReader.file_metrics in file /home/runner/work/datafusion/datafusion/datafusion/datasource-parquet/src/reader.rs:201
  field ParquetFileReader.inner in file /home/runner/work/datafusion/datafusion/datafusion/datasource-parquet/src/reader.rs:201
  field ParquetFileReader.partitioned_file in file /home/runner/work/datafusion/datafusion/datafusion/datasource-parquet/src/reader.rs:201

     Summary semver requires new major version: 4 major and 0 minor checks failed
    Finished [ 103.465s] datafusion-datasource-parquet

CachedParquetFileReader duplicated ParquetFileReader's get_bytes /
get_byte_ranges implementations and differed only in whether it passed
a FileMetadataCache to DFParquetMetadata when fetching metadata. Fold
it into ParquetFileReader with an `Option<Arc<FileMetadataCache>>`
field: `None` behaves like the old uncached reader
(DefaultParquetFileReaderFactory), `Some(cache)` like the old cached
one (CachedParquetFileReaderFactory).

Also make all ParquetFileReader fields private and add file_metrics()
and partitioned_file() accessors for the two that were previously
public, narrowing the public surface now that construction goes
through ParquetFileReaderFactory.
@alamb
alamb force-pushed the alamb/unify-parquet-file-reader branch from 0573892 to faa8de8 Compare July 31, 2026 20:44
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 31, 2026
partitioned_file,
};
let reader =
ParquetFileReader::new(file_metrics.clone(), store, inner, partitioned_file);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ParquetFileReader now has a real new() method

}
}

/// Implements [`AsyncFileReader`] for a parquet file in object storage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this was all duplicated with CachedParquetFilerReader and I have unified the two

) -> BoxFuture<'a, parquet::errors::Result<Arc<ParquetMetaData>>> {
let object_meta = self.partitioned_file.object_meta.clone();
let metadata_cache = Arc::clone(&self.metadata_cache);
let metadata_cache = self.metadata_cache.clone();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is now Option<Arc<..>> so it needs a clone (rather than being able to call Arc::clone directly

@alamb
alamb marked this pull request as ready for review July 31, 2026 20:57
@codecov-commenter

codecov-commenter commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.85714% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.89%. Comparing base (bc8b1a7) to head (f580cc6).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/datasource-parquet/src/reader.rs 80.64% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24036      +/-   ##
==========================================
- Coverage   80.89%   80.89%   -0.01%     
==========================================
  Files        1102     1102              
  Lines      376196   376179      -17     
  Branches   376196   376179      -17     
==========================================
- Hits       304329   304301      -28     
- Misses      53756    53765       +9     
- Partials    18111    18113       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alamb
alamb enabled auto-merge August 4, 2026 19:50
@alamb

alamb commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the review @zhuqi-lucas

alamb added a commit to alamb/datafusion that referenced this pull request Aug 4, 2026
…24037)

## Which issue does this PR close?

- Something I noticed while working on
apache#24036

## Rationale for this change

`DFParquetMetadata` had several fields and methods with no doc comments,
or only a one-line description, making it hard to understand their
purpose without reading the implementation.

## What changes are included in this PR?

Add doc comments

## Are these changes tested?

No behavior changed, only doc comments were added; existing tests cover
the code.

## Are there any user-facing changes?

No functional changes; public API doc comments are improved.
@alamb
alamb added this pull request to the merge queue Aug 4, 2026
Merged via the queue into apache:main with commit e8015e4 Aug 4, 2026
38 checks passed
@alamb
alamb deleted the alamb/unify-parquet-file-reader branch August 4, 2026 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api change Changes the API exposed to users of the crate auto detected api change Auto detected API change datasource Changes to the datasource crate documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants