Jiashu-Hu opened a new pull request, #15056: URL: https://github.com/apache/datafusion/pull/15056
## 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 check_group_by_info(input: &LogicalPlan) -> (bool, Vec<Expr>, Vec<Expr>)` - Detects if a query contains a GROUP BY clause - Collects columns used in GROUP BY and in aggregate functions - Returns a tuple of `(has_group_by, group_by_columns, aggregate_columns)` 2. `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::GroupByColumnInvalid` error when validation fails 3. added a new `SchemaError` type to shows the error message - `datafusion_common::SchemaError::GroupByColumnInvalid` ### 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)? --> - The new validation functions in `expand_wildcard_rule.rs` have been tested with test cases included at the bottom of the file. These tests verify both successful validation and proper error reporting. - The message improvements in `datafusion/sql/src/utils.rs` modify only the error text, not the functional logic, so no additional tests were added for these changes. Additional test cases are welcome to ensure comprehensive coverage. ## 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: ``` Error during planning: Column in SELECT must be grouped or aggregated: Expression foo.b could not be resolved from available columns: foo.a ``` 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