This is an automated email from the ASF dual-hosted git repository.

jayzhan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 286eb3445d Minor: add a few more dictionary unwrap tests (#10335)
286eb3445d is described below

commit 286eb3445d1b78661c32fea4c14ac5c59559f82d
Author: Andrew Lamb <[email protected]>
AuthorDate: Wed May 1 22:25:26 2024 -0400

    Minor: add a few more dictionary unwrap tests (#10335)
    
    * Minor: add a few more dictionary unwrap tests
    
    * mt
---
 datafusion/optimizer/src/unwrap_cast_in_comparison.rs | 14 ++++++++++++--
 datafusion/sqllogictest/test_files/dictionary.slt     | 13 +++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs 
b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
index 293a694d68..07a946c1ad 100644
--- a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
+++ b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs
@@ -623,15 +623,25 @@ mod tests {
 
         // cast(tag as Utf8) = Utf8('value') => tag = arrow_cast('value', 
'Dictionary<Int32, Utf8>')
         let expr_input = cast(col("tag"), DataType::Utf8).eq(lit("value"));
-        let expected = col("tag").eq(lit(dict));
+        let expected = col("tag").eq(lit(dict.clone()));
         assert_eq!(optimize_test(expr_input, &schema), expected);
 
+        // Verify reversed argument order
+        // arrow_cast('value', 'Dictionary<Int32, Utf8>') = cast(str1 as 
Dictionary<Int32, Utf8>) => Utf8('value1') = str1
+        let expr_input = lit(dict.clone()).eq(cast(col("str1"), 
dict.data_type()));
+        let expected = lit("value").eq(col("str1"));
+        assert_eq!(optimize_test(expr_input, &schema), expected);
+    }
+
+    #[test]
+    fn test_unwrap_cast_comparison_large_string() {
+        let schema = expr_test_schema();
         // cast(largestr as Dictionary<Int32, LargeUtf8>) = 
arrow_cast('value', 'Dictionary<Int32, LargeUtf8>') => str1 = 
LargeUtf8('value1')
         let dict = ScalarValue::Dictionary(
             Box::new(DataType::Int32),
             Box::new(ScalarValue::LargeUtf8(Some("value".to_owned()))),
         );
-        let expr_input = cast(col("largestr"), dict.data_type()).eq(lit(dict));
+        let expr_input = cast(col("largestr"), 
dict.data_type()).eq(lit(dict.clone()));
         let expected =
             
col("largestr").eq(lit(ScalarValue::LargeUtf8(Some("value".to_owned()))));
         assert_eq!(optimize_test(expr_input, &schema), expected);
diff --git a/datafusion/sqllogictest/test_files/dictionary.slt 
b/datafusion/sqllogictest/test_files/dictionary.slt
index 7e45f5e444..ec8a514885 100644
--- a/datafusion/sqllogictest/test_files/dictionary.slt
+++ b/datafusion/sqllogictest/test_files/dictionary.slt
@@ -414,6 +414,19 @@ physical_plan
 02)--FilterExec: column2@1 = 1
 03)----MemoryExec: partitions=1, partition_sizes=[1]
 
+# try literal = col to verify order doesn't matter
+# filter should not cast column2
+query TT
+explain SELECT * from test where '1' = column2
+----
+logical_plan
+01)Filter: test.column2 = Dictionary(Int32, Utf8("1"))
+02)--TableScan: test projection=[column1, column2]
+physical_plan
+01)CoalesceBatchesExec: target_batch_size=8192
+02)--FilterExec: column2@1 = 1
+03)----MemoryExec: partitions=1, partition_sizes=[1]
+
 
 # Now query using an integer which must be coerced into a dictionary string
 query T?


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to