Skip to content

Commit 6e28936

Browse files
committed
Address make_interval review feedback
1 parent 8693243 commit 6e28936

7 files changed

Lines changed: 130 additions & 15 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ The type-name conversion functions (`bigint`, `binary`, `boolean`, `date`, `deci
277277
| `localtimestamp` ||| |
278278
| `make_date` || Native | |
279279
| `make_dt_interval` || Codegen dispatch | |
280-
| `make_interval` || Hybrid | Routes through the JVM codegen dispatcher by default; the native path is opt-in via allowIncompatible ([details](compatibility/expressions/datetime.md)) |
280+
| `make_interval` || Hybrid | Routes through the JVM codegen dispatcher by default; intervals outside Arrow's nanosecond range are tracked by [#5279](https://github.com/apache/datafusion-comet/issues/5279); the native path is opt-in via allowIncompatible ([details](compatibility/expressions/datetime.md)) |
281281
| `make_time` | 🔜 || Spark 4.1 TIME type; tracked by [#4288](https://github.com/apache/datafusion-comet/issues/4288) |
282282
| `make_timestamp` || Hybrid | |
283283
| `make_timestamp_ltz` ||| 2-arg TIME form falls back |

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,16 +1132,9 @@ object QueryPlanSerde extends Logging with CometExprShim with CometTypeShim {
11321132
}
11331133

11341134
def scalarFunctionExprToProto(funcName: String, args: Option[Expr]*): Option[Expr] = {
1135-
scalarFunctionExprToProto(funcName, false, args: _*)
1136-
}
1137-
1138-
def scalarFunctionExprToProto(
1139-
funcName: String,
1140-
failOnError: Boolean,
1141-
args: Option[Expr]*): Option[Expr] = {
11421135
val builder = ExprOuterClass.ScalarFunc.newBuilder()
11431136
builder.setFunc(funcName)
1144-
builder.setFailOnError(failOnError)
1137+
builder.setFailOnError(false)
11451138
scalarFunctionExprToProto0(builder, args: _*)
11461139
}
11471140

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,12 @@ object CometMakeInterval extends CometExpressionSerde[MakeInterval] with Codegen
969969
" precision, and stores time in nanoseconds, which overflows for large time components" +
970970
" (hours, minutes, seconds) that Spark can represent."
971971

972+
override def getCompatibleNotes(): Seq[String] = Seq(
973+
"Both the default JVM codegen-dispatch path and the native path encode elapsed time as" +
974+
" Arrow nanoseconds. Spark intervals whose microseconds cannot be multiplied by 1,000" +
975+
" in an `i64` are not supported" +
976+
" ([#5279](https://github.com/apache/datafusion-comet/issues/5279)).")
977+
972978
override def getIncompatibleReasons(): Seq[String] = Seq(incompatReason)
973979

974980
override def getSupportLevel(expr: MakeInterval): SupportLevel =
@@ -979,7 +985,7 @@ object CometMakeInterval extends CometExpressionSerde[MakeInterval] with Codegen
979985
inputs: Seq[Attribute],
980986
binding: Boolean): Option[Expr] = {
981987
// The explicit return type skips DataFusion's registry coercion, but its kernel needs Float64.
982-
val children = expr.children.updated(6, Cast(expr.children(6), DoubleType))
988+
val children = expr.children.updated(6, Cast(expr.secs, DoubleType))
983989
val childExprs = children.map(exprToProtoInternal(_, inputs, binding))
984990
val optExpr = scalarFunctionExprToProtoWithReturnType(
985991
"make_interval",

spark/src/test/resources/sql-tests/expressions/datetime/make_interval_ansi.sql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ SELECT make_interval(1, 2, 3, 4, 5, 6, 7.123456)
3131
query
3232
SELECT make_interval(years) FROM test_make_interval_ansi
3333

34-
query expect_error(ARITHMETIC_OVERFLOW)
34+
query expect_error(overflow. If necessary set)
3535
SELECT make_interval(2147483647)
3636

37-
query expect_error(ARITHMETIC_OVERFLOW)
37+
query expect_error(overflow. If necessary set)
3838
SELECT make_interval(0, 0, 2147483647)
39+
40+
query ignore(https://github.com/apache/datafusion-comet/issues/5131)
41+
SELECT make_interval(0, 0, 0, 0, 2562048)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
-- With allowIncompatible unset, MakeInterval uses Spark's JVM codegen dispatcher.
19+
20+
statement
21+
CREATE TABLE test_make_interval_dispatch(
22+
years int,
23+
months int,
24+
weeks int,
25+
days int,
26+
hours int,
27+
mins int,
28+
secs decimal(18, 6)) USING parquet
29+
30+
statement
31+
INSERT INTO test_make_interval_dispatch VALUES
32+
(1, 2, 3, 4, 5, 6, 7.123456),
33+
(0, 1, 0, 1, 0, 0, 100.000001),
34+
(-1, -2, -1, -1, -1, -1, -1.500000),
35+
(NULL, 1, 2, 3, 4, 5, 6.000000),
36+
(2, NULL, 2, 3, 4, 5, 6.000000),
37+
(3, 1, 2, 3, 4, 5, NULL),
38+
(0, 0, 0, 0, 2562048, 0, 0.000000)
39+
40+
query
41+
SELECT make_interval(years, months, weeks, days, hours, mins, secs)
42+
FROM test_make_interval_dispatch
43+
WHERE hours != 2562048
44+
ORDER BY years
45+
46+
query ignore(https://github.com/apache/datafusion-comet/issues/5279)
47+
SELECT make_interval(0, 0, 0, 0, hours)
48+
FROM test_make_interval_dispatch
49+
WHERE hours = 2562048
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
-- Config: spark.sql.ansi.enabled=true
19+
20+
statement
21+
CREATE TABLE test_make_interval_dispatch_ansi(years int, weeks int, hours int) USING parquet
22+
23+
statement
24+
INSERT INTO test_make_interval_dispatch_ansi VALUES
25+
(1, 0, 5),
26+
(2147483647, 0, 0),
27+
(0, 2147483647, 0),
28+
(0, 0, 2562048)
29+
30+
query
31+
SELECT make_interval(years, 0, weeks, 0, hours)
32+
FROM test_make_interval_dispatch_ansi
33+
WHERE years = 1
34+
35+
query expect_error(overflow. If necessary set)
36+
SELECT make_interval(years)
37+
FROM test_make_interval_dispatch_ansi
38+
WHERE years = 2147483647
39+
40+
query expect_error(overflow. If necessary set)
41+
SELECT make_interval(0, 0, weeks)
42+
FROM test_make_interval_dispatch_ansi
43+
WHERE weeks = 2147483647
44+
45+
query ignore(https://github.com/apache/datafusion-comet/issues/5279)
46+
SELECT make_interval(0, 0, 0, 0, hours)
47+
FROM test_make_interval_dispatch_ansi
48+
WHERE hours = 2562048

spark/src/test/resources/sql-tests/expressions/datetime/try_make_interval.sql

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,24 @@
1616
-- under the License.
1717

1818
-- MinSparkVersion: 4.0
19-
-- Config: spark.sql.ansi.enabled=true
20-
-- Config: spark.comet.exec.scalaUDF.codegen.enabled=true
19+
-- ConfigMatrix: spark.sql.ansi.enabled=true,false
20+
21+
statement
22+
CREATE TABLE test_try_make_interval(
23+
years int,
24+
months int,
25+
weeks int,
26+
days int,
27+
hours int,
28+
mins int,
29+
secs decimal(18, 6)) USING parquet
30+
31+
statement
32+
INSERT INTO test_try_make_interval VALUES
33+
(1, 2, 3, 4, 5, 6, 7.123456),
34+
(2147483647, 0, 0, 0, 0, 0, 0.000000)
2135

2236
query
23-
SELECT try_make_interval(2147483647)
37+
SELECT try_make_interval(years, months, weeks, days, hours, mins, secs)
38+
FROM test_try_make_interval
39+
ORDER BY years

0 commit comments

Comments
 (0)