ygf11 commented on code in PR #4602:
URL: https://github.com/apache/arrow-datafusion/pull/4602#discussion_r1048360204


##########
datafusion/core/tests/sql/joins.rs:
##########
@@ -2448,3 +2492,289 @@ async fn reduce_cross_join_with_wildcard_and_expr() -> 
Result<()> {
 
     Ok(())
 }
+
+#[tokio::test]
+async fn both_side_expr_key_inner_join() -> Result<()> {
+    let test_repartition_joins = vec![true, false];
+    for repartition_joins in test_repartition_joins {
+        let ctx = create_join_context("t1_id", "t2_id", repartition_joins)?;
+
+        let sql = "SELECT t1.t1_id, t2.t2_id, t1.t1_name \
+                         FROM t1 \
+                         INNER JOIN t2 \
+                         ON t1.t1_id + cast(12 as INT UNSIGNED)  = t2.t2_id + 
cast(1 as INT UNSIGNED)";
+
+        let msg = format!("Creating logical plan for '{}'", sql);
+        let plan = ctx.create_logical_plan(sql).expect(&msg);
+        let state = ctx.state();
+        let logical_plan = state.optimize(&plan)?;
+        let physical_plan = state.create_physical_plan(&logical_plan).await?;
+
+        let expected = if repartition_joins {
+            vec![
+                "ProjectionExec: expr=[t1_id@0 as t1_id, t2_id@2 as t2_id, 
t1_name@1 as t1_name]",
+                "  ProjectionExec: expr=[t1_id@0 as t1_id, t1_name@1 as 
t1_name, t2_id@3 as t2_id]",

Review Comment:
   It seems merging projection does not consider the ordering also.



##########
datafusion/core/tests/sql/joins.rs:
##########
@@ -2432,6 +2428,54 @@ async fn reduce_cross_join_with_wildcard_and_expr() -> 
Result<()> {
             "\n\nexpected:\n\n{:#?}\nactual:\n\n{:#?}\n\n",
             expected, actual
         );
+
+        // assert physical plan
+        let msg = format!("Creating physical plan for '{}'", sql);
+        let plan = ctx.create_logical_plan(sql).expect(&msg);
+        let state = ctx.state();
+        let logical_plan = state.optimize(&plan)?;
+        let physical_plan = state.create_physical_plan(&logical_plan).await?;
+        let expected = if repartition_joins {
+            vec![
+                "ProjectionExec: expr=[t1_id@0 as t1_id, t1_name@1 as t1_name, 
t1_int@2 as t1_int, t2_id@3 as t2_id, t2_name@4 as t2_name, t2_int@5 as t2_int, 
CAST(t1_id@0 AS Int64) + 11 as t1.t1_id + Int64(11)]",
+                "  ProjectionExec: expr=[t1_id@0 as t1_id, t1_name@1 as 
t1_name, t1_int@2 as t1_int, t2_id@4 as t2_id, t2_name@5 as t2_name, t2_int@6 
as t2_int]",
+                "    CoalesceBatchesExec: target_batch_size=4096",
+                "      HashJoinExec: mode=Partitioned, join_type=Inner, 
on=[(Column { name: \"t1.t1_id + Int64(11)\", index: 3 }, Column { name: 
\"CAST(t2.t2_id AS Int64)\", index: 3 })]",
+                "        CoalesceBatchesExec: target_batch_size=4096",
+                "          RepartitionExec: partitioning=Hash([Column { name: 
\"t1.t1_id + Int64(11)\", index: 3 }], 2)",
+                "            ProjectionExec: expr=[t1_id@0 as t1_id, t1_name@1 
as t1_name, t1_int@2 as t1_int, CAST(t1_id@0 AS Int64) + 11 as t1.t1_id + 
Int64(11)]",
+                "              RepartitionExec: 
partitioning=RoundRobinBatch(2)",

Review Comment:
   The name in join and projection matches now, both are `t1.t1_id + Int64(11)`.
   cc @liukun4515 



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