alamb commented on code in PR #15034:
URL: https://github.com/apache/datafusion/pull/15034#discussion_r1981853516


##########
datafusion/core/tests/expr_api/mod.rs:
##########
@@ -304,6 +307,38 @@ async fn test_aggregate_ext_null_treatment() {
     .await;
 }
 
+#[tokio::test]
+async fn test_create_physical_expr() {
+    // create_physical_expr does not simplify the expression
+    // 1 + 1
+    create_expr_test(lit(1i32) + lit(2i32), "1 + 2");
+    // However, you can run the simplifier before creating the physical
+    // expression. This mimics what delta.rs and other non-sql libraries do to
+    // create predicates
+    //
+    // 1 + 1
+    create_simplified_expr_test(lit(1i32) + lit(2i32), "3");
+}
+
+#[tokio::test]
+async fn test_create_physical_expr_coercion() {
+    // create_physical_expr does apply type coercion and unwrapping in cast
+    //
+    // expect the cast on the literals
+    // compare string function to int  `id = 1`
+    create_expr_test(col("id").eq(lit(1i32)), "id@0 = CAST(1 AS Utf8)");
+    create_expr_test(lit(1i32).eq(col("id")), "CAST(1 AS Utf8) = id@0");
+    // compare int col to string literal `i = '202410'`
+    // Note this casts the column (not the field)
+    create_expr_test(col("i").eq(lit("202410")), "CAST(i@1 AS Utf8) = 202410");
+    create_expr_test(lit("202410").eq(col("i")), "202410 = CAST(i@1 AS Utf8)");
+    // however, when simplified the casts on i should removed
+    create_simplified_expr_test(col("i").eq(lit("202410")), "CAST(i@1 AS Utf8) 
= 202410");

Review Comment:
   This line should change when 
https://github.com/apache/datafusion/issues/14944 is resolved



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