Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class JacksonParser(
case VALUE_NUMBER_INT | VALUE_NUMBER_FLOAT =>
parser.getFloatValue

case VALUE_STRING =>
case VALUE_STRING if parser.getTextLength >= 1 =>
// Special case handling for NaN and Infinity.
parser.getText match {
case "NaN" => Float.NaN
Expand All @@ -153,7 +153,7 @@ class JacksonParser(
case VALUE_NUMBER_INT | VALUE_NUMBER_FLOAT =>
parser.getDoubleValue

case VALUE_STRING =>
case VALUE_STRING if parser.getTextLength >= 1 =>
// Special case handling for NaN and Infinity.
parser.getText match {
case "NaN" => Double.NaN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2490,4 +2490,10 @@ class JsonSuite extends QueryTest with SharedSQLContext with TestJsonData {
assert(exception.getMessage.contains("encoding must not be included in the blacklist"))
}
}

test("SPARK-25040: empty strings should be treated as null for double and float") {
val df = spark.read.schema("a DOUBLE, b FLOAT")
.option("mode", "FAILFAST").json(Seq("""{"a":"","b": ""}""", """{"a": 1.1,"b": 1.1}""").toDS)
checkAnswer(df, Row(null, null) :: Row(1.1D, 1.1F) :: Nil)
}
}