diff --git a/common/utils/src/main/resources/error/error-conditions.json b/common/utils/src/main/resources/error/error-conditions.json index 18603b61d8ae..98b04ccaf0f5 100644 --- a/common/utils/src/main/resources/error/error-conditions.json +++ b/common/utils/src/main/resources/error/error-conditions.json @@ -2655,6 +2655,12 @@ ], "sqlState" : "2203G" }, + "INVALID_JSON_RECORD_TYPE" : { + "message" : [ + "Detected an invalid type of a JSON record while inferring a common schema in the mode . Expected a STRUCT type, but found ." + ], + "sqlState" : "22023" + }, "INVALID_JSON_ROOT_FIELD" : { "message" : [ "Cannot convert JSON root field to target Spark type." @@ -7284,11 +7290,6 @@ "Malformed JSON." ] }, - "_LEGACY_ERROR_TEMP_2167" : { - "message" : [ - "Malformed records are detected in schema inference. Parse Mode: . Reasons: Failed to infer a common schema. Struct types are expected, but `` was found." - ] - }, "_LEGACY_ERROR_TEMP_2168" : { "message" : [ "Decorrelate inner query through is not supported." diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala index 2cc223ba69fa..a9beb11daa91 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala @@ -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) } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala index 06183596a54a..dfbc8e5279aa 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala @@ -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