[GitHub] [spark] MaxGekk commented on a diff in pull request #37742: [SPARK-40291][SQL] Improve the message for column not in group by clause error
MaxGekk commented on code in PR #37742: URL: https://github.com/apache/spark/pull/37742#discussion_r961902629 ## sql/core/src/test/scala/org/apache/spark/sql/execution/SQLViewSuite.scala: ## @@ -897,10 +897,9 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils { val e = intercept[AnalysisException] { sql("SELECT * FROM v3") }.getMessage -assert(e.contains( - "expression 'spark_catalog.default.t.c1' 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.")) +assert( + e.contains("COLUMN_NOT_IN_GROUP_BY_CLAUSE") && +e.contains("\"c1\"")) Review Comment: Could you use `checkError()`, please. See the check above. ## core/src/main/resources/error/error-classes.json: ## @@ -65,6 +65,12 @@ ], "sqlState" : "22005" }, + "COLUMN_NOT_IN_GROUP_BY_CLAUSE" : { +"message" : [ + "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." Review Comment: Usually, the error messages starts from an upper case char (see messages around): ```suggestion "The 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." ``` -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org
[GitHub] [spark] MaxGekk commented on a diff in pull request #37742: [SPARK-40291][SQL] Improve the message for column not in group by clause error
MaxGekk commented on code in PR #37742: URL: https://github.com/apache/spark/pull/37742#discussion_r960464975 ## sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala: ## @@ -2527,4 +2527,11 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase { errorClass = "INVALID_COLUMN_OR_FIELD_DATA_TYPE", messageParameters = Array(toSQLId(name), toSQLType(dt), toSQLType(expected))) } + + def columnNotInGroupByClauseError(expression: Expression): Throwable = { +new AnalysisException( + errorClass = "COLUMN_NOT_IN_GROUP_BY_CLAUSE", + messageParameters = Array(expression.sql) Review Comment: expression.sql -> toSQLExpr(expression) ## core/src/main/resources/error/error-classes.json: ## @@ -65,6 +65,12 @@ ], "sqlState" : "22005" }, + "COLUMN_NOT_IN_GROUP_BY_CLAUSE" : { +"message" : [ + "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." Review Comment: Please, remove '' around and use toSQLExpr(), and first() should be quoted by back ticks. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org - To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org