[
https://issues.apache.org/jira/browse/SPARK-5456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14516195#comment-14516195
]
Yi Zhang commented on SPARK-5456:
---------------------------------
I got same issue. When I access Postgresql based on Spark SQL, and the code is
as below:
dataFrame.registerTempTable("Employees")
val emps = sqlContext.sql("select name, sum(salary) from Employees group by
name")
monitor {
emps.take(10)
.map(row => (row.getString(0), row.getDecimal(1)))
.foreach(println)
}
The type of salary column in data table of Postgresql is numeric(10, 2).
Running it, then it throws the following exception:
Exception in thread "main" org.apache.spark.SparkException: Job aborted due to
stage failure: Task 0 in stage 0.0 failed 1 times, most recent failure: Lost
task 0.0 in stage 0.0 (TID 0, localhost): java.lang.ClassCastException:
java.math.BigDecimal cannot be cast to org.apache.spark.sql.types.Decimal
> Decimal Type comparison issue
> -----------------------------
>
> Key: SPARK-5456
> URL: https://issues.apache.org/jira/browse/SPARK-5456
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 1.2.0, 1.3.0
> Reporter: Kuldeep
> Priority: Blocker
>
> Not quite able to figure this out but here is a junit test to reproduce this,
> in JavaAPISuite.java
> {code:title=DecimalBug.java}
> @Test
> public void decimalQueryTest() {
> List<Row> decimalTable = new ArrayList<Row>();
> decimalTable.add(RowFactory.create(new BigDecimal("1"), new
> BigDecimal("2")));
> decimalTable.add(RowFactory.create(new BigDecimal("3"), new
> BigDecimal("4")));
> JavaRDD<Row> rows = sc.parallelize(decimalTable);
> List<StructField> fields = new ArrayList<StructField>(7);
> fields.add(DataTypes.createStructField("a",
> DataTypes.createDecimalType(), true));
> fields.add(DataTypes.createStructField("b",
> DataTypes.createDecimalType(), true));
> sqlContext.applySchema(rows.rdd(),
> DataTypes.createStructType(fields)).registerTempTable("foo");
> Assert.assertEquals(sqlContext.sql("select * from foo where a >
> 0").collectAsList(), decimalTable);
> }
> {code}
> Fails with
> java.lang.ClassCastException: java.math.BigDecimal cannot be cast to
> org.apache.spark.sql.types.Decimal
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]