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