Repository navigation
Spark, Databricks: parse multi-unit interval literals - #2616
Draft
moshap-firebolt wants to merge 6 commits into
Draft
moshap-firebolt wants to merge 6 commits into
moshap-firebolt wants to merge 6 commits into
Conversation
Spark's multi-units interval syntax lets the string carry its own units, as in INTERVAL '1 YEAR 2 DAYS 3 HOURS', so no unit follows the literal. Databricks Runtime parses with the same grammar. A unit after a literal is still read; the expression form this gives up (INTERVAL 1 + 1 DAY) is not Spark syntax.
moshap-firebolt
marked this pull request as draft
October 6, 2026 21:34
moshap-firebolt
force-pushed
the
moshap/upstream-interval-multi-units
branch
from
October 6, 2026 21:35
e3732a5 to
f696fd3
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2616 +/- ##
==========================================
+ Coverage 81.14% 81.23% +0.08%
==========================================
Files 42 42
Lines 33736 33966 +230
Branches 33736 33966 +230
==========================================
+ Hits 27376 27592 +216
+ Misses 2797 2796 -1
- Partials 3563 3578 +15 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Address review: turning require_interval_qualifier off accepted INTERVAL 1 and read SELECT interval FROM t as SELECT INTERVAL FROM AS t. Keep it on and add supports_interval_string_without_qualifier: the value must be a literal, and only an unsigned string may omit the qualifier. INTERVAL is not reserved for these dialects, so SELECT interval FROM t reads a column.
moshap-firebolt
force-pushed
the
moshap/upstream-interval-multi-units
branch
from
October 8, 2026 00:32
f696fd3 to
0e240d3
Compare
…ter interval is arithmetic Address review: a double-quoted string is a Spark string literal, so it may be an interval value and may omit the qualifier (INTERVAL "2 months", INTERVAL "1" DAY). Only a bare number or a string after INTERVAL keeps the interval error; a signed number falls back to the identifier, so interval - 1 and INTERVAL -1 are arithmetic on the column, as in Spark. A string window frame bound stays a string literal in these dialects (RANGE BETWEEN '1 day' PRECEDING), as in Spark, rather than being read as an interval without a qualifier.
moshap-firebolt
force-pushed
the
moshap/upstream-interval-multi-units
branch
from
October 14, 2026 01:42
0e240d3 to
3a4d8c3
Compare
Address review: Spark accepts INTERVAL '1' DAY TO as an alias, so assert the error on TO x instead. parse_interval_number_without_unit_error and parse_interval_expression_value repeat test_interval_numeric_requires_unit and parse_interval_require_qualifier. The guard comment now covers strings as well as numbers.
Spark's multi-units interval syntax lists several value / unit pairs, INTERVAL 10 YEAR 20 MONTH, documented as the same as the string form INTERVAL '10 YEAR 20 MONTH'. A new supports_interval_multi_units hook, enabled for SparkSqlDialect and DatabricksDialect, reads the extra pairs into that string form, so the AST is unchanged.
A double-quoted string is a Spark string literal, so it may be any value of a multi-units interval, e.g. INTERVAL "1" DAY "2" HOUR.
moshap-firebolt
force-pushed
the
moshap/upstream-interval-multi-units
branch
from
October 16, 2026 16:41
c665a51 to
f559398
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on #2614, whose commits this branch includes; only the last two commits are new. It needs #2614 because the string form below has no unit, which Spark and Databricks reject until #2614 lands. I will rebase onto
mainonce #2614 merges.Spark's multi-units interval syntax lists several value / unit pairs,
INTERVAL 10 YEAR 20 MONTH, documented as equivalent toINTERVAL '10 YEAR 20 MONTH'.This adds
Dialect::supports_interval_multi_units, enabled forSparkSqlDialectandDatabricksDialect. When set,parse_intervalreads the extra pairs into that string form, so the AST is unchanged. Values may be numbers or single- or double-quoted strings, optionally signed. A single unit, or a unit followed by something else (INTERVAL 3 DAY + 1), parses as before. Tests insqlparser_common.rscover dialects with and without the hook.