Skip to content

fix(e6): subtract 1 from EXTRACT(DOW) on the multidialect path - #290

Merged
tkaunlaky-e6 merged 1 commit into
e6data:mainfrom
tkaunlaky-e6:fix/e6-multidialect-dow-offset
Aug 12, 2026
Merged

fix(e6): subtract 1 from EXTRACT(DOW) on the multidialect path#290
tkaunlaky-e6 merged 1 commit into
e6data:mainfrom
tkaunlaky-e6:fix/e6-multidialect-dow-offset

Conversation

@tkaunlaky-e6

Copy link
Copy Markdown

Problem

e6's EXTRACT(DOW) is 1–7 (Sun=1); Postgres' is 0–6 (Sun=0). BI-tool (Tableau) queries emit 1 + EXTRACT(DOW) expecting Postgres' 0–6, so on e6 it becomes 1 + (1..7) = 2–8 (off by one).

Fix

Rewrite EXTRACT(DOW ..)EXTRACT(DOW ..) - 1 so e6 reproduces the Postgres value in every context:

  • 1 + EXTRACT(DOW)1 + (EXTRACT(DOW) - 1) = 1–7
  • bare EXTRACT(DOW)0–6

subtract_one_from_dow lives in the e6 dialect (sqlglot/dialects/e6.py) and is applied via tree.transform(...) in the multidialect-only _region_to_e6 helper (converter_api.py). So it is gated on the MULTIDIALECT flag and covers both multidialect paths:

  • primary (pg → databricks → e6)
  • fallback (pg → e6)

Plain databricks → e6 (non-multidialect) is untouched. It's a plain AST rewrite, so no Databricks-generator change is needed — the primary path's intermediary is re-parsed by _region_to_e6 before e6 generation.

Verification (on the engine)

Schemaless (literal-date) queries transpiled through the converter and executed on e6:

Dayprimaryfallback
Sunday11
Monday22
Saturday77

Fallback genuinely exercised (numeric TRUNC forces the split; log confirms primary … failed → fallback). Non-multidialect control keeps 1 + EXTRACT(DOW) (no -1). e6 suite: 60 passed.

e6's EXTRACT(DOW) is 1-7 (Sun=1) while Postgres' is 0-6 (Sun=0). BI-tool
(Tableau) queries emit `1 + EXTRACT(DOW)` expecting Postgres' 0-6, so on e6
the value ends up 2-8. Rewrite `EXTRACT(DOW ..)` -> `EXTRACT(DOW ..) - 1` so
e6 reproduces the Postgres value: `1 + (EXTRACT(DOW) - 1)` = 1-7, and a bare
`EXTRACT(DOW)` = 0-6.
The transform (subtract_one_from_dow in the e6 dialect) is applied in the
multidialect-only _region_to_e6 helper, so it is gated on the MULTIDIALECT
flag and covers both the primary (pg->databricks->e6) and fallback (pg->e6)
paths; plain databricks->e6 is untouched. Verified on the engine: Sun=1,
Mon=2, Sat=7 on both paths.
@tkaunlaky-e6
tkaunlaky-e6 merged commit 73670be into e6data:mainAug 12, 2026
6 checks passed
Sign up for freeto 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.

3 participants

@tkaunlaky-e6@gauravdawar-e6@suyashkhare1403