Skip to content

fix(e6): Tableau E'...' strings in Postgres regions of the subquery tree - #340

Merged
tkaunlaky-e6 merged 2 commits into
mainfrom
fix/e6-postgres-escape-string
Nov 20, 2026
Merged

tkaunlaky-e6 merged 2 commits into
mainfrom
fix/e6-postgres-escape-string

Conversation

@tkaunlaky-e6

@tkaunlaky-e6 tkaunlaky-e6 commented Nov 20, 2026 •

Copy link
Copy Markdown

Problem

Samsung Tableau queries failed with PARSING_FAILED (20 Nov: 27 failures, 9 distinct queries):

Lexical error at line 17, column 2617.  Encountered: "\\" (92)

Tableau's Postgres connector sends a parameter as E'135030,...,135998\n'. Under SUBQUERY_TREE each region is Postgres unless it fails the Postgres parse. This Custom SQL has no backticks, so it parses as Postgres, E'...' becomes a Postgres byte string, and e6 printed it bare with the raw \n:

... 135998\n = 'All' ...

STRIP_E_STRING_PREFIX (#332/#339) only set up the Databricks tokenizer. That is why SAMSUNG_TABLEAU_DASHBOARD (Custom SQL always read as Databricks) and queries with backticks worked.

Fix

  1. postgres.py: the same tokenizer setting as the Databricks fix. With (SAMSUNG_TABLEAU_DASHBOARD, SUBQUERY_TREE or SUBQUERY_TREE_MULTIDIALECT) + STRIP_E_STRING_PREFIX, the Postgres tokenizer reads E'...' as a plain quote with \ as a string escape. sqlglot then decodes the escapes in both the Python and Rust tokenizers. STRIP_STRING_NEWLINES drops the newline, giving the same output as the Databricks path:
    ... 135998' = 'All' ...
    
  2. subquery_tree.py: the structural tokenize treats \ as a string escape. Before, a backslash-escaped quote (Databricks 'O\'Brien', Tableau E'O\'Brien') ended a string early and the request failed with a 500 under SUBQUERY_TREE. Each region still tokenizes in its own dialect.

Testing

  • make style, make test (Rust and Python tokenizers) and make test-multidialect all pass.
  • New tests: test_postgres_tableau_escape_strings (every Tableau escape, flag gating, newline stripping), the Postgres-region path under SUBQUERY_TREE and SUBQUERY_TREE_MULTIDIALECT, and backslash-escaped quotes.
  • Replay of 1,748 queries (Samsung, Conde Nast and OneTrust corpora, plus the 3 Nov and 20 Nov failure CSVs), main vs this branch:
Mode Changed Errors main / branch
SUBQUERY_TREE + both strip flags (Samsung prod) 9 Samsung (the 20 Nov failures) + 82 Conde Nast 18 / 18
SUBQUERY_TREE_MULTIDIALECT + both strip flags same 18 / 18
SAMSUNG_TABLEAU_DASHBOARD + both strip flags 82 Conde Nast 70 / 70
SUBQUERY_TREE only 0 18 / 18

The 82 Conde Nast changes are all backslashes in Databricks strings that the tree read as Postgres. They now follow Databricks semantics, e.g. regex '(\\?.*paid-revops)' keeps one backslash instead of being doubled. These only change under the Tableau flags, which Conde Nast does not set.

  • Local engine, main vs this branch (main fails on every Tableau case; this branch returns):
Case This branch
E'VZ_1,VZ_2\n' VZ_1,VZ_2, length 9
E'a\tb', E'a\rb' length 3
E'C:\\tmp' C:\tmp
E'O\'Brien', E'O''Brien' O'Brien
parameter in IN (...) / = 'All' matches
regex '(\\?.*paid-revops)' on a URL without ? 0 (main: 1, wrong)

The 20 Nov queries now get past parsing (they only fail locally on the missing dlt catalog).

Deployment

No config change. The Samsung config already sets SUBQUERY_TREE, STRIP_E_STRING_PREFIX and STRIP_STRING_NEWLINES.

Known limitation

With these flags, plain Postgres strings also use backslash escapes, so a hand-written 'C:\' would fail. Tableau sends backslashes only inside E'...', and none of the replayed queries contain such a string.

Under SUBQUERY_TREE a Custom SQL region without backticks parses as Postgres, so a Tableau
parameter E'...\n' became a Postgres byte string that e6 printed bare (engine: Lexical error
on "\"). With (SAMSUNG_TABLEAU_DASHBOARD, SUBQUERY_TREE or SUBQUERY_TREE_MULTIDIALECT) +
STRIP_E_STRING_PREFIX, emit it as a quoted string with its escapes decoded as Postgres does;
STRIP_STRING_NEWLINES then drops the newline, as on the Databricks path.

The tree's structural tokenize also treats a backslash as a string escape, so a
backslash-escaped quote ('O\'Brien', E'O\'Brien') no longer ends a string early and fails
the request.
…f a regex decoder

Replace the e6 bytestring_sql regex decoder with the same tokenizer setting the Databricks
fix uses: under (SAMSUNG_TABLEAU_DASHBOARD, SUBQUERY_TREE or SUBQUERY_TREE_MULTIDIALECT) +
STRIP_E_STRING_PREFIX the Postgres tokenizer reads E'...' as a plain quote with backslash
escapes, and sqlglot decodes them (Python and Rust tokenizers). The flag is read at import,
so the tests run in a subprocess.
@tkaunlaky-e6
tkaunlaky-e6 merged commit 47977ae into main Nov 20, 2026
6 checks passed
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