Skip to content

fix(e6): unit-first TIMESTAMP_DIFF, Databricks % precedence, native DATE_ADD/TO_TIMESTAMP - #322

Merged
tkaunlaky-e6 merged 1 commit into
mainfrom
fix/e6-mod-precedence-date-format
Oct 1, 2026
Merged

tkaunlaky-e6 merged 1 commit into
mainfrom
fix/e6-mod-precedence-date-format

Conversation

@tkaunlaky-e6

Copy link
Copy Markdown

Fixes

  1. TIMESTAMP_DIFF argument order. e6 only accepts TIMESTAMP_DIFF(unit, start, end); the unit-last form we emitted fails with Cannot apply 'TIMESTAMP_DIFF' to arguments…. e6 now generates and parses unit-first, and Databricks TIMEDIFF is built with build_date_delta like the other date-diff functions.
  2. Databricks % precedence. % binds like * and / (added to FACTOR), so a - b % 7 → a - MOD(b, 7).
  3. Native executor, 2-arg DATE_ADD(date, n). A BIGINT count is rejected, so a non-literal count is cast to INT (DATE_ADD(d, CAST(n AS INT))); literal counts are left as is. The java path is unchanged.
  4. Native executor, Databricks to_timestamp(x, fmt). The format is kept as written (like format_date_sql) with inner quotes doubled, e.g. 'yyyy-MM-dd''T''HH:mm:ss.SSSSSS'. With no format it falls back to the default path. The java path is unchanged.

Not changed

The Postgres AGE() rewrite keeps its unit-last TIMESTAMP_DIFF. Switching it to unit-first double-counts the day boundary, because e6 TIMESTAMP_DIFF('MONTH') already counts complete months: AGE('2026-06-05', '2020-05-10') would give 5 years 11 months instead of 6 years 0 months. That needs its own fix.

Testing

  • make check passes: ruff, ruff-format, mypy, and the full suite with both the Python and Rust tokenizers (1012 tests each).
  • New tests in tests/dialects/test_e6.py: % precedence (5 cases), e6 parsing its own unit-first TIMESTAMP_DIFF for all 7 units, and native DATE_ADD with a column count vs literal counts. Reverting the % fix fails 3 checks; reverting the unit-first parse fails 35.
  • On a local e6 engine: unit-first TIMESTAMP_DIFF returns the right value and the old form errors; 20 - MOD(10, 7) = 17.
  • Not verified locally: the native-executor DATE_ADD BIGINT rejection (the local engine accepts both forms) and native TO_TIMESTAMP fractional seconds.

…ATE_ADD/TO_TIMESTAMP

- TIMESTAMP_DIFF: e6 only accepts TIMESTAMP_DIFF(unit, start, end); the unit-last form
  fails with "Cannot apply 'TIMESTAMP_DIFF'". Generate and parse unit-first, and build
  Databricks TIMEDIFF with build_date_delta like the other date-diff functions.
- Databricks binds % like * and / (FACTOR), so a - b % 7 is a - MOD(b, 7).
- Native executor: 2-arg DATE_ADD(date, n) rejects a BIGINT count, so cast a non-literal
  count to INT; literal counts are left as is.
- Native executor: Databricks to_timestamp(x, fmt) keeps the format as written (like
  format_date_sql) with inner quotes doubled; with no format it falls back to the default
  path.

The Postgres AGE() rewrite keeps its unit-last TIMESTAMP_DIFF for now: switching it to
unit-first double-counts the day boundary, since e6 TIMESTAMP_DIFF('MONTH') already counts
complete months (AGE('2026-06-05','2020-05-10') would give 5y 11m instead of 6y 0m).
@tkaunlaky-e6
tkaunlaky-e6 merged commit 03806cd into main Oct 1, 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