liukun4515 commented on code in PR #4666:
URL: https://github.com/apache/arrow-datafusion/pull/4666#discussion_r1053117398


##########
datafusion/core/tests/sql/joins.rs:
##########
@@ -2778,3 +2781,141 @@ async fn select_wildcard_with_expr_key_inner_join() -> 
Result<()> {
 
     Ok(())
 }
+
+#[tokio::test]
+async fn join_with_type_coercion_for_equi_expr() -> Result<()> {
+    let ctx = create_join_context("t1_id", "t2_id", false)?;
+
+    let sql = "select t1.t1_id, t1.t1_name, t2.t2_id from t1 inner join t2 on 
t1.t1_id + 11 = t2.t2_id";
+
+    // assert logical plan
+    let msg = format!("Creating logical plan for '{}'", sql);
+    let plan = ctx
+        .create_logical_plan(&("explain ".to_owned() + sql))
+        .expect(&msg);
+    let state = ctx.state();
+    let plan = state.optimize(&plan)?;
+
+    let expected = vec![
+        "Explain [plan_type:Utf8, plan:Utf8]",
+        "  Projection: t1.t1_id, t1.t1_name, t2.t2_id [t1_id:UInt32;N, 
t1_name:Utf8;N, t2_id:UInt32;N]",
+        "    Inner Join: CAST(t1.t1_id AS Int64) + Int64(11) = CAST(t2.t2_id 
AS Int64) [t1_id:UInt32;N, t1_name:Utf8;N, t2_id:UInt32;N]",

Review Comment:
   This rule just can apply to the pattern 
   ```
   expr `op` literal
   ```
   
   cc @alamb 
   
   We can file a new issue to discuss this.
   
   I must point out a problem about overflow for `add` operation, for example  
`i32::max` + `i32::max` maybe overflow.
   



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