gabotechs commented on code in PR #16064:
URL: https://github.com/apache/datafusion/pull/16064#discussion_r2098169086


##########
datafusion/core/src/physical_planner.rs:
##########
@@ -2711,6 +2724,47 @@ mod tests {
 
         assert_eq!(col.name(), "metric:avg");
     }
+
+    #[tokio::test]
+    async fn test_maybe_fix_nested_column_name_with_colon() {
+        let schema = Schema::new(vec![Field::new("column", DataType::Int32, 
false)]);
+        let schema_ref: SchemaRef = Arc::new(schema);
+
+        // Construct the nested expr
+        let col_expr = Arc::new(Column::new("column:1", 0)) as Arc<dyn 
PhysicalExpr>;
+        let is_not_null_expr = Arc::new(IsNotNullExpr::new(col_expr.clone()));
+
+        // Create a binary expression and put the column inside
+        let binary_expr = Arc::new(BinaryExpr::new(
+            is_not_null_expr.clone(),
+            Operator::Or,
+            is_not_null_expr.clone(),
+        )) as Arc<dyn PhysicalExpr>;
+
+        let fixed_expr =

Review Comment:
   nit: just to reinforce a bit the purpose of the test
   ```suggestion
           // Fix the column names ensuring that columns nested under 
expressions are also fixed
           let fixed_expr =
   ```



##########
datafusion/core/src/physical_planner.rs:
##########
@@ -2067,29 +2069,37 @@ fn maybe_fix_physical_column_name(
     expr: Result<Arc<dyn PhysicalExpr>>,
     input_physical_schema: &SchemaRef,
 ) -> Result<Arc<dyn PhysicalExpr>> {
-    if let Ok(e) = &expr {

Review Comment:
   nit: with just some minor tweaks we should be able to trim 2 indentation 
levels in the body of the function while saving some lines:
   <details><summary>Less indented version of the function</summary>
   
   ```rust
   fn maybe_fix_physical_column_name(
       expr: Result<Arc<dyn PhysicalExpr>>,
       input_physical_schema: &SchemaRef,
   ) -> Result<Arc<dyn PhysicalExpr>> {
       let Ok(expr) = expr else { return expr };
       expr.transform_down(|node| {
           let Some(column) = node.as_any().downcast_ref::<Column>() else {
               return Ok(Transformed::no(node));
           };
           let idx = column.index();
           let physical_field = input_physical_schema.field(idx);
           let expr_col_name = column.name();
           let physical_name = physical_field.name();
   
           if expr_col_name != physical_name {
               // handle edge cases where the physical_name contains ':'.
               let colon_count = physical_name.matches(':').count();
               let mut splits = expr_col_name.match_indices(':');
               let split_pos = splits.nth(colon_count);
   
               if let Some((i, _)) = split_pos {
                   let base_name = &expr_col_name[..i];
                   if base_name == physical_name {
                       let updated_column = Column::new(physical_name, idx);
                       return Ok(Transformed::yes(Arc::new(updated_column)));
                   }
               }
           }
   
           // If names already match or fix is not possible, just leave it as 
it is
           Ok(Transformed::no(node))
       })
       .data()
   }
   ```
   </details>



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to