karenfeng commented on a change in pull request #33282:
URL: https://github.com/apache/spark/pull/33282#discussion_r667185471
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala
##########
@@ -1349,9 +1349,13 @@ private[spark] object QueryCompilationErrors {
s"${evalTypes.mkString(",")}")
}
- def ambiguousFieldNameError(fieldName: String, names: String): Throwable = {
+ def ambiguousFieldNameError(
+ fieldName: Seq[String], nunMatches: Int, context: Origin): Throwable = {
new AnalysisException(
- s"Ambiguous field name: $fieldName. Found multiple columns that can
match: $names")
+ errorClass = "INVALID_FIELD_NAME",
+ messageParameters = Array(fieldName.quoted,
+ s"${fieldName.last} is ambiguous and has $nunMatches matching fields
in the struct"),
Review comment:
Can we put the majority of this in the error message format? Eg. the
format would be `Field name %s is invalid: %s is ambiguous and has %s matching
fields in the struct`, and the parameters would be `Array(fieldName.quoted,
fieldName.last, numMatches)`
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala
##########
@@ -1349,9 +1349,13 @@ private[spark] object QueryCompilationErrors {
s"${evalTypes.mkString(",")}")
}
- def ambiguousFieldNameError(fieldName: String, names: String): Throwable = {
+ def ambiguousFieldNameError(
+ fieldName: Seq[String], nunMatches: Int, context: Origin): Throwable = {
new AnalysisException(
- s"Ambiguous field name: $fieldName. Found multiple columns that can
match: $names")
+ errorClass = "INVALID_FIELD_NAME",
+ messageParameters = Array(fieldName.quoted,
+ s"${fieldName.last} is ambiguous and has $nunMatches matching fields
in the struct"),
Review comment:
In this case, we would have to create two new error classes (another one
for the case that path is not a struct).
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala
##########
@@ -1349,9 +1349,13 @@ private[spark] object QueryCompilationErrors {
s"${evalTypes.mkString(",")}")
}
- def ambiguousFieldNameError(fieldName: String, names: String): Throwable = {
+ def ambiguousFieldNameError(
+ fieldName: Seq[String], nunMatches: Int, context: Origin): Throwable = {
Review comment:
Nit: `nunMatches` -> `numMatches`
##########
File path: core/src/main/resources/error/error-classes.json
##########
@@ -7,6 +7,9 @@
"message" : [ "Found duplicate keys '%s'" ],
"sqlState" : "23000"
},
+ "INVALID_FIELD_NAME" : {
+ "message" : [ "Field name %s is invalid: %s." ]
Review comment:
I believe this is actually SQLSTATE 42000 (syntax error) as well
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]