Skip to content

[SPARK-39255][SQL] Improve error messages #36635

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions core/src/main/resources/error/error-classes.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"message" : [ "Cannot up cast <value> from <sourceType> to <targetType>.\n<details>" ]
},
"CAST_INVALID_INPUT" : {
"message" : [ "The value <value> of the type <sourceType> cannot be cast to <targetType> because it is malformed. To return NULL instead, use `try_cast`. If necessary set <config> to \"false\" to bypass this error." ],
"message" : [ "The value <value> of the type <sourceType> cannot be cast to <targetType> because it is malformed. Correct the value as per the syntax, or change its target type. To return NULL instead, use `try_cast`. If necessary set <config> to \"false\" to bypass this error." ],
"sqlState" : "42000"
},
"CAST_OVERFLOW" : {
Expand Down Expand Up @@ -52,9 +52,6 @@
"message" : [ "Failed to rename <sourcePath> to <targetPath> as destination already exists" ],
"sqlState" : "22023"
},
"FAILED_SET_ORIGINAL_PERMISSION_BACK" : {
"message" : [ "Failed to set original permission <permission> back to the created path: <path>. Exception: <message>" ]
},
"FORBIDDEN_OPERATION" : {
"message" : [ "The operation <statement> is not allowed on <objectType>: <objectName>" ]
},
Expand Down Expand Up @@ -164,11 +161,11 @@
"message" : [ "more than one row returned by a subquery used as an expression: <plan>" ]
},
"NON_LITERAL_PIVOT_VALUES" : {
"message" : [ "Literal expressions required for pivot values, found '<expression>'" ],
"message" : [ "Literal expressions required for pivot values, found <expression>." ],
"sqlState" : "42000"
},
"NON_PARTITION_COLUMN" : {
"message" : [ "PARTITION clause cannot contain a non-partition column name: <columnName>" ],
"message" : [ "PARTITION clause cannot contain the non-partition column: <columnName>." ],
"sqlState" : "42000"
},
"NO_HANDLER_FOR_UDAF" : {
Expand Down Expand Up @@ -197,6 +194,9 @@
"message" : [ "Failed to rename as <sourcePath> was not found" ],
"sqlState" : "22023"
},
"RESET_PERMISSION_TO_ORIGINAL" : {
"message" : [ "Failed to set original permission <permission> back to the created path: <path>. Exception: <message>" ]
},
"SECOND_FUNCTION_ARGUMENT_NOT_INTEGER" : {
"message" : [ "The second argument of '<functionName>' function needs to be an integer." ],
"sqlState" : "22023"
Expand Down Expand Up @@ -322,7 +322,7 @@
"message" : [ "an existent path." ]
},
"NON_EXISTENT_PATH" : {
"message" : [ "a not existent path." ]
"message" : [ "a non-existent path." ]
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object QueryCompilationErrors extends QueryErrorsBase {
def nonLiteralPivotValError(pivotVal: Expression): Throwable = {
new AnalysisException(
errorClass = "NON_LITERAL_PIVOT_VALUES",
messageParameters = Array(pivotVal.toString))
messageParameters = Array(toSQLExpr(pivotVal)))
}

def pivotValDataTypeMismatchError(pivotVal: Expression, pivotCol: Expression): Throwable = {
Expand Down Expand Up @@ -2364,7 +2364,7 @@ object QueryCompilationErrors extends QueryErrorsBase {
def invalidFieldName(fieldName: Seq[String], path: Seq[String], context: Origin): Throwable = {
new AnalysisException(
errorClass = "INVALID_FIELD_NAME",
messageParameters = Array(fieldName.quoted, path.quoted),
messageParameters = Array(toSQLId(fieldName), toSQLId(path)),
origin = context)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import org.apache.spark.sql.types.{DataType, DoubleType, FloatType}
* For example: "spark.sql.ansi.enabled".
* 6. Any values of datasource options or SQL configs shall be double quoted.
* For example: "true", "CORRECTED".
* 7. SQL expressions shall be wrapped by double quotes.
* For example: "earnings + 1".
*/
trait QueryErrorsBase {
// Converts an error class parameter to its SQL representation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ object QueryExecutionErrors extends QueryErrorsBase {
permission: FsPermission,
path: Path,
e: Throwable): Throwable = {
new SparkSecurityException(errorClass = "FAILED_SET_ORIGINAL_PERMISSION_BACK",
new SparkSecurityException(errorClass = "RESET_PERMISSION_TO_ORIGINAL",
Array(permission.toString, path.toString, e.getMessage))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,8 @@ class StructTypeSuite extends SparkFunSuite with SQLHelper {
var e = intercept[AnalysisException] {
check(Seq("S1", "S12", "S123"), None)
}
assert(e.getMessage.contains("Field name S1.S12.S123 is invalid: s1.s12 is not a struct"))
assert(e.getMessage.contains(
"Field name `S1`.`S12`.`S123` is invalid: `s1`.`s12` is not a struct"))

// ambiguous name
e = intercept[AnalysisException] {
Expand All @@ -335,17 +336,19 @@ class StructTypeSuite extends SparkFunSuite with SQLHelper {
e = intercept[AnalysisException] {
check(Seq("m1", "key"), None)
}
assert(e.getMessage.contains("Field name m1.key is invalid: m1 is not a struct"))
assert(e.getMessage.contains("Field name `m1`.`key` is invalid: `m1` is not a struct"))
checkCollection(Seq("m1", "key"), Some(Seq("m1") -> StructField("key", IntegerType, false)))
checkCollection(Seq("M1", "value"), Some(Seq("m1") -> StructField("value", IntegerType)))
e = intercept[AnalysisException] {
checkCollection(Seq("M1", "key", "name"), None)
}
assert(e.getMessage.contains("Field name M1.key.name is invalid: m1.key is not a struct"))
assert(e.getMessage.contains(
"Field name `M1`.`key`.`name` is invalid: `m1`.`key` is not a struct"))
e = intercept[AnalysisException] {
checkCollection(Seq("M1", "value", "name"), None)
}
assert(e.getMessage.contains("Field name M1.value.name is invalid: m1.value is not a struct"))
assert(e.getMessage.contains(
"Field name `M1`.`value`.`name` is invalid: `m1`.`value` is not a struct"))

// map of struct
checkCollection(Seq("M2", "key", "A"),
Expand All @@ -357,24 +360,25 @@ class StructTypeSuite extends SparkFunSuite with SQLHelper {
e = intercept[AnalysisException] {
checkCollection(Seq("m2", "key", "A", "name"), None)
}
assert(e.getMessage.contains("Field name m2.key.A.name is invalid: m2.key.a is not a struct"))
assert(e.getMessage.contains(
"Field name `m2`.`key`.`A`.`name` is invalid: `m2`.`key`.`a` is not a struct"))
e = intercept[AnalysisException] {
checkCollection(Seq("M2", "value", "b", "name"), None)
}
assert(e.getMessage.contains(
"Field name M2.value.b.name is invalid: m2.value.b is not a struct"))
"Field name `M2`.`value`.`b`.`name` is invalid: `m2`.`value`.`b` is not a struct"))

// simple array type
e = intercept[AnalysisException] {
check(Seq("A1", "element"), None)
}
assert(e.getMessage.contains("Field name A1.element is invalid: a1 is not a struct"))
assert(e.getMessage.contains("Field name `A1`.`element` is invalid: `a1` is not a struct"))
checkCollection(Seq("A1", "element"), Some(Seq("a1") -> StructField("element", IntegerType)))
e = intercept[AnalysisException] {
checkCollection(Seq("A1", "element", "name"), None)
}
assert(e.getMessage.contains(
"Field name A1.element.name is invalid: a1.element is not a struct"))
"Field name `A1`.`element`.`name` is invalid: `a1`.`element` is not a struct"))

// array of struct
checkCollection(Seq("A2", "element", "C"),
Expand All @@ -384,7 +388,7 @@ class StructTypeSuite extends SparkFunSuite with SQLHelper {
checkCollection(Seq("a2", "element", "C", "name"), None)
}
assert(e.getMessage.contains(
"Field name a2.element.C.name is invalid: a2.element.c is not a struct"))
"Field name `a2`.`element`.`C`.`name` is invalid: `a2`.`element`.`c` is not a struct"))
}

test("SPARK-36807: Merge ANSI interval types to a tightest common type") {
Expand Down
Loading