NarekDW commented on code in PR #39501:
URL: https://github.com/apache/spark/pull/39501#discussion_r1066814829
##########
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:
Sure, I've made it more readable, hope it is better now.
--
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]