Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18875#discussion_r138095618
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/JsonFunctionsSuite.scala ---
    @@ -180,10 +180,30 @@ class JsonFunctionsSuite extends QueryTest with 
SharedSQLContext {
     
       test("to_json - array") {
         val df = Seq(Tuple1(Tuple1(1) :: Nil)).toDF("a")
    +    val df2 = Seq(Tuple1(Map("a" -> 1) :: Nil)).toDF("a")
     
         checkAnswer(
           df.select(to_json($"a")),
           Row("""[{"_1":1}]""") :: Nil)
    +    checkAnswer(
    +      df2.select(to_json($"a")),
    +      Row("""[{"a":1}]""") :: Nil)
    +  }
    +
    +  test("to_json - map") {
    +    val df1 = Seq(Map("a" -> Tuple1(1))).toDF("a")
    +    val df2 = Seq(Map(Tuple1(1) -> Tuple1(1))).toDF("a")
    +    val df3 = Seq(Map("a" -> 1)).toDF("a")
    +
    +    checkAnswer(
    +      df1.select(to_json($"a")),
    +      Row("""{"a":{"_1":1}}""") :: Nil)
    +    checkAnswer(
    +      df2.select(to_json($"a")),
    +      Row("""{"[0,1]":{"_1":1}}""") :: Nil)
    --- End diff --
    
    I think we don't have a `toString` method for `UnsafeRow` to show up 
well-format string representation. The current `toString` for it is just for 
debugging. It simply gets the hex string for each 8 bytes. Consider the nature 
of `UnsafeRow`, this `toString` might make sense to me.
    
    We can remove this test case if the result could be confusing, otherwise we 
should add a comment to explain why the JSON looks like it.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to