itholic commented on code in PR #39501:
URL: https://github.com/apache/spark/pull/39501#discussion_r1066733263
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeExtractors.scala:
##########
@@ -64,7 +64,7 @@ object ExtractValue {
case (_: ArrayType, _) => GetArrayItem(child, extraction)
- case (MapType(kt, _, _), _) => GetMapValue(child, extraction)
+ case (MapType(_, _, _), _) => GetMapValue(child, extraction)
Review Comment:
Can I ask what is the intention for this change?
Seems like maybe it is not required to update an error class name??
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/ComplexTypeSuite.scala:
##########
@@ -460,24 +460,44 @@ class ComplexTypeSuite extends SparkFunSuite with
ExpressionEvalHelper {
}
test("error message of ExtractValue") {
- val structType = StructType(StructField("a", StringType, true) :: Nil)
- val otherType = StringType
-
- def checkErrorMessage(
- childDataType: DataType,
- fieldDataType: DataType,
- errorMessage: String): Unit = {
- val e = intercept[org.apache.spark.sql.AnalysisException] {
- ExtractValue(
- Literal.create(null, childDataType),
- Literal.create(null, fieldDataType),
- _ == _)
- }
- assert(e.getMessage().contains(errorMessage))
- }
+ val testResolver = (a: String, b: String) => a == b
+ val childStructFiledLiteral = Literal.create(create_row("test value"),
+ StructType(StructField("test_field", StringType) :: Nil))
+ val extractionIntegerFieldLiteral = Literal.create(null, IntegerType)
+ val childStringFiledLiteral = Literal.create("test value", StringType)
+ val extractionStringFieldLiteral = Literal.create("test_field", StringType)
+ val childStructFiledLiteralWithDuplicateColumns = Literal.create(
+ create_row("test value 1", "test value 2"),
+ StructType(
+ StructField("test_field", StringType) :: StructField("test_field",
StringType) :: Nil))
+
+ checkError(
+ exception = intercept[AnalysisException](
+ ExtractValue(childStructFiledLiteral, extractionIntegerFieldLiteral,
testResolver)),
+ errorClass = "INVALID_EXTRACT_FIELD_TYPE",
+ parameters = Map("extraction" -> extractionIntegerFieldLiteral.toString)
+ )
- checkErrorMessage(structType, IntegerType, "Field name should be String
Literal")
- checkErrorMessage(otherType, StringType, "Can't extract value from")
Review Comment:
Seems like maybe we can simply update the test by using `checkError` as
below?
```diff
- checkErrorMessage(structType, IntegerType, "Field name should be String
Literal")
- checkErrorMessage(otherType, StringType, "Can't extract value from")
+ checkError(
+ exception = intercept[org.apache.spark.sql.AnalysisException] {
+ ExtractValue(
+ Literal.create(null, structType),
+ Literal.create(null, IntegerType),
+ _ == _)
+ },
+ errorClass = "INVALID_EXTRACT_FIELD_TYPE",
+ parameters = Map("extraction" -> "null")
+ )
+
+ checkError(
+ exception = intercept[org.apache.spark.sql.AnalysisException] {
+ ExtractValue(
+ Literal.create(null, otherType),
+ Literal.create(null, StringType),
+ _ == _)
+ },
+ errorClass = "INVALID_CHILD_FIELD_TYPE",
+ parameters = Map("child" -> "null", "other" -> "string")
+ )
```
Current fix seems a bit harms the readability IMHO.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]