mingmwang commented on code in PR #4443:
URL: https://github.com/apache/arrow-datafusion/pull/4443#discussion_r1041728697


##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -1012,6 +1013,68 @@ pub fn table_scan(
     LogicalPlanBuilder::scan(name.unwrap_or(UNNAMED_TABLE), table_source, 
projection)
 }
 
+/// Wrap projection for a plan, if the join keys contains normal expression.
+pub fn wrap_projection_for_join_if_necessary(
+    join_keys: &[Expr],
+    input: LogicalPlan,
+) -> Result<(LogicalPlan, Vec<Column>, bool)> {
+    let input_schema = input.schema();
+    let alias_join_keys: Vec<Expr> = join_keys
+        .iter()
+        .map(|key| {
+            // The display_name() of cast expression will ignore the cast 
info, and show the inner expression name.
+            // If we do not add alais, it will throw same field name error in 
the schema when adding projection.
+            // For example:
+            //    input scan : [a, b, c],
+            //    join keys: [cast(a as int)]
+            //
+            //  then a and cast(a as int) will use the same field name - `a` 
in projection schema.

Review Comment:
   Why the `Cast` expressions ignore the cast info ? Looks like this is not the 
expected behavior. 
   I think no matter the Cast is explicit or implicit, it should display the 
cast info.
   
   
https://github.com/apache/arrow-datafusion/blob/cedb05aedf3cea030bfa8774b8575d8f4806a1c8/datafusion/expr/src/expr.rs#L1108-L1115
   
   @andygrove @liukun4515 @jackwener 
   How do you think? 
   
   



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

Reply via email to