planga82 commented on a change in pull request #33525:
URL: https://github.com/apache/spark/pull/33525#discussion_r677004457
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala
##########
@@ -853,4 +854,32 @@ class JsonExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper with
checkEvaluation(JsonObjectKeys(Literal(input)), expected)
}
}
+
+ def checkMapTypeKeyError(schema: DataType, jsonData: String): Unit = {
+ assert( JsonToStructs(schema, Map.empty,
Literal(jsonData)).checkInputDataTypes() match {
+ case TypeCheckFailure(_) => true
+ case _ => false
+ })
+ }
+
+ test("SPARK-35320: from_json should fail with a key type different of
StringType") {
+ checkMapTypeKeyError(MapType(IntegerType, StringType), """{"1": "test"}""")
+ }
+
+ test("SPARK-35320: from_json should fail with a key type different of
StringType " +
+ "anidated in a StructType") {
+ checkMapTypeKeyError(StructType(Seq(StructField("test",
MapType(IntegerType, StringType)))),
+ """"test": {"1": "test"}""")
+ }
+
+ test("SPARK-35320: from_json should fail with a key type different of
StringType " +
+ "anidated in a ArrayType") {
+ checkMapTypeKeyError(ArrayType(MapType(IntegerType, StringType)),
"""[{"1": "test"}]""")
+ }
+
+ test("SPARK-35320: from_json should fail with a key type different of
StringType " +
+ "anidated in a MapType") {
+ checkMapTypeKeyError(MapType(StringType, MapType(IntegerType, StringType)),
+ """{"key": {"1" : "test"}}""")
+ }
Review comment:
Yes you are right, I'm going to put it in only one test to simplify it
--
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]