Skip to content
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

[SPARK-49951][SQL] Assign proper error condition for _LEGACY_ERROR_TEMP_(1099|3085) #48449

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
16 changes: 6 additions & 10 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -3809,6 +3809,12 @@
],
"sqlState" : "42617"
},
"PARSE_MODE_UNSUPPORTED" : {
"message" : [
"The function <funcName> doesn't support the <mode> mode. Acceptable modes are PERMISSIVE and FAILFAST."
],
"sqlState" : "42601"
},
"PARSE_SYNTAX_ERROR" : {
"message" : [
"Syntax error at or near <error><hint>."
Expand Down Expand Up @@ -6027,11 +6033,6 @@
"DataType '<x>' is not supported by <className>."
]
},
"_LEGACY_ERROR_TEMP_1099" : {
"message" : [
"<funcName>() doesn't support the <mode> mode. Acceptable modes are <permissiveMode> and <failFastMode>."
]
},
"_LEGACY_ERROR_TEMP_1103" : {
"message" : [
"Unsupported component type <clz> in arrays."
Expand Down Expand Up @@ -8093,11 +8094,6 @@
"No handler for UDF/UDAF/UDTF '<clazz>': <e>"
]
},
"_LEGACY_ERROR_TEMP_3085" : {
"message" : [
"from_avro() doesn't support the <name> mode. Acceptable modes are <permissiveMode> and <failFastMode>."
]
},
"_LEGACY_ERROR_TEMP_3086" : {
"message" : [
"Cannot persist <tableName> into Hive metastore as table property keys may not start with 'spark.sql.': <invalidKeys>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import org.apache.avro.generic.GenericDatumReader
import org.apache.avro.io.{BinaryDecoder, DecoderFactory}

import org.apache.spark.SparkException
import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.expressions.{ExpectsInputTypes, Expression, SpecificInternalRow, UnaryExpression}
import org.apache.spark.sql.catalyst.expressions.codegen.{CodegenContext, CodeGenerator, ExprCode}
import org.apache.spark.sql.catalyst.util.{FailFastMode, ParseMode, PermissiveMode}
import org.apache.spark.sql.errors.QueryCompilationErrors
import org.apache.spark.sql.types._

private[sql] case class AvroDataToCatalyst(
Expand Down Expand Up @@ -80,12 +80,9 @@ private[sql] case class AvroDataToCatalyst(
@transient private lazy val parseMode: ParseMode = {
val mode = avroOptions.parseMode
if (mode != PermissiveMode && mode != FailFastMode) {
throw new AnalysisException(
errorClass = "_LEGACY_ERROR_TEMP_3085",
messageParameters = Map(
"name" -> mode.name,
"permissiveMode" -> PermissiveMode.name,
"failFastMode" -> FailFastMode.name))
throw QueryCompilationErrors.parseModeUnsupportedError(
prettyName, mode
)
}
mode
}
Expand Down Expand Up @@ -123,12 +120,9 @@ private[sql] case class AvroDataToCatalyst(
s"Current parse Mode: ${FailFastMode.name}. To process malformed records as null " +
"result, try setting the option 'mode' as 'PERMISSIVE'.", e)
case _ =>
throw new AnalysisException(
errorClass = "_LEGACY_ERROR_TEMP_3085",
messageParameters = Map(
"name" -> parseMode.name,
"permissiveMode" -> PermissiveMode.name,
"failFastMode" -> FailFastMode.name))
throw QueryCompilationErrors.parseModeUnsupportedError(
"from_avro", parseMode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, use prettyName

)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ class AvroFunctionsSuite extends QueryTest with SharedSparkSession {
functions.from_avro(
$"avro", avroTypeStruct, Map("mode" -> "PERMISSIVE").asJava)),
expected)

checkError(
exception = intercept[AnalysisException] {
avroStructDF.select(
functions.from_avro(
$"avro", avroTypeStruct, Map("mode" -> "DROPMALFORMED").asJava)).collect()
},
condition = "PARSE_MODE_UNSUPPORTED",
parameters = Map(
"funcName" -> "from_avro",
"mode" -> "DROPMALFORMED"))
}

test("roundtrip in to_avro and from_avro - array with null") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.apache.spark.sql.catalyst.expressions.aggregate.AnyValue
import org.apache.spark.sql.catalyst.plans.JoinType
import org.apache.spark.sql.catalyst.plans.logical.{Assignment, InputParameter, Join, LogicalPlan, SerdeInfo, Window}
import org.apache.spark.sql.catalyst.trees.{Origin, TreeNode}
import org.apache.spark.sql.catalyst.util.{quoteIdentifier, FailFastMode, ParseMode, PermissiveMode}
import org.apache.spark.sql.catalyst.util.{quoteIdentifier, ParseMode}
import org.apache.spark.sql.connector.catalog._
import org.apache.spark.sql.connector.catalog.CatalogV2Implicits._
import org.apache.spark.sql.connector.catalog.functions.{BoundFunction, UnboundFunction}
Expand Down Expand Up @@ -1341,12 +1341,10 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase with Compilat

def parseModeUnsupportedError(funcName: String, mode: ParseMode): Throwable = {
new AnalysisException(
errorClass = "_LEGACY_ERROR_TEMP_1099",
errorClass = "PARSE_MODE_UNSUPPORTED",
messageParameters = Map(
"funcName" -> funcName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it is an id, please, quote it:

Suggested change
"funcName" -> funcName,
"funcName" -> toSQLId(funcName),

"mode" -> mode.name,
"permissiveMode" -> PermissiveMode.name,
"failFastMode" -> FailFastMode.name))
"mode" -> mode.name))
}

