Commit 11a79a6
authored
Guard date_trunc lower-bound truncation (#22303)
## Which issue does this PR close?
- Closes #22214.
## Rationale for this change
Truncating a near-lower-bound nanosecond timestamp to a coarser calendar
unit can produce a timestamp outside Arrow's nanosecond range.
`date_trunc_coarse` already used fallible timestamp conversion, but it
unwrapped the final conversion back to nanoseconds and could panic.
## What changes are included in this PR?
- Convert the final out-of-range truncation case into a DataFusion
execution error.
- Add a small string helper for user-facing granularity names in the
error.
- Add a unit regression and a sqllogictest regression for lower-bound
nanosecond truncation.
## Are these changes tested?
Yes:
- `cargo fmt --check`
- `git diff --check`
-
`CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target
CARGO_BUILD_JOBS=2 cargo test -p datafusion-functions --lib
date_trunc_out_of_range_lower_bound_returns_error`
-
`CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target
CARGO_BUILD_JOBS=2 cargo test -p datafusion-sqllogictest --test
sqllogictests -- date_trunc_boundaries.slt`
-
`CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target
CARGO_BUILD_JOBS=2 cargo clippy -p datafusion-functions --lib -- -D
warnings`
## Are there any user-facing changes?
Instead of panicking, out-of-range `date_trunc` results now return an
error.1 parent 070d013 commit 11a79a6
2 files changed
Lines changed: 45 additions & 2 deletions
File tree
- datafusion
- functions/src/datetime
- sqllogictest/test_files/datetime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
138 | 157 | | |
139 | 158 | | |
140 | 159 | | |
| |||
629 | 648 | | |
630 | 649 | | |
631 | 650 | | |
| 651 | + | |
632 | 652 | | |
633 | 653 | | |
634 | 654 | | |
| |||
645 | 665 | | |
646 | 666 | | |
647 | 667 | | |
648 | | - | |
649 | | - | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
650 | 673 | | |
651 | 674 | | |
652 | 675 | | |
| |||
879 | 902 | | |
880 | 903 | | |
881 | 904 | | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
882 | 918 | | |
883 | 919 | | |
884 | 920 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5345 | 5345 | | |
5346 | 5346 | | |
5347 | 5347 | | |
| 5348 | + | |
| 5349 | + | |
| 5350 | + | |
| 5351 | + | |
| 5352 | + | |
| 5353 | + | |
| 5354 | + | |
5348 | 5355 | | |
5349 | 5356 | | |
5350 | 5357 | | |
| |||
0 commit comments