Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/18875#discussion_r138078894
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/JsonExpressionsSuite.scala
---
@@ -612,6 +612,54 @@ class JsonExpressionsSuite extends SparkFunSuite with
ExpressionEvalHelper {
)
}
+ test("SPARK-21513: to_json support map[string, struct] to json") {
+ val schema = MapType(StringType, StructType(StructField("a",
IntegerType) :: Nil))
+ val input = Literal.create(ArrayBasedMapData(Map("test" ->
InternalRow(1))), schema)
+ checkEvaluation(
+ StructsToJson(Map.empty, input),
+ """{"test":{"a":1}}"""
+ )
+ }
+
+ test("SPARK-21513: to_json support map[struct, struct] to json") {
+ val schema = MapType(StructType(StructField("a", IntegerType) :: Nil),
+ StructType(StructField("b", IntegerType) :: Nil))
+ val input = Literal.create(ArrayBasedMapData(Map(InternalRow(1) ->
InternalRow(2))), schema)
+ checkEvaluation(
+ StructsToJson(Map.empty, input),
+ """{"[1]":{"b":2}}"""
+ )
+ }
+
+ test("SPARK-21513: to_json support map[string, integer] to json") {
+ val schema = MapType(StringType, IntegerType)
+ val input = Literal.create(ArrayBasedMapData(Map("a" -> 1)), schema)
+ checkEvaluation(
+ StructsToJson(Map.empty, input),
+ """{"a":1}"""
+ )
+ }
+
+ test("to_json - array with maps") {
+ val inputSchema = ArrayType(MapType(StringType, IntegerType))
+ val input = new GenericArrayData(ArrayBasedMapData(
+ Map("a" -> 1)) :: ArrayBasedMapData(Map("b" -> 2)) :: Nil)
+ val output = """[{"a":1},{"b":2}]"""
+ checkEvaluation(
+ StructsToJson(Map.empty, Literal.create(input, inputSchema), gmtId),
+ output)
+ }
+
+ test("to_json - array with single map") {
+ val inputSchema = ArrayType(MapType(StringType, IntegerType))
+ val input = new GenericArrayData(ArrayBasedMapData(
+ Map("a" -> 1)) :: Nil)
--- End diff --
Let's make this inlined.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]