From 471c2a727bd7c23e9e6c9080445632215113a0b4 Mon Sep 17 00:00:00 2001 From: himadripal Date: Thu, 14 Nov 2024 12:04:13 -0800 Subject: [PATCH] enable decimal to decimal cast of different precision and scale --- .../org/apache/comet/expressions/CometCast.scala | 3 +-- .../test/scala/org/apache/comet/CometCastSuite.scala | 12 ++++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spark/src/main/scala/org/apache/comet/expressions/CometCast.scala b/spark/src/main/scala/org/apache/comet/expressions/CometCast.scala index 11d6d049f..584220282 100644 --- a/spark/src/main/scala/org/apache/comet/expressions/CometCast.scala +++ b/spark/src/main/scala/org/apache/comet/expressions/CometCast.scala @@ -71,8 +71,7 @@ object CometCast { Unsupported } case (_: DecimalType, _: DecimalType) => - // https://github.com/apache/datafusion-comet/issues/375 - Incompatible() + Compatible() case (DataTypes.StringType, _) => canCastFromString(toType, timeZoneId, evalMode) case (_, DataTypes.StringType) => diff --git a/spark/src/test/scala/org/apache/comet/CometCastSuite.scala b/spark/src/test/scala/org/apache/comet/CometCastSuite.scala index db9a870dc..b6a535118 100644 --- a/spark/src/test/scala/org/apache/comet/CometCastSuite.scala +++ b/spark/src/test/scala/org/apache/comet/CometCastSuite.scala @@ -895,6 +895,18 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper { } } + test("cast between decimals with different precision and scale") { + // cast between default Decimal(38, 18) to Decimal(9,1) + val values = Seq(BigDecimal("12345.6789"), BigDecimal("9876.5432"), BigDecimal("123.4567")) + val df = withNulls(values).toDF("a") + castTest(df, DataTypes.createDecimalType(7, 2)) + } + + test("cast two between decimals with different precision and scale") { + // cast between Decimal(10, 2) to Decimal(9,1) + castTest(generateDecimalsPrecision10Scale2(), DataTypes.createDecimalType(9, 1)) + } + private def generateFloats(): DataFrame = { withNulls(gen.generateFloats(dataSize)).toDF("a") }