You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Jiashu-Hu (via GitHub)" <gi...@apache.org> on 2025/03/18 02:51:57 UTC
[PR] Improvement/improve wildcard error 15004 [datafusion]
Jiashu-Hu opened a new pull request, #15287:
URL: https://github.com/apache/datafusion/pull/15287
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- Closes [#15004](https://github.com/apache/datafusion/issues/15004).
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue, then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
The current error messages for non-aggregate columns in GROUP BY queries are technically accurate but not user-friendly. They use technical terminology like "non-aggregate values" without clearly explaining the problem or providing actionable solutions. This PR improves these error messages to be more intuitive and helpful, especially for users who might not be familiar with SQL aggregation concepts.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
### added two function in to `expand_wildcard_rule.rs`:
1. `fn validate_columns_in_group_by_or_aggregate(has_group_by: bool, expanded: &Vec<Expr>, group_by_columns: &Vec<Expr>, aggregate_columns: &Vec<Expr>) -> Result<(), DataFusionError>`
- Verifies all selected columns appear either in the GROUP BY clause or within aggregate functions
- Returns a clear `SchemaError::GroupByColumnNotInSelectList` error when validation fails
2. added a new `SchemaError` type to shows the error message - `datafusion_common::SchemaError::GroupByColumnNotInSelectList`
### In datafusion/sql/src/utils.rs:
- Updated `message_prefix()` method to provide clearer error message prefixes
- Improved help text in `check_column_satisfies_expr()` to suggest specific solutions
- for easy understanding as requested in [#15004](https://github.com/apache/datafusion/issues/15004)
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
3. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
There are several existing tests that directly evaluate this function during the CICL process, and all of them have been successfully passed.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
Yes. Users will now see more intuitive error messages when they encounter GROUP BY validation issues. For example, instead of seeing:
```
Error during planning: Projection references non-aggregate values: Expression foo.b could not be resolved from available columns: foo.a
```
They will see:
```
SchemaError: Column 'foo.b' must appear in the GROUP BY clause or be used in an aggregate function
```
This change makes errors more understandable and provides clearer guidance on how to fix the issue.
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Improvement/improve wildcard error 15004 [datafusion]
Posted by "Jiashu-Hu (via GitHub)" <gi...@apache.org>.
Jiashu-Hu commented on code in PR #15287:
URL: https://github.com/apache/datafusion/pull/15287#discussion_r2001662346
##########
datafusion/sql/src/select.rs:
##########
@@ -826,6 +827,13 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
.map(|expr| rebase_expr(expr, &aggr_projection_exprs, input))
.collect::<Result<Vec<Expr>>>()?;
+ // check if the columns in the SELECT list are in the GROUP BY clause
+ // or are part of an aggregate function, if not, throw an error.
+ validate_columns_in_group_by_or_aggregate(
Review Comment:
hey jay, thanks for your review! I've unified these 2 also updated error message in the test file.
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Improvement/improve wildcard error 15004 [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15287:
URL: https://github.com/apache/datafusion/pull/15287#discussion_r2000153792
##########
datafusion/sql/src/select.rs:
##########
@@ -826,6 +827,13 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
.map(|expr| rebase_expr(expr, &aggr_projection_exprs, input))
.collect::<Result<Vec<Expr>>>()?;
+ // check if the columns in the SELECT list are in the GROUP BY clause
+ // or are part of an aggregate function, if not, throw an error.
+ validate_columns_in_group_by_or_aggregate(
Review Comment:
It seems like the error should be handled in the `check_columns_satisfy_exprs` below with `ProjectionMustReferenceAggregate`
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Improved error for expand wildcard rule [datafusion]
Posted by "ozankabak (via GitHub)" <gi...@apache.org>.
ozankabak commented on PR #15287:
URL: https://github.com/apache/datafusion/pull/15287#issuecomment-2745187508
This PR seems to have broken `main`.
@alamb -- Extended tests break very frequently these days. We should prioritize completing the work on running them before merge.
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Improvement/improve wildcard error 15004 [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #15287:
URL: https://github.com/apache/datafusion/pull/15287#discussion_r2000153792
##########
datafusion/sql/src/select.rs:
##########
@@ -826,6 +827,13 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
.map(|expr| rebase_expr(expr, &aggr_projection_exprs, input))
.collect::<Result<Vec<Expr>>>()?;
+ // check if the columns in the SELECT list are in the GROUP BY clause
+ // or are part of an aggregate function, if not, throw an error.
+ validate_columns_in_group_by_or_aggregate(
Review Comment:
It seems like the error should be handled in the `check_columns_satisfy_exprs` below with `ProjectionMustReferenceAggregate`, is it possible to unify these 2?
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Improved error for expand wildcard rule [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #15287:
URL: https://github.com/apache/datafusion/pull/15287#issuecomment-2746384487
> This PR seems to have broken `main`. It is an easy fix (error messages do not match).
>
> @alamb -- Extended tests break very frequently these days. We should prioritize completing the work on running them before merge.
@ozankabak I think there is a PR waiting on review that would let us more easily run the tests before merge. I am not sure how we would have known to run them in this case though
- https://github.com/apache/datafusion/pull/15101
I feel like what would be idea is some workflow that actually ran the tests before merge but that didn't need us to babysit the PR -- something like letting a bot merge it or a merge queue
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Improved error for expand wildcard rule [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #15287:
URL: https://github.com/apache/datafusion/pull/15287#issuecomment-2745020209
Thanks @alamb @Jiashu-Hu
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Improved error for expand wildcard rule [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 merged PR #15287:
URL: https://github.com/apache/datafusion/pull/15287
--
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-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org