-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-11753][SQL][test-hadoop2.2] Make allowNonNumericNumbers option work #9759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
2777677
b2a835d
186fa5e
dc9abc3
6d90b24
c74d715
6f668c3
1cfd1dc
4fca52c
0e473fc
025edea
af1e3a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -93,22 +93,41 @@ 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 = sqlContext.sparkContext.parallelize(Seq(str)) | ||
| val df = sqlContext.read.json(rdd) | ||
| test("allowNonNumericNumbers off") { | ||
| var testCases: Seq[String] = Seq("""{"age": NaN}""", """{"age": Infinity}""", | ||
| """{"age": -Infinity}""") | ||
|
|
||
| assert(df.schema.head.name == "_corrupt_record") | ||
| testCases.foreach { str => | ||
| val rdd = sqlContext.sparkContext.parallelize(Seq(str)) | ||
| val df = sqlContext.read.option("allowNonNumericNumbers", "false").json(rdd) | ||
|
|
||
| assert(df.schema.head.name == "_corrupt_record") | ||
| } | ||
|
|
||
| testCases = Seq("""{"age": "NaN"}""", """{"age": "Infinity"}""", | ||
| """{"age": "-Infinity"}""") | ||
|
|
||
| testCases.foreach { str => | ||
| val rdd = sqlContext.sparkContext.parallelize(Seq(str)) | ||
| val df = sqlContext.read.option("allowNonNumericNumbers", "false").json(rdd) | ||
|
|
||
| assert(df.schema.head.name == "age") | ||
| } | ||
| } | ||
|
|
||
| ignore("allowNonNumericNumbers on") { | ||
| val str = """{"age": NaN}""" | ||
| val rdd = sqlContext.sparkContext.parallelize(Seq(str)) | ||
| val df = sqlContext.read.option("allowNonNumericNumbers", "true").json(rdd) | ||
| test("allowNonNumericNumbers on") { | ||
| val testCases: Seq[String] = Seq("""{"age": NaN}""", """{"age": Infinity}""", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we still read them if they are quoted?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, so if we don't set |
||
| """{"age": -Infinity}""", """{"age": "NaN"}""", """{"age": "Infinity"}""", | ||
| """{"age": "-Infinity"}""") | ||
| val tests: Seq[Double => Boolean] = Seq(_.isNaN, _.isPosInfinity, _.isNegInfinity, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Besides, I found that "Inf", "-Inf" seems not working even
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to upgrade jackson library version in order to support "INF" and "-INF" (case-sensitive). |
||
| _.isNaN, _.isPosInfinity, _.isNegInfinity) | ||
|
|
||
| assert(df.schema.head.name == "age") | ||
| assert(df.first().getDouble(0).isNaN) | ||
| testCases.zipWithIndex.foreach { case (str, idx) => | ||
| val rdd = sqlContext.sparkContext.parallelize(Seq(str)) | ||
| val df = sqlContext.read.json(rdd) | ||
|
|
||
| assert(df.schema.head.name == "age") | ||
| assert(tests(idx)(df.first().getDouble(0))) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we removing the special handling for float types here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, should revert it back. BTW, do we actually test "inf" and "-inf" before? Because "inf".toFloat is not legal.