Repository navigation
Conversation
Records the current behavior: predicates on `get_field(s, 'a')` get no pruning predicate, so every row group and page is read. Later commits update the expected output. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`PruningStatistics` lives in `datafusion-common`, which cannot name `PhysicalExpr`. Asking a statistics source for the statistics of an expression (such as `get_field(s, 'a')` or `variant_get(v, 'a')`) needs the trait to live next to `PhysicalExpr`. This is a mechanical move of `datafusion_common::pruning` to `datafusion_physical_expr_common::pruning` and an update of the imports. `datafusion_common` cannot re-export it, because `physical-expr-common` depends on it, so the old path is removed. `datafusion_pruning::PruningStatistics` keeps working. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`PruningStatistics` only returns statistics for whole columns. Add `min_values_for_expr`, `max_values_for_expr`, `null_counts_for_expr` and `contained_for_expr`, so a source can answer for an expression such as `get_field(s, 'a')` or `variant_get(v, 'a')`. The defaults return `None`, so existing implementations keep working and prune nothing for such expressions. `CompositePruningStatistics` forwards the new methods to its members. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`build_predicate_expression` takes the schema, the unhandled-predicate hook and the IN-list limit as separate arguments and passes all three to each recursive call. Struct field pruning adds one more read-only setting (which expressions have their own statistics). Bundle them in `PredicateBuildContext`. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`RequiredColumns` and `PruningExpressionBuilder` identify the statistics they read by a bare column. Pruning on `get_field(s, 'a')` or `variant_get(v, 'a')` needs statistics for an expression that is not a column. This adds an optional expression next to each required column and a `StatsKey` that `ColumnReferenceCount` returns. The statistics record batch reads expression statistics through `*_for_expr`. Every key is still a plain column, so behavior does not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`PruningPredicate` only reads statistics for columns, so a predicate on `get_field(s, 'a')` or `variant_get(v, 'a')` cannot be pruned. The pruning crate cannot know which such expressions a statistics source can answer: Parquet knows struct fields, and a variant extension knows shredded variant paths. Add `StatisticsExprMatcher`, set with `PruningPredicateBuilder::with_statistics_expr_matcher`. A matched expression that reads one column and has a non-nested type becomes one statistics key: the predicate replaces it with its statistics columns and reads them through `PruningStatistics::*_for_expr`. `RequiredColumns::single_column` returns `None` when a key is an expression. The new `single_key` returns the column or expression. No caller sets a matcher yet, so plans do not change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parquet stores statistics for every leaf column, including struct fields and shredded variant columns, but predicates on `get_field` or `variant_get` cannot use them. Add `ParquetStatisticsResolver`. A resolver says which expressions it may answer and reads their statistics from `ParquetLeafStatistics`, a view of the leaf column statistics of a file's row groups. Resolvers can come from outside DataFusion through `ParquetSource::with_statistics_resolver`. The resolvers of a scan are also the `StatisticsExprMatcher` for its pruning predicates. `GetFieldStatisticsResolver` is always present. It maps `get_field(s, 'a', ...)` to the leaf of that struct field and rejects paths through maps or lists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page index only accepts predicates whose statistics come from one column, so `s['a'] >= 85` read every page of a row group. A resolver can now name the one Parquet leaf whose pages hold an expression, through `ParquetStatisticsResolver::page_index_leaf`. The page filter prunes that leaf's pages, and `PagesPruningStatistics` answers the resolvers through `ParquetLeafStatistics`, for that leaf only, because the pages of other leaves do not line up. The page index load check uses the same leaf. The default returns `None`, so a resolver that needs several leaves (such as a shredded variant) prunes row groups only. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Show that a crate outside DataFusion can register a `ParquetStatisticsResolver` for its own function. A stand-in for a shredded `variant_get` reads bounds from the shredded `typed_value` leaf, and only uses them for row groups where the binary fallback `value` leaf is null in every row. Without the resolver, nothing is pruned. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Records the current behavior: `ORDER BY s['a'] DESC LIMIT 3` gets no pruning predicate for its dynamic filter, while the same query on a plain column does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`RowGroupPruner` re-checks row groups as a dynamic filter (such as a TopK bound) tightens. It built its pruning predicate without a statistics matcher and read statistics with the default resolvers only, so it could never prune on a struct field or a custom resolver's expression. Pass it the scan's `ParquetStatisticsResolvers` for both. The TopK slt does not change yet: its filter `s['a'] IS NULL OR ...` still becomes `true`, because `IS NULL` only accepts a column. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`IS NULL` and `IS NOT NULL` only accepted a bare column, so `get_field(s, 'a') IS NULL` became `true`. A dynamic TopK filter on a nullable key always has the shape `key IS NULL OR key > x`, so the `true` arm made the whole filter unprunable. Accept any statistics key and read its null count through `null_counts_for_expr`. For a struct field the Parquet leaf null count also counts rows where an ancestor is null, which matches `get_field`. `ORDER BY s['a'] DESC LIMIT 3` now skips 4 of 5 row groups, as the same query on a plain column does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Records the current behavior: when a file stores a struct field as INT and the table declares DOUBLE, `s['a'] > 6.5` is checked as `CAST(get_field(s, 'a') AS DOUBLE) > 6.5` and prunes nothing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The schema adapter reads a struct field whose file type differs from the table type as `CAST(get_field(s, 'a') AS T)`. The comparison rewrite only looked through casts down to a bare column, so such predicates could not be pruned when the cast stays (for example INT to DOUBLE against 6.5). `rewrite_expr_to_prunable` now takes the statistics key and stops at it, so CAST, TRY_CAST, negation and NOT over a key are handled like over a column. Order preservation is still checked for each cast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A boolean column used directly as a predicate (`WHERE flag`, `WHERE NOT flag`) is pruned with its min and max. A boolean struct field (`WHERE s['flag']`) was not, because the check only accepted a bare column and looked at the column's own type. Accept any statistics key and check the type of the key expression, since the root of a boolean struct field is a struct. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With a raised `max_in_list_size`, a 21-value IN list on `s['a']` is pruned through the per-value rewrite (one equality per value). The next commit gives it the compact form without changing the pruning result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An IN list longer than 20 values (when `max_in_list_size` allows it) is checked with one compact set-intersection test against min and max. For a struct field it fell back to one equality check per value, because the compact form only accepted a bare column. Accept any statistics key, taking the value type from the key expression. The pruning result does not change, only the size of the predicate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A predicate such as `s['a'] = 5` or `s['a'] IN (1, 2)` gives a literal guarantee that a bloom filter can check, but `LiteralGuarantee` only describes columns, so struct fields got none. Before `LiteralGuarantee::analyze` runs, each distinct matched expression is replaced with a placeholder column of a reserved name. The guarantees on placeholders are mapped back to their expressions as `ExprLiteralGuarantee`s, and `prune` checks them with `PruningStatistics::contained_for_expr`. `LiteralGuarantee` and the existing column guarantees do not change. `always_true` counts expression guarantees, so a predicate whose only pruning power is such a guarantee is kept. `literal_exprs` lists the expressions, so a source can load only the bloom filters it needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Records the current behavior: the file has bloom filters for its struct field leaves, but `s['a'] = 50` does not use them, so both row groups are read although neither holds 50. The test also checks that `!=` and values present in Int8, Date and Decimal fields keep their rows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parquet writes a bloom filter per leaf column, so struct fields have their own. DataFusion only loaded bloom filters for top-level columns, so `s['a'] = 50` could not use them. A `ParquetStatisticsResolver` can now name the leaf whose bloom filter holds the values of an expression, through `bloom_filter_leaf`. `GetFieldStatisticsResolver` names the struct field leaf. The opener loads those filters for the predicate's `literal_exprs`, and `BloomFilterStatistics` answers `contained_for_expr` from them, with the same rules as for a column: it never reports that a value is present. The default returns `None`. A shredded variant cannot use it, because some of its values may live in the binary `value` column. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adriangb
force-pushed
the
expr-stats-pruning
branch
from
November 25, 2026 05:50
0a2d9da to
16afa88
Compare
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?
GetFieldFunc#21306.variant_get) can plug in.Rationale for this change
WHERE s['a'] > 5,WHERE s['a'] = 50andORDER BY s['a'] DESC LIMIT 3read every Parquet row group, even though Parquet stores min/max, null counts and bloom filters for each struct field leaf.PruningPredicateandPruningStatisticsonly know top-level columns. The same gap blocks pruning on a shreddedvariant_get(v, 'a').What changes are included in this PR?
Literal guarantees: before
LiteralGuarantee::analyze, each matched expression is replaced with a placeholder column, and the guarantees are mapped back toExprLiteralGuarantees.LiteralGuaranteedoes not change.Review commit by commit. Each
test:commit records today's output, and the next commit's slt diff shows the change.test:slt for struct field pruningrefactor:movePruningStatisticstodatafusion-physical-expr-common(mechanical)feat:*_for_exprmethods onPruningStatisticsrefactor:PredicateBuildContextrefactor:key statistics by a column or an expressionfeat:StatisticsExprMatcherfeat:Parquet resolvers, row groupsfeat:Parquet resolvers, page indextest:a resolver from outside DataFusion (fakevariant_get)test:/feat:dynamic TopK pruner gets the resolversfeat:IS [NOT] NULL on keystest:/feat:CAST, TRY_CAST, NOT over keys (struct type drift)feat:boolean keystest:/feat:compact IN on keysfeat:literal guarantees on keystest:/feat:bloom filters on struct fieldsNot included: hash-join (
HashTableLookupExpr) filters on keys, file-level pruning (needs nestedStatistics, #20707), and a realvariant_getresolver.What is the testing strategy for this PR?
parquet_struct_field_pruning.slt:s['a'] > 15, 4 row groupss['a'] >= 85, 10 pages (page index)ORDER BY s['a'] DESC LIMIT 3, 5 row groupsINT, tableDOUBLE,s['a'] > 6.5s['a'] = 50with bloom filterss['a'] != 50, Int8/Date/Decimal equalityexpr_statistics_resolver.rs(core parquet integration test) registers a fake shredded-variant resolver from outside DataFusion: it usestyped_valuebounds only for row groups where the fallbackvalueis null in every row. Unit tests inpruning_predicate.rscover rejected shapes,single_column()/single_key(), guarantees (a = 1 OR b = 2gives none,CAST(key) = litgives none), andalways_true()with only an expression guarantee.Are there any user-facing changes?
Fewer row groups and pages are read for struct field predicates.
API changes (
api change):datafusion_common::pruningmoves todatafusion_physical_expr_common::pruning.datafusion_pruning::PruningStatisticsstill works.PruningStatistics(defaultNone).RequiredColumns::single_column()returnsNonewhen a key is an expression.single_key()is new.StatisticsExprMatcher,ExprLiteralGuarantee,ParquetStatisticsResolver,ParquetLeafStatistics,ParquetSource::with_statistics_resolver.ParquetSourcewith custom resolvers does not serialize to proto (returnsNone).Door: two-way, apart from the module move, which downstream crates will notice.
Blast radius: pruning. A wrong leaf mapping, null count or bloom check would skip row groups that hold matching rows. The null-struct, null-leaf,
!=and typed-equality slt cases target that.🤖 Generated with Claude Code