jayzhan211 commented on code in PR #12046:
URL: https://github.com/apache/datafusion/pull/12046#discussion_r1720930646


##########
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.
   ```
   
   In this case, if we see wildcard, we can just return the error without 
actually expanding the actual columns



-- 
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

Reply via email to