Skip to content

feat: allow downcasting ParquetFileReaderFactory - #26635

Merged
alamb merged 1 commit into
apache:mainfrom
morristai:parquet-reader-factory-downcast
Nov 13, 2026
Merged

alamb merged 1 commit into
apache:mainfrom
morristai:parquet-reader-factory-downcast

Conversation

@morristai

@morristai morristai commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

There is no way to tell which reader factory a ParquetSource uses. parquet_file_reader_factory() returns &Arc<dyn ParquetFileReaderFactory>, and the trait has no downcast path.

What changes are included in this PR?

ParquetFileReaderFactory gets Any as a supertrait, and dyn ParquetFileReaderFactory gets is and downcast_ref, like dyn FileSource in #21576. I also added a 57.0.0 upgrade guide entry, like the ones for MemoryPool (#21803) and QueryPlanner (#22241).

What is the testing strategy for this PR?

A unit test in source.rs sets each built-in factory on a ParquetSource and checks that parquet_file_reader_factory() downcasts to it.

Are there any user-facing changes?

Two new methods on dyn ParquetFileReaderFactory. The semver check will flag the new supertrait, but the trait already required 'static, so existing implementations compile unchanged.

Drafted with Claude. I reviewed the change and this text.

🤖 Generated with Claude Code

@github-actions github-actions Bot added documentation Improvements or additions to documentation datasource Changes to the datasource crate auto detected api change Auto detected API change labels Oct 23, 2026
@morristai
morristai force-pushed the parquet-reader-factory-downcast branch from d36ed93 to c9c6138 Compare November 4, 2026 09:06
@github-actions github-actions Bot removed the auto detected api change Auto detected API change label Nov 4, 2026
@morristai
morristai force-pushed the parquet-reader-factory-downcast branch from a0599b6 to aa2ab01 Compare November 9, 2026 22:26

@kosiew kosiew 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.

@morristai,

Thanks for adding concrete-type inspection to ParquetFileReaderFactory. The approach is sound and appropriately scoped. Extending the trait with Any provides a reliable way to identify built-in factories without changing reader execution or requiring existing implementations to change.

The architectural boundary is important for downstream scan rewrites: replacing a Parquet reader is safe only when the replacement can preserve the original reader's semantics. Concrete type identity provides a dependable basis for recognizing supported factories, unlike Debug formatting, which is neither stable nor authoritative. Keeping this capability on the owning trait also avoids introducing a parallel classification mechanism.

I found no blocking correctness issues. I've left a few non-blocking suggestions to strengthen regression coverage and place the upgrade note in the correct release guide.

DefaultParquetFileReaderFactory::new(Arc::clone(&store)),
));
let factory = source.parquet_file_reader_factory().unwrap();
assert!(factory.is::<DefaultParquetFileReaderFactory>());

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.

Consider adding downcast_ref::<DefaultParquetFileReaderFactory>().is_some() here, and optionally the equivalent cached-factory assertion. The tests currently exercise only unsuccessful downcasts, so an implementation that always returns None would still pass.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

assert!(
factory
.downcast_ref::<DefaultParquetFileReaderFactory>()
.is_none()

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.

As optional issue-specific coverage, consider testing a custom factory whose Debug output resembles a built-in factory. Assert that both built-in is::<T>() checks return false and that downcasting to the custom type succeeds, documenting the false-positive scenario from issue #26633 without requiring file I/O.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done


See [issue #18235](https://github.com/apache/datafusion/issues/18235) for details.

### `ParquetFileReaderFactory` adds `Any` as a supertrait

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.

Could you move this entry to the 57.0.0 upgrade guide? The workspace is already at 57.0.0-dev (Cargo.toml:72), so documenting this API addition under 56.0.0 attributes it to the wrong release. The 57 guide does not yet exist in this checkout, so it would need to be created and registered using the existing upgrade-guide structure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done

@morristai
morristai force-pushed the parquet-reader-factory-downcast branch from aa2ab01 to d1873e9 Compare November 12, 2026 15:22
@morristai
morristai requested a review from kosiew November 12, 2026 15:35
Add an `Any` supertrait to `ParquetFileReaderFactory` and the `is` and
`downcast_ref` methods that `dyn FileSource` has, so code that inspects
a `ParquetSource` can tell `DefaultParquetFileReaderFactory` and
`CachedParquetFileReaderFactory` from a caller-provided factory.

The trait already required `'static`, which `Any` implies, so existing
implementations compile unchanged; the explicit `'static` is dropped to
match the other `Any` supertraits. The 57.0.0 upgrade guide notes the
new supertrait.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@morristai
morristai force-pushed the parquet-reader-factory-downcast branch from d1873e9 to 7f3d86e Compare November 13, 2026 04:37

@kosiew kosiew 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.

@morristai, thanks for addressing the review feedback. The updated tests now cover successful downcasts for both built-in factories, cross-type rejection, and a custom factory with misleading Debug output. The upgrade note also targets the correct 57.0.0 release.

Using Any for concrete type checks is the right boundary. It lets plan rewrites identify supported reader factories without relying on Debug formatting. This matters because custom factories may change file contents, metadata, caching, or credentials, so they must not be treated as equivalent to built-in factories.

The follow-up addresses the previous concerns. The regression tests verify the type checks without requiring file I/O, and the documentation reflects the public API change. I found no remaining blocking issues. Approved.

@alamb alamb 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 good to me -- thank you @morristai and @kosiew

@alamb alamb added the api change Changes the API exposed to users of the crate label Nov 13, 2026
@alamb
alamb added this pull request to the merge queue Nov 13, 2026
Merged via the queue into apache:main with commit 9f89821 Nov 13, 2026
44 checks passed
@morristai
morristai deleted the parquet-reader-factory-downcast branch November 13, 2026 20:51
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 datasource Changes to the datasource crate documentation Improvements or additions to documentation v57.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow downcasting ParquetFileReaderFactory like FileSource and DataSource

3 participants