Repository navigation
Conversation
Negative strides had no defined semantics: a negative fixed stride rounds toward the origin, and a negative month stride is not monotonic. Like PostgreSQL, `date_bin` now returns an error for a stride that is not greater than zero, which also covers the zero stride. With only positive strides, `output_ordering` no longer special-cases negative month strides (added in apache#25815), and `compute_distance` / `compute_distance_wide` round down with `rem_euclid`. Closes apache#25856.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #26070 +/- ##
==========================================
- Coverage 82.69% 82.69% -0.01%
==========================================
Files 1147 1147
Lines 447348 447330 -18
Branches 447348 447330 -18
==========================================
- Hits 369936 369919 -17
+ Misses 54999 54998 -1
Partials 22413 22413 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Which issue does this PR close?
Rationale for this change
date_binaccepted negative strides, but they had no defined semantics:date_bin(INTERVAL '-1 month', ts, TIMESTAMP '2023-01-31')bins 2023-01-01 to 2023-02-28 and 2023-01-31 to itself.#25815 worked around the second one by not propagating ordering for negative month strides. As discussed in #25856,
date_binnow rejects strides that are not positive. This matches PostgreSQL for fixed strides (PostgreSQL does not support month strides at all), and DataFusion applies the same rule to month strides. A positive stride already bins timestamps before the origin, so a negative stride adds nothing, and an error is better than silently taking the absolute value of an accidental negative.What changes are included in this PR?
date_binreturnsDATE_BIN stride must be greater than zerofor a stride that is not positive. This covers negative months, negative days or nanoseconds, intervals whose parts add up to a negative stride, and TIME inputs. The zero-stride error is folded into this message.output_orderingno longer special-cases negative month strides: any constant stride preserves the order of the source.compute_distanceandcompute_distance_wideround down withrem_euclid. For a positive stride this is the same as the old truncate-then-step-back logic, and the two functions still match. Overflow neari64::MINstill returns an error, which becomes NULL.date_bindocs say the interval must be greater than zero, and the 56.0.0 upgrade guide describes the change.What is the testing strategy for this PR?
date_bin_errors.slt: error cases for negative month, year, minute, day and nanosecond strides, an interval whose parts add up to a negative stride, scalar and column inputs at second and nanosecond precision, and TIME inputs. The-1 nanosecondcase replaces the unit test for thei64::MIN % -1overflow from panic: date_bin compute_distance subtracts past i64::MIN #22215, which can no longer be reached.timestamps.slt: the negative-month ordering cases from fix: bin coarse date_bin timestamps in i128 and restore ordering #25815 are replaced by the error tests above. The positive-month control stays, and the zero-stride cases expect the new message.test_date_bincovers negativeIntervalDayTimestrides, which SQL interval literals cannot produce.output_ordering_requires_constant_stridereplacesoutput_ordering_requires_monotonic_stride.Are there any user-facing changes?
Yes, this is a breaking change: a negative
date_binstride is now an error. Previously it returned the same bins as the positive stride when the source was at or after the origin (for month strides, only when the source's day of month was not earlier than the origin's), and a bin later than the source otherwise. The zero-stride error message also changes. Both are documented in the 56.0.0 upgrade guide.