Repository navigation
fix(e6): unit-first TIMESTAMP_DIFF, Databricks % precedence, native DATE_ADD/TO_TIMESTAMP - #322
Merged
Merged
Conversation
…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).
suyashkhare1403
approved these changes
Oct 1, 2026
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.
Fixes
TIMESTAMP_DIFFargument order. e6 only acceptsTIMESTAMP_DIFF(unit, start, end); the unit-last form we emitted fails withCannot apply 'TIMESTAMP_DIFF' to arguments…. e6 now generates and parses unit-first, and DatabricksTIMEDIFFis built withbuild_date_deltalike the other date-diff functions.%precedence.%binds like*and/(added toFACTOR), soa - b % 7→a - MOD(b, 7).DATE_ADD(date, n). A BIGINT count is rejected, so a non-literal count is cast toINT(DATE_ADD(d, CAST(n AS INT))); literal counts are left as is. The java path is unchanged.to_timestamp(x, fmt). The format is kept as written (likeformat_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-lastTIMESTAMP_DIFF. Switching it to unit-first double-counts the day boundary, because e6TIMESTAMP_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 checkpasses: ruff, ruff-format, mypy, and the full suite with both the Python and Rust tokenizers (1012 tests each).tests/dialects/test_e6.py:%precedence (5 cases), e6 parsing its own unit-firstTIMESTAMP_DIFFfor all 7 units, and nativeDATE_ADDwith a column count vs literal counts. Reverting the%fix fails 3 checks; reverting the unit-first parse fails 35.TIMESTAMP_DIFFreturns the right value and the old form errors;20 - MOD(10, 7)= 17.DATE_ADDBIGINT rejection (the local engine accepts both forms) and nativeTO_TIMESTAMPfractional seconds.