Skip to content

Commit 2777677

Browse files
committed
Make allowNonNumericNumbers option work.
1 parent fbad920 commit 2777677

3 files changed

Lines changed: 4 additions & 17 deletions

File tree

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/json/JSONOptions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ object JSONOptions {
5959
allowNumericLeadingZeros =
6060
parameters.get("allowNumericLeadingZeros").map(_.toBoolean).getOrElse(false),
6161
allowNonNumericNumbers =
62-
parameters.get("allowNonNumericNumbers").map(_.toBoolean).getOrElse(true)
62+
parameters.get("allowNonNumericNumbers").map(_.toBoolean).getOrElse(false)
6363
)
6464
}

sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/json/JacksonParser.scala

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,7 @@ object JacksonParser {
100100
parser.getFloatValue
101101

102102
case (VALUE_STRING, FloatType) =>
103-
// Special case handling for NaN and Infinity.
104-
val value = parser.getText
105-
val lowerCaseValue = value.toLowerCase()
106-
if (lowerCaseValue.equals("nan") ||
107-
lowerCaseValue.equals("infinity") ||
108-
lowerCaseValue.equals("-infinity") ||
109-
lowerCaseValue.equals("inf") ||
110-
lowerCaseValue.equals("-inf")) {
111-
value.toFloat
112-
} else {
113-
sys.error(s"Cannot parse $value as FloatType.")
114-
}
103+
parser.getFloatValue
115104

116105
case (VALUE_NUMBER_INT | VALUE_NUMBER_FLOAT, DoubleType) =>
117106
parser.getDoubleValue

sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonParsingOptionsSuite.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,15 @@ class JsonParsingOptionsSuite extends QueryTest with SharedSQLContext {
9393
assert(df.first().getLong(0) == 18)
9494
}
9595

96-
// The following two tests are not really working - need to look into Jackson's
97-
// JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS.
98-
ignore("allowNonNumericNumbers off") {
96+
test("allowNonNumericNumbers off") {
9997
val str = """{"age": NaN}"""
10098
val rdd = sqlContext.sparkContext.parallelize(Seq(str))
10199
val df = sqlContext.read.json(rdd)
102100

103101
assert(df.schema.head.name == "_corrupt_record")
104102
}
105103

106-
ignore("allowNonNumericNumbers on") {
104+
test("allowNonNumericNumbers on") {
107105
val str = """{"age": NaN}"""
108106
val rdd = sqlContext.sparkContext.parallelize(Seq(str))
109107
val df = sqlContext.read.option("allowNonNumericNumbers", "true").json(rdd)

0 commit comments

Comments
 (0)