You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Hyukjin Kwon (JIRA)" <ji...@apache.org> on 2016/03/28 07:12:25 UTC

[jira] [Commented] (SPARK-14189) JSON data source infers a field type as StringType when some are inferred as DecimalType not capable of IntegralType.

    [ https://issues.apache.org/jira/browse/SPARK-14189?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15213817#comment-15213817 ] 

Hyukjin Kwon commented on SPARK-14189:
--------------------------------------

I can work on this.

> JSON data source infers a field type as StringType when some are inferred as DecimalType not capable of IntegralType.
> ---------------------------------------------------------------------------------------------------------------------
>
>                 Key: SPARK-14189
>                 URL: https://issues.apache.org/jira/browse/SPARK-14189
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.0.0
>            Reporter: Hyukjin Kwon
>
> When inferred types in the same field during finding competible {{DataType}} are {{IntegralType}} and {{DecimalType}} but {{DecimalType}} is not capable of the given {{IntegralType}}, JSON data source simply parses this as {{StringType}}.
> This can be observed when {{floatAsBigDecimal}} is enabled.
> {code}
> 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()
> {code}
> produces below:
> {code}
> root
>  |-- a: string (nullable = true)
>  |-- b: string (nullable = true)
> {code}
>  When {{floatAsBigDecimal}} is disabled.
> {code}
> def mixedIntegerAndDoubleRecords: RDD[String] =
>   sqlContext.sparkContext.parallelize(
>     """{"a": 3, "b": 1.1}""" ::
>     """{"a": 3.1, "b": 1}""" :: Nil)
> val jsonDF = sqlContext.read
>   .option("floatAsBigDecimal", "false")
>   .json(mixedIntegerAndDoubleRecords)
>   .printSchema()
> {code}
> produces below correctly:
> {code}
> root
>  |-- a: double (nullable = true)
>  |-- b: double (nullable = true)
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org