alamb commented on code in PR #11897: URL: https://github.com/apache/datafusion/pull/11897#discussion_r1712647625
########## datafusion/sqllogictest/test_files/aggregate.slt: ########## @@ -5553,4 +5553,33 @@ drop table employee_csv; query I??III?T select count(null), min(null), max(null), bit_and(NULL), bit_or(NULL), bit_xor(NULL), nth_value(NULL, 1), string_agg(NULL, ','); ---- -0 NULL NULL NULL NULL NULL NULL NULL \ No newline at end of file +0 NULL NULL NULL NULL NULL NULL NULL + +statement ok +create table t1(v1 int); + +query R +SELECT AVG(v1) FROM t1 having false; Review Comment: Can we please also add negative (positive?) tests like: ```sql SELECT AVG(v1) FROM t1 GROUP BY false having true; ``` And ```sql SELECT AVG(v1) FROM t1 GROUP BY false having 1 = 1; ``` ########## datafusion/sql/src/select.rs: ########## @@ -778,9 +777,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { // Rewrite the HAVING expression to use the columns produced by the // aggregation. let having_expr_post_aggr = if let Some(having_expr) = having_expr_opt { - let having_expr_post_aggr = - rebase_expr(having_expr, &aggr_projection_exprs, input)?; - + let having_expr_post_aggr = if is_constant_expression(having_expr) { Review Comment: The check needs to be for a false constant (not just a false constant) right? I'll suggest a test to show this ########## datafusion/sql/src/select.rs: ########## @@ -778,9 +777,11 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { // Rewrite the HAVING expression to use the columns produced by the // aggregation. let having_expr_post_aggr = if let Some(having_expr) = having_expr_opt { - let having_expr_post_aggr = - rebase_expr(having_expr, &aggr_projection_exprs, input)?; - + let having_expr_post_aggr = if is_constant_expression(having_expr) { Review Comment: The check needs to be for a false constant (not just a constant) right? I'll suggest a test to show this -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org