rkrishn7 commented on code in PR #17313:
URL: https://github.com/apache/datafusion/pull/17313#discussion_r2301400501


##########
datafusion/sql/src/select.rs:
##########
@@ -944,15 +963,41 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
             check_columns_satisfy_exprs(
                 &column_exprs_post_aggr,
                 std::slice::from_ref(&having_expr_post_aggr),
-                CheckColumnsSatisfyExprsPurpose::HavingMustReferenceAggregate,
+                CheckColumnsSatisfyExprsPurpose::Aggregate(
+                    CheckColumnsMustReferenceAggregatePurpose::Having,
+                ),
             )?;
 
             Some(having_expr_post_aggr)
         } else {
             None
         };
 
-        Ok((plan, select_exprs_post_aggr, having_expr_post_aggr))
+        // Rewrite the QUALIFY expression to use the columns produced by the
+        // aggregation.
+        let qualify_expr_post_aggr = if let Some(qualify_expr) = 
qualify_expr_opt {

Review Comment:
   Definitely similar, although currently we still require multiple distinct 
function calls to `check_column_satisfy_expr` because for each expression 
(`SELECT`, `HAVING`, `QUALIFY`), we pass in diagnostic information that 
indicates which clause the error occurs in (`CheckColumnsSatisfyExprsPurpose`).
   
   Given this, I'm not quite sure a helper function would help 
readability/redundancy too much



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

Reply via email to