Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-40291][SQL] Improve the message for column not in group by clause error #37742

Closed
wants to merge 9 commits into from

Conversation

linhongliu-db
Copy link
Contributor

What changes were proposed in this pull request?

Improve the message for columns not in group by clause error

Why are the changes needed?

Use the new error class framework for columns not in group by clause error

Does this PR introduce any user-facing change?

Yes, adding error class

How was this patch tested?

UT

@linhongliu-db
Copy link
Contributor Author

cc @cloud-fan

@@ -65,6 +65,12 @@
],
"sqlState" : "22005"
},
"COLUMN_NOT_IN_GROUP_BY_CLAUSE" : {
"message" : [
"expression '<expression>' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove '' around and use toSQLExpr(), and first() should be quoted by back ticks.

def columnNotInGroupByClauseError(expression: Expression): Throwable = {
new AnalysisException(
errorClass = "COLUMN_NOT_IN_GROUP_BY_CLAUSE",
messageParameters = Array(expression.sql)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expression.sql -> toSQLExpr(expression)

@linhongliu-db
Copy link
Contributor Author

@MaxGekk Thanks for reviewing! I updated the PR

Comment on lines 900 to 902
assert(
e.contains("COLUMN_NOT_IN_GROUP_BY_CLAUSE") &&
e.contains("\"c1\""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use checkError(), please. See the check above.

core/src/main/resources/error/error-classes.json Outdated Show resolved Hide resolved
@MaxGekk
Copy link
Member

MaxGekk commented Sep 7, 2022

+1, LGTM. Merging to master.
Thank you, @linhongliu-db.

@MaxGekk MaxGekk closed this in 333140f Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants