Github user davies commented on a diff in the pull request:
https://github.com/apache/spark/pull/12030#discussion_r58302741
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/json/JsonSuite.scala
---
@@ -773,6 +773,45 @@ class JsonSuite extends QueryTest with
SharedSQLContext with TestJsonData {
)
}
+ test("Infer big integers as doubles when it does not fit in decimal") {
+ val jsonDF = sqlContext.read
+ .json(doubleRecords)
+ .selectExpr("a", "c")
+
+ // The values in `a` field will be doubles as they all do not fit in
decimal. For `c` field,
+ // it will be also doubles as `9.223372036854776E19` can be a decimal
but `2.0E38` becomes
+ // a double as it does not fit in decimal. It makes the type as double
in this case.
+ val expectedSchema = StructType(
+ StructField("a", DoubleType, true) ::
+ StructField("c", DoubleType, true):: Nil)
+
+ assert(expectedSchema === jsonDF.schema)
+ checkAnswer(
+ jsonDF,
+ Seq(Row(1.0E38D, 9.223372036854776E19), Row(2.0E38D, 2.0E38D))
+ )
+ }
+
+ test("Infer floating-point values as doubles when it does not fit in
decimal") {
+ val jsonDF = sqlContext.read
+ .option("prefersDecimal", "true")
+ .json(doubleRecords)
+ .selectExpr("b", "d")
--- End diff --
It's better to check the schema of all columns
---
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]