From f190b2454de66e46135299d2a6a9a96ce9503302 Mon Sep 17 00:00:00 2001 From: wiedld Date: Mon, 18 Mar 2024 23:49:39 -0700 Subject: [PATCH] test(9678): reproducer for optimizer error (in common_subexpr_eliminate), as seen in other test case --- .../test_files/common_subexpr_eliminate.slt | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/datafusion/sqllogictest/test_files/common_subexpr_eliminate.slt b/datafusion/sqllogictest/test_files/common_subexpr_eliminate.slt index 33e87f43f7aa..272b21f029e9 100644 --- a/datafusion/sqllogictest/test_files/common_subexpr_eliminate.slt +++ b/datafusion/sqllogictest/test_files/common_subexpr_eliminate.slt @@ -49,3 +49,56 @@ query RRR rowsort select f64, case when f64 > 0 then 1.0 / f64 else null end, acos(case when f64 > 0 then 1.0 / f64 else null end) from doubles; ---- 10.1 0.09900990099 1.471623942989 + + +statement ok +CREATE EXTERNAL TABLE aggregate_test_100 ( + c1 VARCHAR NOT NULL, + c2 TINYINT NOT NULL, + c3 SMALLINT NOT NULL, + c4 SMALLINT, + c5 INT, + c6 BIGINT NOT NULL, + c7 SMALLINT NOT NULL, + c8 INT NOT NULL, + c9 BIGINT UNSIGNED NOT NULL, + c10 VARCHAR NOT NULL, + c11 FLOAT NOT NULL, + c12 DOUBLE NOT NULL, + c13 VARCHAR NOT NULL +) +STORED AS CSV +WITH HEADER ROW +LOCATION '../../testing/data/csv/aggregate_test_100.csv' + +# starting complex expression +query TIB +SELECT DISTINCT ON (chr(ascii(c1) + 3), c2 % 2) chr(ascii(upper(c1)) + 3), c2 % 2, c3 > 80 +FROM aggregate_test_100 +WHERE c1 IN ('a', 'b') +ORDER BY chr(ascii(c1) + 3), c2 % 2, c3 DESC; +---- +D 0 false +D 1 true +E 0 false +E 1 false + +# BUG: fix this +# added to boolean expr in the projections `AND c2 % 2 = 1` +# `Error during planning: No function matches the given name and argument types 'chr(Utf8)'` +# +query error DataFusion error: Optimizer rule 'common_sub_expression_eliminate' failed +SELECT DISTINCT ON (chr(ascii(c1) + 3), c2 % 2) chr(ascii(upper(c1)) + 3), c2 % 2, c3 > 80 AND c2 % 2 = 1 +FROM aggregate_test_100 +WHERE c1 IN ('a', 'b') +ORDER BY chr(ascii(c1) + 3), c2 % 2, c3 DESC; + +# The projection `c2 % 2 = 1` is fine. +query B +SELECT c2 % 2 = 1 +FROM aggregate_test_100 +WHERE c1 IN ('a', 'b') +ORDER BY chr(ascii(c1) + 3), c2 % 2, c3 DESC +LIMIT 1; +---- +false \ No newline at end of file