You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2018/12/14 12:34:42 UTC

[GitHub] mgaido91 commented on a change in pull request #23308: [SPARK-26308][SQL] Infer abstract decimal type for java/scala BigDecimal

mgaido91 commented on a change in pull request #23308: [SPARK-26308][SQL] Infer abstract decimal type for java/scala BigDecimal
URL: https://github.com/apache/spark/pull/23308#discussion_r241740706
 
 

 ##########
 File path: sql/core/src/test/scala/org/apache/spark/sql/UDFSuite.scala
 ##########
 @@ -420,4 +420,14 @@ class UDFSuite extends QueryTest with SharedSQLContext {
       checkAnswer(df, Seq(Row("null1x"), Row(null), Row("N3null")))
     }
   }
+
+  test("SPARK-26308: udf with decimal") {
+    val df1 = spark.createDataFrame(
+      sparkContext.parallelize(Seq(Row(new java.math.BigDecimal("2011000000000002456556")))),
+      StructType(Seq(StructField("col1", DecimalType(30, 0)))))
+    val udf1 = org.apache.spark.sql.functions.udf((value: java.math.BigDecimal) => {
+      if (value == null) null else value.toBigInteger.toString
 
 Review comment:
   before this fix, the value passed here is null. This happens because the decimal value is casted to `Decimal(38, 18)` which is not enough to contain that value: so it becomes null. I preferred the test to fail for a bad result rather than a NPE, without this fix.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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