Repository navigation
Spark, Databricks: parse DIV, USING, LONG, 1L, exists() and backslash escapes in both - #21
Open
moshap-firebolt wants to merge 5 commits into
Open
moshap-firebolt wants to merge 5 commits into
moshap-firebolt wants to merge 5 commits into
Conversation
… 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>
….) 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>
…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>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ 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.
…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>
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.

Databricks SQL is Spark SQL plus extensions, but each dialect parsed pieces the other did not.
a DIV b,CREATE TABLE ... USING fmtor theLONGtype. It now does; theDIVinfix is shared with Spark.1Las an identifier that starts with a digit, because its numeric-prefix rule ran before theLsuffix. A new dialect hook,supports_long_suffix_before_numeric_prefix, lets an uppercaseLthat ends the number win; Databricks and Hive opt in, MySQL does not, and1Lais still an identifier. This matches the upstream draft; lowercase1lstays an identifier under Databricks.exists(arr, x -> ...)as anEXISTSsubquery. It is now a function, as under Databricks, unless the parentheses hold a query, parenthesized or not;NOT exists(...)negates the function.'it\'s'was unterminated. Spark reads them;\%and\_stay as written, as they already do for Databricks.New tests in
sqlparser_spark.rsandsqlparser_databricks.rscover 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 sharedparse_div_infixwith Spark),CREATE TABLE ... USING,LONGasBIGINT, and the collectionexists(...)function hook.1Lis tokenized as a BIGINT literal instead of a digit-prefixed identifier whensupports_long_suffix_before_numeric_prefixis enabled (Databricks and Hive;1Lastays an identifier).Spark treats
exists(arr, lambda)as a function call whileEXISTS (SELECT …)remains a subquery, using a newsupports_exists_functiondialect flag andmaybe_parse_exists_exprinstead of Databricks-onlyEXISTSlookahead. Spark also enables backslash escapes in single-quoted strings (e.g.'it\'s').The tokenizer checks the
Lsuffix 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.