Skip to content

Spark, Databricks: parse DIV, USING, LONG, 1L, exists() and backslash escapes in both - #21

Open
moshap-firebolt wants to merge 5 commits into
firebolt/v0.63.0-patchesfrom
spark-databricks-parity
Open

moshap-firebolt wants to merge 5 commits into
firebolt/v0.63.0-patchesfrom
spark-databricks-parity

Conversation

@moshap-firebolt

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

Copy link
Copy Markdown

Databricks SQL is Spark SQL plus extensions, but each dialect parsed pieces the other did not.

  • Databricks did not parse a DIV b, CREATE TABLE ... USING fmt or the LONG type. It now does; the DIV infix is shared with Spark.
  • Databricks read 1L as an identifier that starts with a digit, because its numeric-prefix rule ran before the L suffix. A new dialect hook, supports_long_suffix_before_numeric_prefix, lets an uppercase L that ends the number win; Databricks and Hive opt in, MySQL does not, and 1La is still an identifier. This matches the upstream draft; lowercase 1l stays an identifier under Databricks.
  • Spark parsed exists(arr, x -> ...) as an EXISTS subquery. It is now a function, as under Databricks, unless the parentheses hold a query, parenthesized or not; NOT exists(...) negates the function.
  • Spark did not read backslash escapes in string literals, so 'it\'s' was unterminated. Spark reads them; \% and \_ stay as written, as they already do for Databricks.

New tests in sqlparser_spark.rs and sqlparser_databricks.rs cover each. The full suite (--all-features), fmt and clippy are clean.

🤖 Generated with Claude Code


Note

Medium Risk
Changes core expression parsing, tokenization, and EXISTS disambiguation across Spark, Databricks, and Hive, which could affect downstream AST shape for edge cases.

Overview
Aligns Spark and Databricks parsing where each dialect previously handled the same syntax differently.

Databricks now parses DIV (via shared parse_div_infix with Spark), CREATE TABLE ... USING, LONG as BIGINT, and the collection exists(...) function hook. 1L is tokenized as a BIGINT literal instead of a digit-prefixed identifier when supports_long_suffix_before_numeric_prefix is enabled (Databricks and Hive; 1La stays an identifier).

Spark treats exists(arr, lambda) as a function call while EXISTS (SELECT …) remains a subquery, using a new supports_exists_function dialect flag and maybe_parse_exists_expr instead of Databricks-only EXISTS lookahead. Spark also enables backslash escapes in single-quoted strings (e.g. 'it\'s').

The tokenizer checks the L suffix before the numeric-prefix identifier rule; tests cover EXISTS, DIV, literals, DDL, and escapes across dialects.

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

… escapes in both

Databricks SQL is Spark SQL plus extensions, but each dialect had pieces
the other lacked:

- Databricks did not parse `a DIV b`, `CREATE TABLE ... USING fmt` or the
  `LONG` type. The DIV infix is now shared with Spark.
- Databricks read `1L` as an identifier starting with a digit, since its
  numeric-prefix rule ran before the `L` suffix. An `L` that ends the
  token is now a long suffix in every dialect with typed suffixes; `1La`
  is still an identifier.
- Spark parsed `exists(arr, x -> ...)` as an EXISTS subquery. It is a
  function, as under Databricks, unless SELECT or WITH follows.
- Spark did not read backslash escapes in string literals, so 'it\'s'
  was unterminated. Spark reads them; `\%` and `\_` stay as written.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/parser/mod.rs Resolved
….) a subquery

Only SELECT and WITH kept EXISTS ( a subquery test, so a pipe query
starting with TABLE was read as a call to the exists function.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/parser/mod.rs Resolved
…ft does

The long suffix ahead of the numeric-prefix rule was keyed on the typed
suffix flag and took `l` too. Gate it on a new hook,
supports_long_suffix_before_numeric_prefix, that Databricks and Hive opt
into, and take `L` only. `1La` is still an identifier; Spark, which has no
numeric prefix, keeps reading `1l` as before.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 90bda1a. Configure here.

Comment thread src/tokenizer.rs Resolved
moshap-firebolt and others added 2 commits October 29, 2026 15:17
…tream apache#2772 does

Replace the dialect_of! check with supports_exists_function, enabled for
Spark and Databricks, and check the function and the query forms on every
dialect with the hook, and the unchanged error on the rest.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…n, as upstream apache#2772 does

Choosing between the two by the keyword after the parenthesis missed a
parenthesized query, so `EXISTS ((SELECT 1) UNION (SELECT 2))` failed
and `EXISTS ((SELECT 1))` became a function call. Parse the predicate
first and fall back to the function call, and do the same after NOT,
which went straight to the predicate.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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