Skip to content

Commit 8e120dc

Browse files
author
Bhargava Vadlamani
committed
cast_operands_to_decimal_integral_division
1 parent da4c671 commit 8e120dc

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

spark/src/main/scala/org/apache/comet/serde/arithmetic.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ object CometIntegralDivide extends CometExpressionSerde with MathBase {
213213

214214
val left =
215215
if (div.left.dataType.isInstanceOf[DecimalType]) div.left
216-
else Cast(div.left, DecimalType(DecimalType.MAX_PRECISION, DecimalType.MAX_SCALE))
216+
else Cast(div.left, DecimalType(19, 0))
217217
val right =
218218
if (div.right.dataType.isInstanceOf[DecimalType]) div.right
219-
else Cast(div.right, DecimalType(DecimalType.MAX_PRECISION, DecimalType.MAX_SCALE))
219+
else Cast(div.right, DecimalType(19, 0))
220220

221221
val rightExpr = nullIfWhenPrimitive(right)
222222

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,13 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
115115

116116
test("Integral Division Overflow Handling Matches Spark Behavior") {
117117
withTable("t1") {
118+
withSQLConf(CometConf.COMET_CAST_ALLOW_INCOMPATIBLE.key -> "true"){
118119
val value = Long.MinValue
119120
sql("create table t1(c1 long, c2 short) using parquet")
120121
sql(s"insert into t1 values($value, -1)")
121122
val res = sql("select c1 div c2 from t1 order by c1")
122-
checkSparkAnswer(res)
123+
checkSparkAnswerAndOperator(res)
124+
}
123125
}
124126
}
125127

0 commit comments

Comments
 (0)