Repository navigation
fix(e6): transpile Postgres E'...' escape strings (Samsung Tableau) - #330
Closed
tkaunlaky-e6 wants to merge 1 commit into
Closed
tkaunlaky-e6 wants to merge 1 commit into
tkaunlaky-e6 wants to merge 1 commit into
Conversation
Samsung's Tableau connects through the Postgres connector, which binds a parameter value holding a control char, quote or backslash into the Databricks Custom SQL as a Postgres escape string (E'VZ_...\n'). The Databricks parse of the "Custom SQL Query" region failed, so 87 dashboard queries fell back to the planner and failed with a backtick lexical error. - Port upstream tobymao#6818 (Python and Rust tokenizer): BYTE_STRING_ESCAPES, so Postgres decodes E'...' bodies; dialects that don't set it keep their STRING_ESCAPES (inherited setting looked up through the MRO, as upstream). - Port upstream tobymao#7677: bytestring_sql prints a byte string as a quoted string literal for targets without byte-string syntax (e6) instead of bare text. - Re-escape decoded byte strings when writing Postgres (E'it''s' stays valid). - Databricks reads E'...' as a byte string under SAMSUNG_TABLEAU_DASHBOARD.
Benchmark for d15a39eClick to view benchmark
|
Author
|
Closing in favour of a minimal, flag-scoped fix: in the Databricks tokenizer, This branch is kept for reference. It also handles apostrophes written as |
Author
|
Superseded by #332: two independent flags under |
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.
Problem
87 Samsung dashboard queries (
samsung-dashboard, query history 2026-10-23) fail withPARSING_FAILED/Lexical error ... Encountered: ""`.Samsung's Tableau connects through the Postgres connector, whose dialect uses
format-string-literal='Extended'. A parameter value containing a control char, quote or backslash is therefore bound into the Databricks Custom SQL as a Postgres escape string:With
SAMSUNG_TABLEAU_DASHBOARD=truethe"Custom SQL Query"region is parsed as Databricks, which has noE'...'syntax (ParseError: Expecting )). The transpiler errors and the planner falls back to the raw query, failing on the first backtick.Postgres → e6 was also broken:
E'x\n'printed as barex\n(no quotes).Fix
BYTE_STRING_ESCAPEStokenizer setting (Python and Rust): PostgresE'...'bodies are decoded (\n,\t,\\,\','', ...). Dialects that don't set it keep theirSTRING_ESCAPES, so they are unchanged.escape_strre-escapes only for dialects whose plain strings use backslash escapes, so Postgres plain-string output is unchangedbytestring_sql: targets without byte-string syntax but with backslash escapes (e6) get a quoted string literal; others raise unsupported instead of emitting bare textbytestring_sql(Postgres target): re-escape the decoded value soE'it''s'stays validE'...'as a byte string only underSAMSUNG_TABLEAU_DASHBOARD(reuses the existing flag; off = Databricks unchanged)Flow with the flag on:
E'x\n'→ tokenizer (byte string, decoded) →ByteString(existing parser) → e6'x\n'.Testing
tests/dialects,test_tokens,test_transpile,test_generator,test_parser,test_expressions,test_optimizer: 795 passed, 11,295 subtests, with both the Python and Rust tokenizers (Rust rebuilt from this branch)./convert-querywithSAMSUNG_TABLEAU_DASHBOARD=true:BYTE_STRING_ESCAPESconcept for postgres/duckdb e-strings tobymao/sqlglot#6818/Fix: improve transpilation ofe'...'strings tobymao/sqlglot#7677 Postgres tests.test_e6.test_escape_stringscovers all 7 Tableau Extended escapes (Postgres → e6) and the flagged Databricks case (run in a subprocess, since the flag is read at import).Notes
sqlglotrs), so the image must rebuild it (the Dockerfile already does).BYTE_STRING_ESCAPESconcept for postgres/duckdb e-strings tobymao/sqlglot#6818: Postgres → Postgres printsE'a\\b'ase'a\b'. e6 output is correct ('a\\b').(DATE '...'),(TIMESTAMP '...'),TRUE/FALSE) already parse in Databricks. Across 791 Custom SQL regions,E'...'was the only failure.