kazuyukitanimura commented on code in PR #1086:
URL: https://github.com/apache/datafusion-comet/pull/1086#discussion_r1851044973
##########
spark/src/test/scala/org/apache/comet/CometCastSuite.scala:
##########
@@ -895,6 +895,34 @@ class CometCastSuite extends CometTestBase with
AdaptiveSparkPlanHelper {
}
}
+ test("cast between decimals with different precision and scale") {
+ // cast between default Decimal(38, 18) to Decimal(6,2)
+ val values = Seq(BigDecimal("12345.6789"), BigDecimal("9876.5432"),
BigDecimal("123.4567"))
+ val df = withNulls(values)
+ .toDF("b")
+ .withColumn("a", col("b").cast(DecimalType(6, 2)))
+ checkSparkAnswer(df)
Review Comment:
FYI, ideally this should be checkSparkAnswerAndOperator once precision
change gets supported
##########
spark/src/test/scala/org/apache/comet/CometCastSuite.scala:
##########
@@ -895,6 +895,34 @@ class CometCastSuite extends CometTestBase with
AdaptiveSparkPlanHelper {
}
}
+ test("cast between decimals with different precision and scale") {
+ // cast between default Decimal(38, 18) to Decimal(6,2)
+ val values = Seq(BigDecimal("12345.6789"), BigDecimal("9876.5432"),
BigDecimal("123.4567"))
+ val df = withNulls(values)
+ .toDF("b")
+ .withColumn("a", col("b").cast(DecimalType(6, 2)))
+ checkSparkAnswer(df)
+ }
+
+ test("cast between decimals with higher precision than source") {
+ // cast between Decimal(10, 2) to Decimal(10,4)
+ castTest(generateDecimalsPrecision10Scale2(),
DataTypes.createDecimalType(10, 4))
+ }
+
+ test("cast between decimals with negative precision") {
+ // cast to negative scale
+ checkSparkMaybeThrows(
+ spark.sql("select a, cast(a as DECIMAL(10,-4)) from t order by a"))
match {
+ case (expected, actual) =>
+ assert(expected.contains("PARSE_SYNTAX_ERROR") ===
actual.contains("PARSE_SYNTAX_ERROR"))
+ }
+ }
+
+ test("cast between decimals with zero precision") {
+ // cast between Decimal(10, 2) to Decimal(10,4)
Review Comment:
Nit: the comment should be `to Decimal(10, 0)`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]