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

    https://github.com/apache/spark/pull/9759#discussion_r63705693
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonParsingOptionsSuite.scala
 ---
    @@ -93,23 +93,45 @@ class JsonParsingOptionsSuite extends QueryTest with 
SharedSQLContext {
         assert(df.first().getLong(0) == 18)
       }
     
    -  // The following two tests are not really working - need to look into 
Jackson's
    -  // JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS.
    -  ignore("allowNonNumericNumbers off") {
    -    val str = """{"age": NaN}"""
    -    val rdd = spark.sparkContext.parallelize(Seq(str))
    -    val df = spark.read.json(rdd)
    -
    -    assert(df.schema.head.name == "_corrupt_record")
    +  test("allowNonNumericNumbers off") {
    +    // non-quoted non-numeric numbers don't work if allowNonNumericNumbers 
is off.
    +    var testCases: Seq[String] = Seq("""{"age": NaN}""", """{"age": 
Infinity}""",
    +      """{"age": -Infinity}""", """{"age": +INF}""", """{"age": -INF}""")
    +    testCases.foreach { str =>
    +      val rdd = spark.sparkContext.parallelize(Seq(str))
    +      val df = spark.read.option("allowNonNumericNumbers", 
"false").json(rdd)
    +
    +      assert(df.schema.head.name == "_corrupt_record")
    +    }
    +
    +    // quoted non-numeric numbers should still work even 
allowNonNumericNumbers is off.
    +    testCases = Seq("""{"age": "NaN"}""", """{"age": "Infinity"}""", 
"""{"age": "-Infinity"}""")
    +    val tests: Seq[Double => Boolean] = Seq(_.isNaN, _.isPosInfinity, 
_.isNegInfinity)
    +
    +    testCases.zipWithIndex.foreach { case (str, idx) =>
    +      val rdd = spark.sparkContext.parallelize(Seq(str))
    +      val df = spark.read.option("allowNonNumericNumbers", 
"false").json(rdd)
    +
    +      assert(df.schema.head.name == "age")
    +      assert(tests(idx)(df.first().getDouble(0)))
    --- End diff --
    
    @cloud-fan I updated it.
    
    Non-quoted non-numeric numbers are parsed as double when the corresponding 
field is double/float type. This behavior is as same as before this patch.
    



---
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