adriangb commented on code in PR #24125:
URL: https://github.com/apache/datafusion/pull/24125#discussion_r3770064794


##########
datafusion/physical-expr-adapter/src/schema_rewriter.rs:
##########
@@ -282,13 +311,130 @@ impl DefaultPhysicalExprAdapterRewriter {
             return Ok(Transformed::yes(transformed));
         }
 
+        if let Some(transformed) = self.try_narrow_struct_cast(&expr)? {
+            return Ok(Transformed::yes(transformed));
+        }
+
         if let Some(column) = expr.downcast_ref::<Column>() {
             return self.rewrite_column(Arc::clone(&expr), column);
         }
 
         Ok(Transformed::no(expr))
     }
 
+    /// Rewrite `get_field(cast(s AS Struct<..>), 'f')` into
+    /// `cast(get_field(s, 'f') AS <type of f>)`.

Review Comment:
   Added below:
   
   ```rust
   /// Narrowing that cast is worthwhile for two reasons:
   ///
   /// 1. Reading one field should not cost a whole struct. The wide form
   ///    casts every field of the column — including ones the query never
   ///    reads — to produce a value that is immediately discarded except for
   ///    one field.
   /// 2. It keeps the column visible. Consumers throughout the codebase
   ///    pattern match on `get_field(column, 'f')` to recognise a struct
   ///    field access; a cast between the `get_field` and its column defeats
   ///    that match, and each such consumer then falls back to whatever it
   ///    does for an unrecognised expression.
   ```



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