Skip to content

Commit

Permalink
enable decimal to decimal cast of different precision and scale
Browse files Browse the repository at this point in the history
  • Loading branch information
himadripal committed Nov 14, 2024
1 parent 2c832b4 commit 471c2a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
12 changes: 12 additions & 0 deletions spark/src/test/scala/org/apache/comet/CometCastSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 471c2a7

Please sign in to comment.