def nonFoldableArgumentError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,17 @@ class CsvExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper with P
test("unsupported mode") {
val csvData = "---"
val schema = StructType(StructField("a", DoubleType) :: Nil)
val exception = intercept[TestFailedException] {
checkEvaluation(
CsvToStructs(schema, Map("mode" -> DropMalformedMode.name), Literal(csvData), UTC_OPT),
InternalRow(null))
}.getCause
assert(exception.getMessage.contains("from_csv() doesn't support the DROPMALFORMED mode"))

checkError(
exception = intercept[TestFailedException] {
checkEvaluation(
CsvToStructs(schema, Map("mode" -> DropMalformedMode.name), Literal(csvData), UTC_OPT),
InternalRow(null))
}.getCause.asInstanceOf[AnalysisException],
condition = "PARSE_MODE_UNSUPPORTED",
parameters = Map(
"funcName" -> "from_csv",
"mode" -> "DROPMALFORMED"))
}

test("infer schema of CSV strings") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,10 @@ class CsvFunctionsSuite extends QueryTest with SharedSparkSession {
exception = intercept[AnalysisException] {
df.select(from_csv($"value", schema, Map("mode" -> "DROPMALFORMED"))).collect()
},
condition = "_LEGACY_ERROR_TEMP_1099",
condition = "PARSE_MODE_UNSUPPORTED",
parameters = Map(
"funcName" -> "from_csv",
"mode" -> "DROPMALFORMED",
"permissiveMode" -> "PERMISSIVE",
"failFastMode" -> "FAILFAST"))
"mode" -> "DROPMALFORMED"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,12 +861,10 @@ class JsonFunctionsSuite extends QueryTest with SharedSparkSession {
exception = intercept[AnalysisException] {
df.select(from_json($"value", schema, Map("mode" -> "DROPMALFORMED"))).collect()
},
condition = "_LEGACY_ERROR_TEMP_1099",
condition = "PARSE_MODE_UNSUPPORTED",
parameters = Map(
"funcName" -> "from_json",
"mode" -> "DROPMALFORMED",
"permissiveMode" -> "PERMISSIVE",
"failFastMode" -> "FAILFAST"))
"mode" -> "DROPMALFORMED"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,12 +1315,10 @@ class XmlSuite
spark.sql(s"""SELECT schema_of_xml('<ROW><a>1<ROW>', map('mode', 'DROPMALFORMED'))""")
.collect()
},
condition = "_LEGACY_ERROR_TEMP_1099",
condition = "PARSE_MODE_UNSUPPORTED",
parameters = Map(
"funcName" -> "schema_of_xml",
"mode" -> "DROPMALFORMED",
"permissiveMode" -> "PERMISSIVE",
"failFastMode" -> FailFastMode.name)
"mode" -> "DROPMALFORMED")
)
}

Expand Down