You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Yin Huai (JIRA)" <ji...@apache.org> on 2015/07/16 23:12:04 UTC

[jira] [Commented] (SPARK-9119) In some cases, we may save wrong decimal values to parquet

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

Yin Huai commented on SPARK-9119:
---------------------------------

The current workaround is to explicitly specify the precision and scale when create the decimal value.
{code}
import org.apache.spark.sql.Row
import org.apache.spark.sql.types.{StructType,StructField,StringType,DecimalType}
import org.apache.spark.sql.types.Decimal
import java.math.BigDecimal

val schema = StructType(Array(StructField("name", DecimalType(10, 5), false)))
val rowRDD = sc.parallelize(Array(Row(Decimal(new BigDecimal("67123.45"), 10, 5))))
val df = sqlContext.createDataFrame(rowRDD, schema)
df.registerTempTable("test")
df.show()
// +-----------+
// |       name|
// +-----------+
// |67123.45000|
// +-----------+

sqlContext.sql("create table testDecimal as select * from test")
sqlContext.table("testDecimal").show()
// +-----------+
// |       name|
// +-----------+
// |67123.45000|
// +-----------+
{code}

> In some cases, we may save wrong decimal values to parquet
> ----------------------------------------------------------
>
>                 Key: SPARK-9119
>                 URL: https://issues.apache.org/jira/browse/SPARK-9119
>             Project: Spark
>          Issue Type: Sub-task
>          Components: SQL
>            Reporter: Yin Huai
>            Priority: Critical
>
> {code}
> > 
> import org.apache.spark.sql.Row
> import org.apache.spark.sql.types.{StructType,StructField,StringType,DecimalType}
> import org.apache.spark.sql.types.Decimal
> ​
> val schema = StructType(Array(StructField("name", DecimalType(10, 5), false)))
> val rowRDD = sc.parallelize(Array(Row(Decimal("67123.45"))))
> val df = sqlContext.createDataFrame(rowRDD, schema)
> df.registerTempTable("test")
> df.show()
> ​
> // +--------+
> // |    name|
> // +--------+
> // |67123.45|
> // +--------+
> sqlContext.sql("create table testDecimal as select * from test")
> sqlContext.table("testDecimal").show()
> // +--------+
> // |    name|
> // +--------+
> // |67.12345|
> // +--------+
> {code}
> The problem is when we do conversions, we do not use precision/scale info in the schema.



--
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