GitHub user HyukjinKwon opened a pull request:
https://github.com/apache/spark/pull/11993
[SPARK-14189][SQL] JSON data sources find compatible types even if inferred
decimal type is not capable of the others
## What changes were proposed in this pull request?
When inferred types in the same field during finding compatible `DataType`,
are `IntegralType` and `{DecimalType` but `DecimalType` is not capable of the
given `IntegralType`, JSON data source simply fails to find a compatible type
resulting in `StringType`.
This can be observed when `floatAsBigDecimal` is enabled.
```scala
def mixedIntegerAndDoubleRecords: RDD[String] =
sqlContext.sparkContext.parallelize(
"""{"a": 3, "b": 1.1}""" ::
"""{"a": 3.1, "b": 1}""" :: Nil)
val jsonDF = sqlContext.read
.option("floatAsBigDecimal", "true")
.json(mixedIntegerAndDoubleRecords)
.printSchema()
```
- **Before**
```
root
|-- a: string (nullable = true)
|-- b: string (nullable = true)
```
- **After**
```
root
|-- a: decimal(21, 1) (nullable = true)
|-- b: decimal(21, 1) (nullable = true)
```
## How was this patch tested?
unit tests were used and style tests by `dev/run_tests`.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/HyukjinKwon/spark SPARK-14189
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/11993.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #11993
----
commit 2eb7ed9cbfadbb10d1e07c0a20eeb50beadccea6
Author: hyukjinkwon <[email protected]>
Date: 2016-03-28T05:17:06Z
Infer a correct compatible type even if inferred decimal type is not
capable of others
commit 45f8e939ee7997c15df73737f254a0170c080ac5
Author: hyukjinkwon <[email protected]>
Date: 2016-03-28T05:18:07Z
Fix commnets in tests
----
---
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]