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

    https://github.com/apache/spark/pull/17377#discussion_r107171523
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
 ---
    @@ -1083,83 +1083,59 @@ class JsonSuite extends QueryTest with 
SharedSQLContext with TestJsonData {
       }
     
       test("Corrupt records: PERMISSIVE mode, without designated column for 
malformed records") {
    -    withTempView("jsonTable") {
    -      val schema = StructType(
    -        StructField("a", StringType, true) ::
    -          StructField("b", StringType, true) ::
    -          StructField("c", StringType, true) :: Nil)
    +    val schema = StructType(
    +      StructField("a", StringType, true) ::
    +        StructField("b", StringType, true) ::
    +        StructField("c", StringType, true) :: Nil)
     
    -      val jsonDF = spark.read.schema(schema).json(corruptRecords)
    -      jsonDF.createOrReplaceTempView("jsonTable")
    +    val jsonDF = spark.read.schema(schema).json(corruptRecords)
     
    -      checkAnswer(
    -        sql(
    -          """
    -            |SELECT a, b, c
    -            |FROM jsonTable
    -          """.stripMargin),
    -        Seq(
    -          // Corrupted records are replaced with null
    -          Row(null, null, null),
    -          Row(null, null, null),
    -          Row(null, null, null),
    -          Row("str_a_4", "str_b_4", "str_c_4"),
    -          Row(null, null, null))
    -      )
    -    }
    +    checkAnswer(
    +      jsonDF.select($"a", $"b", $"c"),
    +      Seq(
    +        // Corrupted records are replaced with null
    +        Row(null, null, null),
    +        Row(null, null, null),
    +        Row(null, null, null),
    +        Row("str_a_4", "str_b_4", "str_c_4"),
    +        Row(null, null, null))
    +    )
       }
     
       test("Corrupt records: PERMISSIVE mode, with designated column for 
malformed records") {
         // Test if we can query corrupt records.
         withSQLConf(SQLConf.COLUMN_NAME_OF_CORRUPT_RECORD.key -> "_unparsed") {
    -      withTempView("jsonTable") {
    -        val jsonDF = spark.read.json(corruptRecords)
    -        jsonDF.createOrReplaceTempView("jsonTable")
    -        val schema = StructType(
    -          StructField("_unparsed", StringType, true) ::
    +      val jsonDF = spark.read.json(corruptRecords)
    +      val schema = StructType(
    +        StructField("_unparsed", StringType, true) ::
               StructField("a", StringType, true) ::
               StructField("b", StringType, true) ::
               StructField("c", StringType, true) :: Nil)
     
    -        assert(schema === jsonDF.schema)
    --- End diff --
    
    Here too. The actual changes are as below:
    
    While trying to check related other PRs, I saw some minor comments in 
https://github.com/apache/spark/pull/14929.
    
    The actual changes are as below:
    
    **From**
    
    ```
    withTempView("jsonTable") {
      ...
      jsonDF.createOrReplaceTempView("jsonTable")
      ...
        sql(
          """
            |SELECT a, b, c, _unparsed
            |FROM jsonTable
          """.stripMargin),
      ...
        sql(
          """
            |SELECT a, b, c
            |FROM jsonTable
            |WHERE _unparsed IS NULL
          """.stripMargin),
      ...
        sql(
         """
            |SELECT _unparsed
            |FROM jsonTable
            |WHERE _unparsed IS NOT NULL
          """.stripMargin),
    ...
    }
    ```
    
    **To**
    
    ```
    ...
    jsonDF.select($"a", $"b", $"c", $"_unparsed"),
    ...
    jsonDF.filter($"_unparsed".isNull).select($"a", $"b", $"c"),
    ...
    jsonDF.filter($"_unparsed".isNotNull).select($"_unparsed"),
    ...
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

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

Reply via email to