mohammadnaqvi04 commented on code in PR #25008: URL: https://github.com/apache/datafusion/pull/25008#discussion_r4000374843
########## datafusion/sqllogictest/test_files/subquery.slt: ########## @@ -1138,6 +1138,83 @@ select t1.t1_int from t1 where ( 2 4 +# correlated_exists_groupless_count_agg_count_bug +query II rowsort +SELECT t1_id, t1_int FROM t1 WHERE EXISTS (SELECT count(*) FROM t2 WHERE t1.t1_id = t2.t2_id) +---- +11 1 +22 2 +33 3 +44 4 + +# correlated_exists_groupless_count_agg_count_bug_having +query TT +explain SELECT t1_id, t1_int FROM t1 WHERE EXISTS (SELECT count(*) FROM t2 WHERE t1.t1_id = t2.t2_id HAVING count(*) = 0) +---- +logical_plan +01)Projection: t1.t1_id, t1.t1_int +02)--Filter: __correlated_sq_1.__always_true IS NULL OR __correlated_sq_1.__always_true IS NOT NULL AND (__correlated_sq_1.count(Int64(1)) != Int64(0)) IS DISTINCT FROM Boolean(true) +03)----Projection: t1.t1_id, t1.t1_int, __correlated_sq_1.count(Int64(1)), __correlated_sq_1.__always_true +04)------Left Join: t1.t1_id = __correlated_sq_1.t2_id +05)--------TableScan: t1 projection=[t1_id, t1_int] +06)--------SubqueryAlias: __correlated_sq_1 +07)----------Projection: t2.t2_id, count(Int64(1)), Boolean(true) AS __always_true +08)------------Aggregate: groupBy=[[t2.t2_id]], aggr=[[count(Int64(1))]] +09)--------------TableScan: t2 projection=[t2_id] + +query II +SELECT t1_id, t1_int FROM t1 WHERE EXISTS (SELECT count(*) FROM t2 WHERE t1.t1_id = t2.t2_id HAVING count(*) = 0) +---- +33 3 + +# correlated_not_exists_groupless_count_agg_count_bug +query II +SELECT t1_id, t1_int FROM t1 WHERE NOT EXISTS (SELECT count(*) FROM t2 WHERE t1.t1_id = t2.t2_id) +---- + +# correlated_in_groupless_count_agg_count_bug +query II +SELECT t1_id, t1_int FROM t1 WHERE 0 IN (SELECT count(*) FROM t2 WHERE t1.t1_id = t2.t2_id) +---- +33 3 + +# correlated_exists_groupless_null_default_agg_always_true +query II rowsort +SELECT t1_id, t1_int FROM t1 WHERE EXISTS (SELECT sum(t2_int) FROM t2 WHERE t1.t1_id = t2.t2_id) +---- +11 1 +22 2 +33 3 +44 4 + +# correlated_not_exists_groupless_null_default_agg_always_true +query II +SELECT t1_id, t1_int FROM t1 WHERE NOT EXISTS (SELECT sum(t2_int) FROM t2 WHERE t1.t1_id = t2.t2_id) +---- + +# correlated_in_groupless_null_default_agg_wrong_zero_substitution +query II +SELECT t1_id, t1_int FROM t1 WHERE t1_id = 33 AND 0 IN (SELECT sum(t2_int) FROM t2 WHERE t1.t1_id = t2.t2_id) +---- + +# correlated_not_in_groupless_count_agg_count_bug +query II rowsort +SELECT t1_id, t1_int FROM t1 WHERE 0 NOT IN (SELECT count(*) FROM t2 WHERE t1.t1_id = t2.t2_id) +---- +11 1 +22 2 +44 4 + +# correlated_not_in_groupless_count_agg_count_bug_having +query II +SELECT t1_id, t1_int FROM t1 WHERE 0 NOT IN (SELECT count(*) FROM t2 WHERE t1.t1_id = t2.t2_id HAVING count(*) = 0) +---- Review Comment: Oof, two things here: 1. The join mishandled `NULL` negation for `NOT IN` 2. This test's expected value was wrong too, they just happened to match each other. Fixed both in the follow-up commit. -- 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]
