jayzhan211 commented on code in PR #27779: URL: https://github.com/apache/datafusion/pull/27779#discussion_r4731474994
########## datafusion/sqllogictest/test_files/subquery_decorrelation.slt: ########## @@ -995,3 +995,181 @@ DROP TABLE t; statement ok RESET datafusion.execution.batch_size; + +# https://github.com/apache/datafusion/issues/5492#issuecomment-6395684651 +statement ok +CREATE TABLE t1(a INT, b INT, c INT) AS VALUES +(1, 1, 1), +(1, 2, NULL), +(2, 2, 3), +(2, NULL, 1), +(3, 1, 2), +(NULL, 2, 2), +(4, 4, 4), +(1, 1, 1); + +statement ok +CREATE TABLE t2(a INT, b INT, c INT) AS VALUES +(1, 1, 5), +(1, 3, NULL), +(2, 2, 1), +(2, 2, 2), +(NULL, 1, 3), +(3, NULL, 1), +(5, 5, 5), +(1, NULL, 2); + +statement ok +CREATE TABLE t3(a INT, b INT, c INT) AS VALUES +(1, 2, 1), +(2, 1, NULL), +(2, 2, 2), +(NULL, NULL, 1), +(3, 3, 3), +(1, 1, 2); + Review Comment: Optional cleanup: `t3` isn't read by any of the new queries, so these lines and the `DROP TABLE t3` at the end of the file can go. A reader then doesn't have to look for the case that uses it. ```suggestion ``` ########## datafusion/sqllogictest/test_files/subquery_decorrelation.slt: ########## @@ -995,3 +995,181 @@ DROP TABLE t; statement ok RESET datafusion.execution.batch_size; + +# https://github.com/apache/datafusion/issues/5492#issuecomment-6395684651 +statement ok +CREATE TABLE t1(a INT, b INT, c INT) AS VALUES +(1, 1, 1), +(1, 2, NULL), +(2, 2, 3), +(2, NULL, 1), +(3, 1, 2), +(NULL, 2, 2), +(4, 4, 4), +(1, 1, 1); + +statement ok +CREATE TABLE t2(a INT, b INT, c INT) AS VALUES +(1, 1, 5), +(1, 3, NULL), +(2, 2, 1), +(2, 2, 2), +(NULL, 1, 3), +(3, NULL, 1), +(5, 5, 5), +(1, NULL, 2); + +statement ok +CREATE TABLE t3(a INT, b INT, c INT) AS VALUES +(1, 2, 1), +(2, 1, NULL), +(2, 2, 2), +(NULL, NULL, 1), +(3, 3, 3), +(1, 1, 2); + +# scalar_subquery_derived_table_redefines_correlated_column +# Fails today. Expected (DuckDB): +# 1 0 +# 1 2 +# 1 2 +# 2 1 +# 2 2 +# 3 2 +# 4 0 +# NULL 2 +query error Schema contains qualified field name t2\.c and unqualified field name c which would be ambiguous +SELECT t1.a, (SELECT count(*) FROM (SELECT a, b + 1 AS c FROM t2 WHERE t2.c = t1.c) x) AS v FROM t1; Review Comment: Optional cleanup: the plain-text form also shows which rule fails (`scalar_subquery_to_join` here, `decorrelate_predicate_subquery` and `decorrelate_lateral_join` for the next two). That helps the later PRs see which rule each case is waiting on, and it drops the `\.` escape. I ran the file with this form for all three cases (filled in with `--complete`), and it passes. ```suggestion query error SELECT t1.a, (SELECT count(*) FROM (SELECT a, b + 1 AS c FROM t2 WHERE t2.c = t1.c) x) AS v FROM t1; ---- DataFusion error: Optimizer rule 'scalar_subquery_to_join' failed caused by Schema error: Schema contains qualified field name t2.c and unqualified field name c which would be ambiguous ``` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
