Skip to content

Commit 523ffb6

Browse files
authored
fix: allow EvalMode.TRY in CometRemainder to support try_mod (#4615)
1 parent 4f8791e commit 523ffb6

3 files changed

Lines changed: 53 additions & 6 deletions

File tree

docs/source/user-guide/latest/expressions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ All higher-order functions are planned via [#4224](https://github.com/apache/dat
389389

390390
| Function | Status | Notes |
391391
| --- | --- | --- |
392-
| `%` || try_mod (TRY mode) falls back |
392+
| `%` || |
393393
| `*` || Interval multiplication falls back |
394394
| `+` || |
395395
| `-` || |
@@ -453,7 +453,7 @@ All higher-order functions are planned via [#4224](https://github.com/apache/dat
453453
| `tanh` || |
454454
| `try_add` || Datetime/interval form falls back |
455455
| `try_divide` || |
456-
| `try_mod` | 🔜 | Lowers to `Remainder` with TRY eval mode, which falls back ([#4484](https://github.com/apache/datafusion-comet/issues/4484)) |
456+
| `try_mod` | | |
457457
| `try_multiply` || |
458458
| `try_subtract` || |
459459
| `unhex` || |

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ object CometRemainder extends CometExpressionSerde[Remainder] with MathBase {
267267
withFallbackReason(expr, s"Unsupported datatype ${expr.left.dataType}")
268268
return None
269269
}
270-
if (expr.evalMode == EvalMode.TRY) {
271-
withFallbackReason(expr, s"Eval mode ${expr.evalMode} is not supported")
272-
return None
273-
}
274270

275271
createMathExpression(
276272
expr,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- TRY mode arithmetic tests for Remainder (try_mod)
19+
-- try_mod returns NULL on divide-by-zero instead of throwing
20+
21+
-- MinSparkVersion: 4.0
22+
23+
statement
24+
CREATE TABLE try_mod_int(a int, b int) USING parquet
25+
26+
statement
27+
INSERT INTO try_mod_int VALUES (10, 3), (10, 0), (0, 0), (NULL, 1), (10, NULL), (-10, 3), (10, -3)
28+
29+
query
30+
SELECT try_mod(a, b) FROM try_mod_int
31+
32+
query
33+
SELECT try_mod(10, 3)
34+
35+
query
36+
SELECT try_mod(10, 0)
37+
38+
query
39+
SELECT try_mod(NULL, 1)
40+
41+
query
42+
SELECT try_mod(10, NULL)
43+
44+
statement
45+
CREATE TABLE try_mod_long(a long, b long) USING parquet
46+
47+
statement
48+
INSERT INTO try_mod_long VALUES (10L, 3L), (10L, 0L), (0L, 0L), (NULL, 1L), (10L, NULL)
49+
50+
query
51+
SELECT try_mod(a, b) FROM try_mod_long

0 commit comments

Comments
 (0)