Skip to content

Commit 074444b

Browse files
panbingkunMaxGekk
authored andcommitted
[SPARK-41179][SQL] Assign a name to the error class _LEGACY_ERROR_TEMP_1092
### What changes were proposed in this pull request? In the PR, I propose to assign the name `INVALID_SCHEMA` to the error class `_LEGACY_ERROR_TEMP_1092`. ### Why are the changes needed? Proper names of error classes should improve user experience with Spark SQL. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Pass GA. Closes #38710 from panbingkun/SPARK-41179. Authored-by: panbingkun <pbk1982@gmail.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
1 parent 9f0aa27 commit 074444b

File tree

7 files changed

+48
-19
lines changed

7 files changed

+48
-19
lines changed

core/src/main/resources/error/error-classes.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,11 @@
756756
"<protobufClassName> is not a Protobuf message type"
757757
]
758758
},
759+
"INVALID_SCHEMA" : {
760+
"message" : [
761+
"The expression <expr> is not a valid schema string."
762+
]
763+
},
759764
"INVALID_SQL_SYNTAX" : {
760765
"message" : [
761766
"Invalid SQL syntax: <inputString>"
@@ -2170,11 +2175,6 @@
21702175
"Cannot read table property '<key>' as it's corrupted.<details>."
21712176
]
21722177
},
2173-
"_LEGACY_ERROR_TEMP_1092" : {
2174-
"message" : [
2175-
"The expression '<expr>' is not a valid schema string."
2176-
]
2177-
},
21782178
"_LEGACY_ERROR_TEMP_1093" : {
21792179
"message" : [
21802180
"Schema should be specified in DDL format as a string literal or output of the schema_of_json/schema_of_csv functions instead of <expr>."

sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryCompilationErrors.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -995,8 +995,8 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase {
995995

996996
def invalidSchemaStringError(exp: Expression): Throwable = {
997997
new AnalysisException(
998-
errorClass = "_LEGACY_ERROR_TEMP_1092",
999-
messageParameters = Map("expr" -> exp.sql))
998+
errorClass = "INVALID_SCHEMA",
999+
messageParameters = Map("expr" -> toSQLExpr(exp)))
10001000
}
10011001

10021002
def schemaNotFoldableError(exp: Expression): Throwable = {

sql/core/src/test/resources/sql-tests/results/csv-functions.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ struct<>
2222
-- !query output
2323
org.apache.spark.sql.AnalysisException
2424
{
25-
"errorClass" : "_LEGACY_ERROR_TEMP_1092",
25+
"errorClass" : "INVALID_SCHEMA",
2626
"messageParameters" : {
27-
"expr" : "1"
27+
"expr" : "\"1\""
2828
},
2929
"queryContext" : [ {
3030
"objectType" : "",

sql/core/src/test/resources/sql-tests/results/json-functions.sql.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ struct<>
148148
-- !query output
149149
org.apache.spark.sql.AnalysisException
150150
{
151-
"errorClass" : "_LEGACY_ERROR_TEMP_1092",
151+
"errorClass" : "INVALID_SCHEMA",
152152
"messageParameters" : {
153-
"expr" : "1"
153+
"expr" : "\"1\""
154154
},
155155
"queryContext" : [ {
156156
"objectType" : "",

sql/core/src/test/scala/org/apache/spark/sql/CsvFunctionsSuite.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,13 @@ class CsvFunctionsSuite extends QueryTest with SharedSparkSession {
363363
}.getMessage
364364
assert(errMsg.contains("Schema should be specified in DDL format as a string literal"))
365365

366-
val errMsg2 = intercept[AnalysisException] {
367-
Seq("1").toDF("csv").select(from_csv($"csv", lit(1), options)).collect()
368-
}.getMessage
369-
assert(errMsg2.contains("The expression '1' is not a valid schema string"))
366+
checkError(
367+
exception = intercept[AnalysisException] {
368+
Seq("1").toDF("csv").select(from_csv($"csv", lit(1), options)).collect()
369+
},
370+
errorClass = "INVALID_SCHEMA",
371+
parameters = Map("expr" -> "\"1\"")
372+
)
370373
}
371374

372375
test("schema_of_csv - infers the schema of foldable CSV string") {

sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5200,6 +5200,23 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
52005200
Seq(Row(Map("a" -> Map("a" -> 6, "b" -> 8), "b" -> Map("a" -> 8, "b" -> 10))))
52015201
)
52025202
}
5203+
5204+
test("from_json - invalid schema string") {
5205+
checkError(
5206+
exception = intercept[AnalysisException] {
5207+
sql("select from_json('{\"a\":1}', 1)")
5208+
},
5209+
errorClass = "INVALID_SCHEMA",
5210+
parameters = Map(
5211+
"expr" -> "\"1\""
5212+
),
5213+
context = ExpectedContext(
5214+
fragment = "from_json('{\"a\":1}', 1)",
5215+
start = 7,
5216+
stop = 29
5217+
)
5218+
)
5219+
}
52035220
}
52045221

52055222
object DataFrameFunctionsSuite {

sql/core/src/test/scala/org/apache/spark/sql/JsonFunctionsSuite.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,19 @@ class JsonFunctionsSuite extends QueryTest with SharedSparkSession {
424424
"from_json(value, 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy HH:mm'))"),
425425
Row(Row(java.sql.Timestamp.valueOf("2015-08-26 18:00:00.0"))))
426426

427-
val errMsg1 = intercept[AnalysisException] {
428-
df3.selectExpr("from_json(value, 1)")
429-
}
430-
assert(errMsg1.getMessage.startsWith("The expression '1' is not a valid schema string"))
427+
checkError(
428+
exception = intercept[AnalysisException] {
429+
df3.selectExpr("from_json(value, 1)")
430+
},
431+
errorClass = "INVALID_SCHEMA",
432+
parameters = Map("expr" -> "\"1\""),
433+
context = ExpectedContext(
434+
fragment = "from_json(value, 1)",
435+
start = 0,
436+
stop = 18
437+
)
438+
)
439+
431440
val errMsg2 = intercept[AnalysisException] {
432441
df3.selectExpr("""from_json(value, 'time InvalidType')""")
433442
}

0 commit comments

Comments
 (0)