Skip to content

Commit

Permalink
[SPARK-50246][SQL] Assign appropriate error condition for `_LEGACY_ER…
Browse files Browse the repository at this point in the history
…ROR_TEMP_2167`: `INVALID_JSON_RECORD_TYPE`

### What changes were proposed in this pull request?

This PR proposes to Integrate `_LEGACY_ERROR_TEMP_2167 ` into `INVALID_JSON_RECORD_TYPE `

### Why are the changes needed?

To improve the error message by assigning proper error condition and SQLSTATE

### Does this PR introduce _any_ user-facing change?

No, only user-facing error message improved

### How was this patch tested?

Updated the existing tests

### Was this patch authored or co-authored using generative AI tooling?

No

Closes apache#48775 from itholic/LEGACY_2167.

Authored-by: Haejoon Lee <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
  • Loading branch information
itholic authored and MaxGekk committed Nov 13, 2024
1 parent ede05fa commit 6fb1d43
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2645,6 +2645,12 @@
],
"sqlState" : "2203G"
},
"INVALID_JSON_RECORD_TYPE" : {
"message" : [
"Detected an invalid type of a JSON record while inferring a common schema in the mode <failFastMode>. Expected a STRUCT type, but found <invalidType>."
],
"sqlState" : "22023"
},
"INVALID_JSON_ROOT_FIELD" : {
"message" : [
"Cannot convert JSON root field to target Spark type."
Expand Down Expand Up @@ -7354,11 +7360,6 @@
"Malformed JSON."
]
},
"_LEGACY_ERROR_TEMP_2167" : {
"message" : [
"Malformed records are detected in schema inference. Parse Mode: <failFastMode>. Reasons: Failed to infer a common schema. Struct types are expected, but `<dataType>` was found."
]
},
"_LEGACY_ERROR_TEMP_2168" : {
"message" : [
"Decorrelate inner query through <plan> is not supported."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1437,10 +1437,10 @@ private[sql] object QueryExecutionErrors extends QueryErrorsBase with ExecutionE

def malformedRecordsDetectedInSchemaInferenceError(dataType: DataType): Throwable = {
new SparkException(
errorClass = "_LEGACY_ERROR_TEMP_2167",
errorClass = "INVALID_JSON_RECORD_TYPE",
messageParameters = Map(
"failFastMode" -> FailFastMode.name,
"dataType" -> dataType.catalogString),
"invalidType" -> toSQLType(dataType)),
cause = null)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2078,8 +2078,8 @@ abstract class JsonSuite
.option("mode", "FAILFAST")
.json(path)
},
condition = "_LEGACY_ERROR_TEMP_2167",
parameters = Map("failFastMode" -> "FAILFAST", "dataType" -> "string|bigint"))
condition = "INVALID_JSON_RECORD_TYPE",
parameters = Map("failFastMode" -> "FAILFAST", "invalidType" -> "\"STRING\"|\"BIGINT\""))

val ex = intercept[SparkException] {
spark.read
Expand Down

0 comments on commit 6fb1d43

Please sign in to comment.