Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: add a few more dictionary unwrap tests #10335

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions datafusion/optimizer/src/unwrap_cast_in_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 13 additions & 0 deletions datafusion/sqllogictest/test_files/dictionary.slt
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down