Skip to content

Spark, Databricks: port upstream interval PRs #2614 and #2616 - #19

Merged
moshap-firebolt merged 9 commits into
firebolt/v0.63.0-patchesfrom
moshap/port-upstream-intervals
Oct 22, 2026
Merged

moshap-firebolt merged 9 commits into
firebolt/v0.63.0-patchesfrom
moshap/port-upstream-intervals

Conversation

@moshap-firebolt

@moshap-firebolt moshap-firebolt commented Oct 14, 2026 •

Copy link
Copy Markdown

Replaces #16 and #17 with the versions under upstream review, apache/datafusion-sqlparser-rs#2614 and #2616, which went further after review: INTERVAL is a column name when no literal follows (SELECT interval FROM t, interval - 1), a double-quoted string is an interval value, a bare number still requires a unit, and a string window frame bound stays a string literal.

Reverts #17 and #16 on top of #18, then cherry-picks the six upstream commits unchanged (four from apache#2614, two from apache#2616). The src/ and test changes are identical, line for line, to the upstream PRs; only conflict context in imports and test-file tails differs. The fork's full suite (--all-features), fmt and clippy are clean.

🤖 Generated with Claude Code


Note

Medium Risk
Changes expression parsing and AST shape for Spark/Databricks intervals and reserved-word fallback; other dialects are mostly unaffected but shared parser paths were touched.

Overview
Aligns Spark and Databricks interval parsing with upstream sqlparser behavior via a new dialect flag, supports_interval_string_without_qualifier.

For those dialects, INTERVAL '2 months' (and similar string literals, including double-quoted values) can omit an explicit unit; bare INTERVAL 1 and INTERVAL 1 + 1 DAY are rejected, while numeric intervals with an explicit unit still parse. INTERVAL is treated as a column name when it is not immediately followed by a number or string literal (e.g. SELECT interval FROM t, interval - 1).

Core parser updates route interval values through parse_interval_literal_value, tighten when a unit qualifier is required, and stop treating quoted window frame bounds like '1 day' as interval literals on these dialects. Shared tests cover the new rules; Spark and Databricks suites add targeted interval cases.

Reviewed by Cursor Bugbot for commit 485484d. Bugbot is set up for automated code reviews on this repo. Configure here.

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.
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.
…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.
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
moshap-firebolt force-pushed the moshap/port-upstream-intervals branch from c0c01aa to a70bb84 Compare October 20, 2026 01:02
…ue_arithmetic

clippy's assertions_on_result_states rejects assert!(... .is_err()).
Compare the message instead, as test_interval_numeric_requires_unit does.
@moshap-firebolt
moshap-firebolt merged commit bc3d1b5 into firebolt/v0.63.0-patches Oct 22, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant