goldmedal commented on code in PR #12046: URL: https://github.com/apache/datafusion/pull/12046#discussion_r1720995552
########## datafusion/sql/src/select.rs: ########## @@ -749,6 +750,37 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> { .map(|expr| rebase_expr(expr, &aggr_projection_exprs, input)) .collect::<Result<Vec<Expr>>>()?; + // If the having expression is present and the group by expression is not present, + // we can ensure this is an invalid query. Expand the wildcard expression here to + // get a better error message. + let select_exprs_post_aggr = if having_expr_opt.is_some() + && group_by_exprs.is_empty() Review Comment: > Instead of expanding wildcard, does it make sense to return the error if neither column is in group by nor is it part of the aggregate function? > > ``` > D select * from t having max(a) = 1; > Binder Error: column "a" must appear in the GROUP BY clause or must be part of an aggregate function. > Either add it to the GROUP BY list, or use "ANY_VALUE(a)" if the exact value of "a" is not important. > ``` > I think it makes sense for the `having` function. I can't find any case that violates this rule 🤔. > In this case, if we see wildcard, we can just return the error without actually expanding the actual columns. Maybe modify `check_columns_satisfy_exprs` Instead of modifying `check_columns_satisfy_exprs`, I guess it would be checked at the part of the building having expression. https://github.com/apache/datafusion/blob/a91be04ced3746c673788d5da124c6d30009d9ff/datafusion/sql/src/select.rs#L762-L770 `check_columns_satisfy_exprs` is also used to check the normal aggregation. I think the rule can't be shared. -- 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