perf: unwrap identity casts in schema adapter to enable Parquet stats pruning#4730
Merged
Conversation
2 tasks
andygrove
approved these changes
Jun 25, 2026
andygrove
left a comment
Member
There was a problem hiding this comment.
Nice catch . Thanks @mbutrovich
Contributor
Author
|
On TPC-DS Q99, for example, we can see the effect of these filters now firing. PR #4730: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Which issue does this PR close?
Closes #.
Rationale for this change
DataFusion's default
PhysicalExprAdapterinserts aCastExpraround every Column reference whenever the logical and physical Arrow Fields differ in any attribute, including metadata-only or nullability-only mismatches. DataFusion itself absorbs this because itsPruningPredicateanalyzer recognizes its ownCastExprand peels it to resolve the column against parquet statistics.Comet's
SparkPhysicalExprAdapter::replace_with_spark_castthen swaps thatCastExprfor adatafusion_comet_spark_expr::Castbecause Spark cast semantics diverge from arrow-cast for overflow, null handling, ANSI mode, etc. The SparkCastis a differentPhysicalExprtype that DataFusion's pruning analyzer does not understand, sobuild_pruning_predicatesreturnsNoneat file open time and no row groups are pruned. With Spark range-derived schemas (non-nullable logical) read from Parquet (nullable physical), this fires on every column reference, silently disabling row-group and page-index stats pruning.For identical source and target data types there is no Spark-specific cast semantics to preserve, so the swap costs us pruning for no benefit.
What changes are included in this PR?
SparkPhysicalExprAdapter::replace_with_spark_castnow skips the SparkCastwrap when the physical and target data types are equal. Unwrapping is safe because aCastwith equal source and target types is a value-level identity (it does not null-strip or enforce non-null), and Arrow field nullability and metadata are informational, not computational.How are these changes tested?
CometNativeReaderSuiteadds a regression test that writes a 1000-row Parquet file withparquet.block.size=1024, asserts more than one row group viaParquetFileReader, then runsSELECT ... WHERE c1 > 500and asserts the scan'snumOutputRowsis strictly less than 1000. Without the fix the scan reads all rows; with the fix row groups whose max is at most 500 are pruned.