-
Notifications
You must be signed in to change notification settings - Fork 343
feat: support make_interval via codegen dispatch #5260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andygrove
wants to merge
1
commit into
apache:main
Choose a base branch
from
andygrove:feat/make-interval-codegen-dispatch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
spark/src/test/resources/sql-tests/expressions/datetime/make_interval.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| -- Licensed to the Apache Software Foundation (ASF) under one | ||
| -- or more contributor license agreements. See the NOTICE file | ||
| -- distributed with this work for additional information | ||
| -- regarding copyright ownership. The ASF licenses this file | ||
| -- to you under the Apache License, Version 2.0 (the | ||
| -- "License"); you may not use this file except in compliance | ||
| -- with the License. You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, | ||
| -- software distributed under the License is distributed on an | ||
| -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| -- KIND, either express or implied. See the License for the | ||
| -- specific language governing permissions and limitations | ||
| -- under the License. | ||
|
|
||
| -- make_interval runs through the codegen dispatcher and produces CalendarIntervalType. | ||
| -- The suite disables ANSI mode, so MakeInterval.failOnError is false here and overflow | ||
| -- yields NULL. See make_interval_ansi.sql for the throwing path. | ||
| -- Config: spark.comet.exec.scalaUDF.codegen.enabled=true | ||
|
|
||
| statement | ||
| CREATE TABLE test_make_interval(y int, mo int, w int, d int, h int, mi int, s decimal(18,6)) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_make_interval VALUES | ||
| (1, 2, 3, 4, 5, 6, 7.008009), | ||
| (30, 25, 0, -100, 40, 80, 299.889987), | ||
| (0, -1, 0, 1, 0, 0, -1.000000), | ||
| (-1, -2, -3, -4, -5, -6, -7.500000), | ||
| (0, 0, 0, 0, 0, 0, 0.000000), | ||
| (NULL, 2, 3, 4, 5, 6, 7.008009), | ||
| (1, 2, 3, 4, 5, 6, NULL) | ||
|
|
||
| -- all seven arguments as columns | ||
| query | ||
| SELECT make_interval(y, mo, w, d, h, mi, s) FROM test_make_interval | ||
|
|
||
| -- the shorter arities filled in by MakeInterval's auxiliary constructors | ||
| query | ||
| SELECT | ||
| make_interval(y), | ||
| make_interval(y, mo), | ||
| make_interval(y, mo, w), | ||
| make_interval(y, mo, w, d), | ||
| make_interval(y, mo, w, d, h), | ||
| make_interval(y, mo, w, d, h, mi) | ||
| FROM test_make_interval | ||
|
|
||
| -- mixed literal and column arguments | ||
| query | ||
| SELECT | ||
| make_interval(1, mo, 3, d, 5, mi, 7.008009), | ||
| make_interval(y, 2, w, 4, h, 6, s) | ||
| FROM test_make_interval | ||
|
|
||
| -- literal arguments (constant folding is disabled by the test suite) | ||
| query | ||
| SELECT | ||
| make_interval(1, 2, 3, 4, 5, 6, 7.008009), | ||
| make_interval(0, 0, 0, 0, 0, 0, 0), | ||
| make_interval(-1, -2, -3, -4, -5, -6, -7.5), | ||
| make_interval(0, 13, 0, 0, 25, 61, 61.5) | ||
|
|
||
| -- NULL arguments propagate. These have to come from nullable columns rather than NULL | ||
| -- literals: MakeInterval is NullIntolerant, so NullPropagation rewrites any call with a | ||
| -- literal NULL argument to a null interval literal and the expression never reaches Comet. | ||
| -- Such a literal currently fails natively rather than falling back, tracked by #5058. | ||
| query | ||
| SELECT | ||
| make_interval(y, 2, 3, 4, 5, 6, 7.008009), | ||
| make_interval(1, 2, 3, 4, 5, 6, s), | ||
| make_interval(y) | ||
| FROM test_make_interval | ||
|
|
||
| -- years * 12 exceeds the int range. Outside ANSI mode MakeInterval swallows the | ||
| -- ArithmeticException and returns NULL. | ||
| query | ||
| SELECT | ||
| make_interval(200000000, 0, 0, 0, 0, 0, 0), | ||
| make_interval(y + 200000000, mo, w, d, h, mi, s) | ||
| FROM test_make_interval |
49 changes: 49 additions & 0 deletions
49
spark/src/test/resources/sql-tests/expressions/datetime/make_interval_ansi.sql
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto as `make_interval.sql.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| -- Licensed to the Apache Software Foundation (ASF) under one | ||
| -- or more contributor license agreements. See the NOTICE file | ||
| -- distributed with this work for additional information | ||
| -- regarding copyright ownership. The ASF licenses this file | ||
| -- to you under the Apache License, Version 2.0 (the | ||
| -- "License"); you may not use this file except in compliance | ||
| -- with the License. You may obtain a copy of the License at | ||
| -- | ||
| -- http://www.apache.org/licenses/LICENSE-2.0 | ||
| -- | ||
| -- Unless required by applicable law or agreed to in writing, | ||
| -- software distributed under the License is distributed on an | ||
| -- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| -- KIND, either express or implied. See the License for the | ||
| -- specific language governing permissions and limitations | ||
| -- under the License. | ||
|
|
||
| -- MakeInterval.failOnError defaults to SQLConf.get.ansiEnabled, so in ANSI mode overflow | ||
| -- raises ARITHMETIC_OVERFLOW instead of returning NULL. The exception has to cross out of | ||
| -- the generated kernel and surface as the same Spark error. | ||
| -- See make_interval.sql for the non-ANSI coverage. | ||
| -- Config: spark.sql.ansi.enabled=true | ||
| -- Config: spark.comet.exec.scalaUDF.codegen.enabled=true | ||
|
|
||
| statement | ||
| CREATE TABLE test_make_interval_ansi(y int, mo int, w int, d int, h int, mi int, s decimal(18,6)) USING parquet | ||
|
|
||
| statement | ||
| INSERT INTO test_make_interval_ansi VALUES | ||
| (1, 2, 3, 4, 5, 6, 7.008009), | ||
| (-1, -2, -3, -4, -5, -6, -7.500000), | ||
| (NULL, 2, 3, 4, 5, 6, 7.008009) | ||
|
|
||
| -- valid inputs still evaluate normally under ANSI, and act as the sentinel proving the | ||
| -- expression is not silently falling back to Spark | ||
| query | ||
| SELECT make_interval(y, mo, w, d, h, mi, s) FROM test_make_interval_ansi | ||
|
|
||
| query | ||
| SELECT make_interval(1, 2, 3, 4, 5, 6, 7.008009) | ||
|
|
||
| -- years * 12 overflows the int range. Spark 3.5 renders ARITHMETIC_OVERFLOW without the | ||
| -- condition name in the message, so match on the shared "overflow" text instead. | ||
| query expect_error(overflow) | ||
| SELECT make_interval(200000000, 0, 0, 0, 0, 0, 0) | ||
|
|
||
| -- weeks * 7 overflows the int range | ||
| query expect_error(overflow) | ||
| SELECT make_interval(0, 0, 400000000, 0, 0, 0, 0) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could also add test cases which is from the review of native
make_intervalimpl: #5039 (comment)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
other reference: #5039 (comment)