cetra3 commented on code in PR #27734:
URL: https://github.com/apache/datafusion/pull/27734#discussion_r4714870660


##########
datafusion/pruning/src/pruning_predicate.rs:
##########
@@ -1376,6 +1477,83 @@ fn rewrite_column_expr(
     .data()
 }
 
+/// Replaces every `get_field(column, path...)` in `e` with `column_new`.
+fn rewrite_field_expr(
+    e: Arc<dyn PhysicalExpr>,
+    column: &phys_expr::Column,
+    path: &[String],
+    column_new: &phys_expr::Column,
+) -> Result<Arc<dyn PhysicalExpr>> {
+    e.transform_down(|expr| {
+        if let Some((c, p)) = struct_field_access(&expr)
+            && &c == column
+            && p == path
+        {
+            return Ok(Transformed::new(
+                Arc::new(column_new.clone()),
+                true,
+                TreeNodeRecursion::Jump,
+            ));
+        }
+        Ok(Transformed::no(expr))
+    })
+    .data()
+}
+
+/// Returns the root column and field path of a struct field access
+/// `get_field(column, 'a', 'b', ...)`, including chained calls such as
+/// `get_field(get_field(column, 'a'), 'b')`.
+///
+/// `datafusion-pruning` does not depend on `datafusion-functions`, so this
+/// matches the function by name. A function-agnostic field accessor trait
+/// would also let other accessors (such as `variant_get`) opt in.
+fn struct_field_access(
+    expr: &Arc<dyn PhysicalExpr>,
+) -> Option<(phys_expr::Column, Vec<String>)> {
+    let func = expr.downcast_ref::<ScalarFunctionExpr>()?;
+    if func.name() != "get_field" {

Review Comment:
   Checking via the function name being `"get_field"` feels a little janky. If 
#26282 is also merged it would make this easier: `as_nested_input_access()` 
plus `required_fields` gives you the column and path without naming the 
function, and `get_field` already decides there which keys are struct fields vs 
map lookups. It feels like this PR strengthens the case for the 
`NestedInputAccess` trait.



##########
datafusion/pruning/src/pruning_predicate.rs:
##########
@@ -857,6 +859,10 @@ pub struct RequiredColumns {
     /// * The field the statistics value should be placed in for
     ///   pruning predicate evaluation (e.g. `min_value` or `max_value`)
     columns: Vec<(phys_expr::Column, StatisticsType, Field)>,
+    /// The struct field path of each entry in `columns`, at the same index.
+    /// An empty path means the statistics are for the column itself. A
+    /// non-empty path means `get_field(column, path...)`.
+    field_paths: Vec<Vec<String>>,

Review Comment:
   `iter()` is public and still yields `(Column, StatisticsType, Field)`, so a 
caller iterating the required columns sees `(s, Min, "s.a_min")` and can't tell 
it from a statistic for `s` itself. Worth a public accessor for the path?



##########
datafusion/common/src/pruning.rs:
##########
@@ -127,6 +127,47 @@ pub trait PruningStatistics {
         column: &Column,
         values: &HashSet<ScalarValue>,
     ) -> Option<BooleanArray>;
+
+    /// Return the minimum values for the struct field reached from `column`
+    /// by `path`, if known.
+    ///
+    /// For example, `get_field(s, 'a', 'b')` has `column` `s` and `path`
+    /// `["a", "b"]`. The path is never empty. The contract matches
+    /// [`Self::min_values`].
+    ///
+    /// The default returns `None`, so pruning keeps every container.
+    fn min_values_for_field(

Review Comment:
   On path vs expression: I'd lean towards the expression. A column + path 
covers accessors whose output statistics are one leaf's statistics. A shredded 
Variant accessor reads several leaves (`typed_value` plus the fallback `value`) 
and has to combine them, which a path can't express. With an expression-keyed 
method, the Parquet source could answer it through 
`NestedInputAccess::output_statistics` from #26282, and that PR would no longer 
need its placeholder-column rewrite to get around `PruningPredicate` only 
understanding columns. The two PRs look complementary to me in that shape: this 
one is how pruning asks for non-column statistics, that one is how a function 
describes them.



-- 
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]

Reply via email to