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


##########
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:
   Yes, I think we need to consider to the `Cast`.
   1. sql can explicitly include `cast`
   2. after `infer cast`, it will generate cast.
   But I need to time to think carefully about its detail.



##########
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:
   Yes, I think we need to consider to the `Cast`.
   1. sql can explicitly include `cast`
   2. after `infer cast`, it will generate cast.
   
   But I need to time to think carefully about its detail.



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