Repository navigation
Spark, Databricks: port upstream interval PRs #2614 and #2616 - #19
Open
moshap-firebolt wants to merge 7 commits into
Open
moshap-firebolt wants to merge 7 commits into
moshap-firebolt wants to merge 7 commits into
Conversation
This reverts commit bae1cb2.
)" This reverts commit ee51174.
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.
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.
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.
Replaces #16 and #17 with the versions under upstream review, apache/datafusion-sqlparser-rs#2614 and #2616, which went further after review:
INTERVALis 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, then cherry-picks the five upstream commits unchanged. 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 core expression parsing for INTERVAL across Spark/Databricks and shared parser paths; misclassification could affect downstream SQL planners, though behavior is heavily test-covered.
Overview
Aligns Spark and Databricks interval parsing with upstream semantics by splitting “require a unit” from “unit may live inside the string literal.”
Adds
Dialect::supports_interval_string_without_qualifier()and turns it on for Spark/Databricks together withrequire_interval_qualifier() = true. Those dialects also overrideis_reserved_for_identifiersoINTERVALcan name a column when it is not followed by a literal (SELECT interval FROM t,interval - 1).Parser updates:
parse_interval()uses a newparse_interval_literal_value()path for string-without-qualifier dialects; bare numericINTERVAL 1stays an error;INTERVAL 1 + 1 DAYis rejected for that mode; double-quoted interval values are accepted; window frame bounds keep'1 day'as a string instead ofINTERVALwhen the dialect supports string intervals without qualifiers; failedINTERVALparses no longer fall back to identifiers when a number/string literal follows.Tests in common, Spark, and Databricks cover the new matrix and tighten existing interval tests to exclude the new dialect behavior.
Reviewed by Cursor Bugbot for commit c0c01aa. Bugbot is set up for automated code reviews on this repo. Configure here.