spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hyukjin Kwon (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (SPARK-14189) JSON data source infers a field type as StringType when some are inferred as DecimalType not capable of IntegralType.
Date Mon, 28 Mar 2016 05:11:25 GMT

     [ https://issues.apache.org/jira/browse/SPARK-14189?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Hyukjin Kwon updated SPARK-14189:
---------------------------------
    Description: 
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}


  was:
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 parse 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}



> 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


Mime
View raw message