Skip to content

Commit 471c2a7

Browse files
author
himadripal
committed
enable decimal to decimal cast of different precision and scale
1 parent 2c832b4 commit 471c2a7

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spark/src/main/scala/org/apache/comet/expressions/CometCast.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ object CometCast {
7171
Unsupported
7272
}
7373
case (_: DecimalType, _: DecimalType) =>
74-
// https://github.com/apache/datafusion-comet/issues/375
75-
Incompatible()
74+
Compatible()
7675
case (DataTypes.StringType, _) =>
7776
canCastFromString(toType, timeZoneId, evalMode)
7877
case (_, DataTypes.StringType) =>

spark/src/test/scala/org/apache/comet/CometCastSuite.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,18 @@ class CometCastSuite extends CometTestBase with AdaptiveSparkPlanHelper {
895895
}
896896
}
897897

898+
test("cast between decimals with different precision and scale") {
899+
// cast between default Decimal(38, 18) to Decimal(9,1)
900+
val values = Seq(BigDecimal("12345.6789"), BigDecimal("9876.5432"), BigDecimal("123.4567"))
901+
val df = withNulls(values).toDF("a")
902+
castTest(df, DataTypes.createDecimalType(7, 2))
903+
}
904+
905+
test("cast two between decimals with different precision and scale") {
906+
// cast between Decimal(10, 2) to Decimal(9,1)
907+
castTest(generateDecimalsPrecision10Scale2(), DataTypes.createDecimalType(9, 1))
908+
}
909+
898910
private def generateFloats(): DataFrame = {
899911
withNulls(gen.generateFloats(dataSize)).toDF("a")
900912
}

0 commit comments

Comments
 (0)