Skip to content

Commit 3956fc2

Browse files
authored
add explain sql test for optimizer rule PreCastLitInComparisonExpressions (#3320)
* add inlist test for optimizer rule PreCastLitInComparisonExpressions * fmt code
1 parent e0a765d commit 3956fc2

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

datafusion/core/tests/sql/explain_analyze.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,32 @@ async fn csv_explain_verbose() {
373373
assert_contains!(actual, "SAME TEXT AS ABOVE");
374374
}
375375

376+
#[tokio::test]
377+
async fn csv_explain_inlist_verbose() {
378+
let ctx = SessionContext::new();
379+
register_aggregate_csv_by_sql(&ctx).await;
380+
let sql = "EXPLAIN VERBOSE SELECT c1 FROM aggregate_test_100 where c2 in (1,2,4)";
381+
let actual = execute(&ctx, sql).await;
382+
383+
// Optimized by PreCastLitInComparisonExpressions rule
384+
// the data type of c2 is INT32, the type of `1,2,3,4` is INT64.
385+
// the value of `1,2,4` will be casted to INT32 and pre-calculated
386+
387+
// flatten to a single string
388+
let actual = actual.into_iter().map(|r| r.join("\t")).collect::<String>();
389+
390+
// before optimization (Int64 literals)
391+
assert_contains!(
392+
&actual,
393+
"#aggregate_test_100.c2 IN ([Int64(1), Int64(2), Int64(4)])"
394+
);
395+
// after optimization (casted to Int32)
396+
assert_contains!(
397+
&actual,
398+
"#aggregate_test_100.c2 IN ([Int32(1), Int32(2), Int32(4)])"
399+
);
400+
}
401+
376402
#[tokio::test]
377403
async fn csv_explain_verbose_plans() {
378404
// This test verify the look of each plan in its full cycle plan creation

0 commit comments

Comments
 (0)