adriangb opened a new pull request, #27852: URL: https://github.com/apache/datafusion/pull/27852
> [!NOTE] > Stacked on https://github.com/apache/datafusion/pull/27736. GitHub shows the commits of both PRs. Only the last two belong to this one: [compare view](https://github.com/adriangb/datafusion/compare/expr-stats-pruning...expr-stats-resolver-hooks). ## Which issue does this PR close? - Part of https://github.com/apache/datafusion/issues/24119 and https://github.com/apache/datafusion/issues/21306. ## Rationale for this change https://github.com/apache/datafusion/pull/27736 prunes Parquet files on struct fields. A function from another crate, such as `variant_get` on a shredded Variant, cannot use its Parquet statistics yet. It can need several leaves, and the layout can differ between files. ## What changes are included in this PR? ```diff PruningPredicate - StructFieldMatcher::bind -> StructFieldLeaf + FileStatisticsResolvers::bind + ParquetStatisticsResolver::bind(expr, file schemas) # get_field built in, others registered + -> BoundExprStatistics::statistics(kind, &dyn ParquetLeafStatistics) ``` ```rust pub trait ParquetStatisticsResolver { // Once per file. None = no statistics for `expr` in this file. fn bind(&self, expr: &Arc<dyn PhysicalExpr>, arrow_schema: &Schema, parquet_schema: &SchemaDescriptor) -> Option<Arc<dyn BoundExprStatistics>>; } pub trait BoundExprStatistics { fn statistics(&self, kind: ExprStatisticsKind, stats: &dyn ParquetLeafStatistics) -> Option<ArrayRef>; fn page_index_leaf(&self) -> Option<usize> { None } // opt in to page pruning fn bloom_filter_leaf(&self) -> Option<usize> { None } // opt in to bloom filters } ParquetSource::with_statistics_resolver(Arc::new(MyVariantResolver)) ``` | # | Commit | |---|---| | 1 | `feat:` the resolver traits. Struct fields become the built-in resolver, with the same behavior | | 2 | `test:` resolvers that use only the public API | This is a draft for discussion of the API. https://github.com/apache/datafusion/pull/26282 proposes a capability on the function for the same use case. The right shape is easier to judge with a real Variant implementation. ## What is the testing strategy for this PR? - [`expr_statistics_resolver.rs`](https://github.com/adriangb/datafusion/blob/fb598463c4e06a272fec9cf53ddd7586748d2b08/datafusion/core/tests/parquet/expr_statistics_resolver.rs): a fake `variant_get` with static and dynamic filters, and a resolver that binds in one file and not in another. - The slt output of https://github.com/apache/datafusion/pull/27736 does not change. - The extended test suite passes. ## Are there any user-facing changes? | Change | Breaking? | |---|---| | New `ParquetStatisticsResolver`, `BoundExprStatistics`, `ParquetLeafStatistics`, `ExprStatisticsKind`, `leaf_index_by_path` and `ParquetSource::with_statistics_resolver` | No | | A `ParquetSource` with a custom resolver does not serialize to proto | New limitation | 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
