Skip to content

refactor: unify ParquetFileReader and CachedParquetFileReader - #24036

Open
alamb wants to merge 1 commit into
apache:mainfrom
alamb:alamb/unify-parquet-file-reader
Open

refactor: unify ParquetFileReader and CachedParquetFileReader#24036
alamb wants to merge 1 commit 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 [  50.386s] (current)
     Parsing datafusion-datasource-parquet v54.1.0 (current)
      Parsed [   0.033s] (current)
    Building datafusion-datasource-parquet v54.1.0 (baseline)
       Built [  49.242s] (baseline)
     Parsing datafusion-datasource-parquet v54.1.0 (baseline)
      Parsed [   0.033s] (baseline)
    Checking datafusion-datasource-parquet v54.1.0 -> v54.1.0 (no change; assume patch)
     Checked [   0.151s] 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/e1a21a4874346164a6142dda64cc03399b2e6fdf/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/e1a21a4874346164a6142dda64cc03399b2e6fdf/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/e1a21a4874346164a6142dda64cc03399b2e6fdf/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/e1a21a4874346164a6142dda64cc03399b2e6fdf/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 [ 101.243s] datafusion-datasource-parquet

@github-actions github-actions Bot added the auto detected api change Auto detected API change label Jul 31, 2026
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

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.85%. Comparing base (dbcb5c0) to head (faa8de8).

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.85%   80.85%   -0.01%     
==========================================
  Files        1101     1101              
  Lines      374933   374916      -17     
  Branches   374933   374916      -17     
==========================================
- Hits       303166   303144      -22     
- Misses      53671    53673       +2     
- Partials    18096    18099       +3     

☔ 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.

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.

2 participants