Fix/improve wildcard error 15004 #15056
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
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?
added two function in to
expand_wildcard_rule.rs
:fn check_group_by_info(input: &LogicalPlan) -> (bool, Vec<Expr>, Vec<Expr>)
(has_group_by, group_by_columns, aggregate_columns)
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>
SchemaError::GroupByColumnInvalid
error when validation failsSchemaError
type to shows the error message -datafusion_common::SchemaError::GroupByColumnInvalid
In datafusion/sql/src/utils.rs:
message_prefix()
method to provide clearer error message prefixescheck_column_satisfies_expr()
to suggest specific solutionsAre these changes tested?
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.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?
Yes. Users will now see more intuitive error messages when they encounter GROUP BY validation issues. For example, instead of seeing:
They will see:
This change makes errors more understandable and provides clearer guidance on how to fix the issue.