Skip to content

Commit beb8cf6

Browse files
author
Bhargava Vadlamani
committed
support_ansi_mode_integral_divide
1 parent 48514ac commit beb8cf6

3 files changed

Lines changed: 26 additions & 18 deletions

File tree

native/core/src/execution/planner.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ impl PhysicalPlanner {
287287
)
288288
}
289289
ExprStruct::IntegralDivide(expr) => {
290-
// TODO respect eval mode
291-
// https://github.com/apache/datafusion-comet/issues/533
292290
let eval_mode = from_protobuf_eval_mode(expr.eval_mode)?;
293291
self.create_binary_expr_with_options(
294292
expr.left.as_ref().unwrap(),
@@ -987,11 +985,12 @@ impl PhysicalPlanner {
987985
} else {
988986
"decimal_div"
989987
};
990-
let fun_expr = create_comet_physical_fun(
988+
let fun_expr = create_comet_physical_fun_with_eval_mode(
991989
func_name,
992990
data_type.clone(),
993991
&self.session_ctx.state(),
994992
None,
993+
eval_mode,
995994
)?;
996995
Ok(Arc::new(ScalarFunctionExpr::new(
997996
func_name,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ object CometIntegralDivide extends CometExpressionSerde[IntegralDivide] with Mat
200200

201201
val rightExpr = if (expr.evalMode != EvalMode.ANSI) nullIfWhenPrimitive(right) else right
202202

203-
val dataType = (left.dataType, right.dataType) match {
203+
val dataType = (left.dataType, rightExpr.dataType) match {
204204
case (l: DecimalType, r: DecimalType) =>
205205
// copy from IntegralDivide.resultDecimalType
206206
val intDig = l.precision - l.scale + r.scale

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2988,20 +2988,29 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
29882988
}
29892989

29902990
test("ANSI support for integral divide (division by zero)") {
2991-
val data = Seq((Integer.MIN_VALUE, 0))
2992-
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
2993-
withParquetTable(data, "tbl") {
2994-
val res = spark.sql("""
2995-
|SELECT
2996-
| _1 div _2
2997-
| from tbl
2998-
| """.stripMargin)
2999-
3000-
checkSparkMaybeThrows(res) match {
3001-
case (Some(sparkExc), Some(cometExc)) =>
3002-
assert(cometExc.getMessage.contains(DIVIDE_BY_ZERO_EXCEPTION_MSG))
3003-
assert(sparkExc.getMessage.contains("Division by zero"))
3004-
case _ => fail("Exception should be thrown")
2991+
val data = Seq((Integer.MAX_VALUE, 0))
2992+
Seq("true", "false").foreach { p =>
2993+
withSQLConf(SQLConf.ANSI_ENABLED.key -> "true") {
2994+
withParquetTable(data, "tbl") {
2995+
val res = spark.sql("""
2996+
|SELECT
2997+
| _1 div _2
2998+
| from tbl
2999+
| """.stripMargin)
3000+
3001+
checkSparkMaybeThrows(res) match {
3002+
case (Some(sparkException), Some(cometException)) =>
3003+
assert(sparkException.getMessage.contains(DIVIDE_BY_ZERO_EXCEPTION_MSG))
3004+
assert(cometException.getMessage.contains(DIVIDE_BY_ZERO_EXCEPTION_MSG))
3005+
case (None, None) => checkSparkAnswerAndOperator(res)
3006+
case (None, Some(ex)) =>
3007+
fail(
3008+
"Comet threw an exception but Spark did not. Comet exception: " + ex.getMessage)
3009+
case (Some(sparkException), None) =>
3010+
fail(
3011+
"Spark threw an exception but Comet did not. Spark exception: " +
3012+
sparkException.getMessage)
3013+
}
30053014
}
30063015
}
30073016
}

0 commit comments

Comments
 (0)