Repository navigation
feat(core-spec): DATEDIFF counts the boundaries of part crossed in OSSIE_SQL_2026 - #816
Open
MrBlack1995 wants to merge 3 commits into
Open
MrBlack1995 wants to merge 3 commits into
MrBlack1995 wants to merge 3 commits into
Conversation
MrBlack1995
force-pushed
the
feat/core-spec-datediff-boundaries
branch
from
November 24, 2026 05:54
94287be to
e13b645
Compare
MrBlack1995
force-pushed
the
feat/core-spec-datediff-boundaries
branch
from
November 24, 2026 06:01
e13b645 to
d2588fb
Compare
jbonofre
self-requested a review
November 24, 2026 12:29
…SIE_SQL_2026 expression_language.md said only "Difference between dates", and engines read it two ways: some engines (Snowflake) count boundaries crossed, Databricks counts whole units elapsed, so DATEDIFF(month, DATE '2015-12-31', DATE '2016-01-01') was 1 or 0. Define the boundary reading, give examples, and the equivalent an elapsed-unit engine evaluates (the same function over DATE_TRUNC-ed values, or the YEAR/MONTH arithmetic). Closes apache#743. Co-authored-by: Isaac <no-reply@databricks.com>
MrBlack1995
force-pushed
the
feat/core-spec-datediff-boundaries
branch
from
November 24, 2026 12:49
d2588fb to
e3cc89b
Compare
Co-authored-by: Isaac <no-reply@databricks.com>
…ete part The equivalent for engines that count elapsed units was written with a generic `part`, which hides that DATE_TRUNC takes the part as a string literal while DATEDIFF takes it unquoted. Write it out for month and say how each function takes the part (review on dev@). Co-authored-by: Isaac <no-reply@databricks.com>
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.
Summary
OSSIE_SQL_2026listsDATEDIFF(part, start_date, end_date)as REQUIRED with the description "Difference between dates", and engines read that in two incompatible ways: some count the boundaries ofpartcrossed (Snowflake), others count whole units elapsed (Databricks). So the same portable metric returns different numbers depending on where it runs (#743).DATEDIFF(month, DATE '2015-12-31', DATE '2016-01-01')1on Snowflake,0on Databricks1DATEDIFF(day, TIMESTAMP_NTZ '2026-01-01 23:59:59', TIMESTAMP_NTZ '2026-01-02 00:00:01')1on boundary engines,0on engines that count 86,400-second days1DATEDIFF(day, ...)overDATEvaluesexpression_language.mdstates the rule:DATEDIFFcompares the two values truncated topart, so it is the number of wholepartunits betweenDATE_TRUNC(part, start_date)andDATE_TRUNC(part, end_date), negative when the end is before the start, with weeks starting on Monday asDATE_TRUNC('week', ...)already says.DATEDIFFcounts whole units elapsed evaluates an equivalent expression, and the section gives two: the same function over the truncated values (both arguments sit on a boundary, so elapsed and crossed units agree), or theYEAR/MONTHarithmetic formonthandyear.partis one of the parts ofDATE_TRUNC(year,quarter,month,week,day,hour,minute,second); the spec gave no list forDATEDIFFbefore. An expression that needs elapsed time takes it from a smaller part, for exampleDATEDIFF(second, start_ts, end_ts) / 86400.0(asked for on Spec gap: DATEDIFF does not say whether it counts boundaries crossed or whole units elapsed #743 by GASP, who counted 60 uses in their model: 48dayoverDATEvalues, unchanged, and 12seconddurations).DATEDIFFrow in Date Arithmetic links to the section.spec.mdchangelog (0.3.0.dev0) anddocs/spec_changes.md: recorded as Breaking, like theROUNDentry: earlier versions did not specify it, so a document written for an engine with the other reading can change meaning.Why boundaries crossed: it is Snowflake's reading, and on #743 djwaldo showed that ThoughtSpot already implements it on both Snowflake and Databricks, emitting
FLOOR(MONTHS_BETWEEN(...))on Databricks rather than passing the part through. A semantic layer that has to hold one meaning across warehouses already ends up here, and the truncation equivalent makes it cheap for elapsed-unit engines.I checked every example and both equivalents against a reference implementation of the rule: for all eight parts, on 20,000 random pairs of timestamps with fractions of a second, the truncation form and the month and year arithmetic agree with it, and the two readings never differ by more than 1.
Impact on existing implementations
datediff), and converters targeting them: emit the equivalent the section gives.DATEDIFF(day, ...)overDATEvalues, which the M6 portability fixture uses, is the same under both readings.DATE_TRUNC('week', ...), a Monday. A source whose weeks start on another day shifts accordingly.DATE_TRUNC, which the spec does not define for them either.Validation
validation/tests: 1103 passed, 1 skipped.compliance: 58 passed.pre-commitpasses on the three changed files.Related Issues
dev@ discussion:
[DISCUSS]thread, lazy consensus until Tuesday 1 December 2026 (UTC).Closes #743. apache/ossie-converters#175 refuses
DATEDIFFtoday for exactly this reason and can translate it once this lands.Checklist
Specification
core-spec/and follow the existing structure[DISCUSS]thread ondev@with a stated end date, and reach lazy consensus (or pass a[VOTE]) before merge (thread open until 2026-12-01)docs/spec_changes.mdrecords rationale, compatibility and migration impact, or the PR explains why no entry is neededConverters
Validation
validation/are updated if the spec changed (no rule changes: the validator does not evaluateDATEDIFF)Tests
pytest/ CI green)Compliance