Skip to content

feat(parser): add BIGQUERY, DATABRICKS and SNOWFLAKE dialect presets - #2515

Open
fudianchn wants to merge 6 commits into
JSQLParser:masterfrom
fudianchn:warehouse-presets
Open

feat(parser): add BIGQUERY, DATABRICKS and SNOWFLAKE dialect presets#2515
fudianchn wants to merge 6 commits into
JSQLParser:masterfrom
fudianchn:warehouse-presets

Conversation

@fudianchn

@fudianchn fudianchn commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.

What

Three warehouse presets, following up on the four warehouses named in #2512:

CCJSqlParserUtil.parse("SELECT `col` FROM t WHERE a = 'x\\'yz' AND b = 42#24",
        p -> p.withDialect(Dialect.BIGQUERY))
// -> SELECT `col` FROM t WHERE a = 'x\'yz' AND b = 42
preset " # \ adjacent literals
BIGQUERY string literal line comment escape sequences WHITESPACE
DATABRICKS string literal the #2507 operator escape sequences WHITESPACE
SNOWFLAKE quoted identifier the operator escape sequences OFF (alias)

Why

Every row is taken from the vendor docs, and Redshift, the fourth warehouse surveyed, matches the defaults on every switch and gains no entry.

  • GoogleSQL, lexical structure: "Both string and bytes literals must be quoted, either with single (') or double (\") quotation marks", # single-line comments, "Backslashes (\) introduce escape sequences", literal chunking where "the literal value is the concatenation of all these parts" across any whitespace ("Quoted identifiers don't concatenate"); identifiers are backticked.
  • Spark, literals: the syntax [ r ] { 'char [ ... ]' | "char [ ... ]" } [ ... ], the escape table, "Chains of string literals are coalesced into a single string literal". The Databricks KB adds that double quoted identifiers need the non-default doubleQuotedIdentifiers conf, so the default reading is the string one, the same preset decision as MySQL and its ANSI_QUOTES mode in feat(parser): support double quoted string literals behind allowDoubleQuotedStrings #2513. # is not a Spark comment.
  • Snowflake, string and binary data types: "A backslash escape sequence is a sequence of characters that begins with a backslash (\)", the double quote "is used (as needed) for delimiting object identifiers"; no adjacent-literal concatenation documented.
  • Redshift: delimited identifiers for ", PG-style -- comments, and no AWS docs sentence found for backslash escapes or adjacent literals (community evidence points to escapes, unverified), so every row stays with the default and no empty preset entry is added.

Sources: GoogleSQL lexical structure, Spark literals, Databricks KB, double quoted identifiers, Snowflake string and binary data types, Redshift names.

How

Enum entries only; withDialect is data driven since #2511 and unchanged. Stacked on #2514 for the WHITESPACE mode, the diff shrinks automatically once it merges.

Testing

CCJSqlParserUtilTest: testDialectPresetsWarehouses (BigQuery backticks + escape + 42#24 swallowed as comment, Databricks double quoted string + escape + # stays the operator, Snowflake escape + # stays the operator), testDoubleQuotedStringsPreset extended (string reading for BigQuery and Databricks, identifier guard for Snowflake), testAdjacentStringLiteralsWhitespace extended (the warehouse presets carry the mode, Snowflake stays the alias reading). All verified failing with a wrong row added or a right row removed (Databricks # on, Snowflake " on, BigQuery # off, WHITESPACE turned into NEWLINE); full suite green.

…ingLiterals

Three readings of two neighboring string literals: alias (MySQL, SQL
Server, the current behavior), concatenated across a newline (the SQL
standard and PostgreSQL), concatenated across any whitespace (GoogleSQL,
Spark/Databricks). The mode lives in a String valued Feature like
Feature.dialect, the merge is one guarded loop in PrimaryExpression
using the token line numbers for the newline rule, producing a single
merged StringValue. ANSI_SQL and POSTGRESQL presets carry NEWLINE.
Implements item 3 of JSQLParser#2512.
The FeatureConfiguration seeds every configurable Feature with its
declared default, so the mode is never null today; the guard keeps the
predicate locally correct regardless.
@manticore-projects

Copy link
Copy Markdown
Contributor

Nice work, please consider my one comment on the Feature and then I would merge prompt. Thank you much for your contribution!

@fudianchn

Copy link
Copy Markdown
Contributor Author

@manticore-projects The comment on the Feature has not arrived on my side: the review still shows as pending (unsubmitted). Could you submit it? I will address it right away.

Comment thread src/main/java/net/sf/jsqlparser/parser/AbstractJSqlParser.java
@manticore-projects

Copy link
Copy Markdown
Contributor

Sorry for asking, are those 2 PRs not additive or redundant?

…, true = NEWLINE

stores the AdjacentStringLiterals enum constant itself as the feature value
@fudianchn

Copy link
Copy Markdown
Contributor Author

@manticore-projects Additive by design: #2514 carries the feature, this PR only the presets on top (the first four commits here are #2514's), and the description notes the same. Once #2514 merges, this diff shrinks to the presets commit. The boolean overload landed in #2514, with this PR rebased on it.

Three warehouse presets for the lexer feature switches, each row taken
from the vendor docs: BIGQUERY carries double quoted strings, # line
comments, backslash escapes and the any-whitespace adjacent literal
rule (GoogleSQL lexical structure; identifiers are backticked);
DATABRICKS the same minus # comments (Spark literals; the double
quoted identifiers switch is a non-default conf); SNOWFLAKE backslash
escape sequences only, double quotes stay quoted identifiers (string
and binary data types). Redshift was surveyed too and stays with the
defaults on every switch, so it gains no preset entry. Follows up on
the four warehouses named in JSQLParser#2512.
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.

2 participants