Commit 7ed3b69
authored
Guard to_timestamp decimal overflow (#22307)
## Which issue does this PR close?
- Closes #22213
## Rationale for this change
`to_timestamp` converted Decimal128 inputs to nanoseconds with unchecked
`i128` multiplication followed by an `as i64` cast. Large Decimal128
values could overflow during nanosecond scaling, causing a panic in
debug builds or a wrapped timestamp value in release builds.
## What changes are included in this PR?
- Convert Decimal128-to-nanoseconds scaling to checked arithmetic.
- Return a DataFusion error when the scaled value cannot fit in
timestamp nanoseconds.
- Cover both scalar and array Decimal128 overflow paths.
- Add a sqllogictest regression for the reported query shape.
## Are these changes tested?
- `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
to_timestamp_decimal128`
-
`CARGO_TARGET_DIR=/home/sean/Projects/datafusion-runtime-set-nonascii/target
CARGO_BUILD_JOBS=2 cargo clippy -p datafusion-functions --lib -- -D
warnings`1 parent 626da1e commit 7ed3b69
2 files changed
Lines changed: 66 additions & 12 deletions
File tree
- datafusion
- functions/src/datetime
- sqllogictest/test_files/datetime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
336 | 336 | | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
337 | 345 | | |
338 | | - | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
339 | 351 | | |
340 | | - | |
| 352 | + | |
341 | 353 | | |
342 | | - | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
343 | 360 | | |
344 | 361 | | |
345 | 362 | | |
| |||
348 | 365 | | |
349 | 366 | | |
350 | 367 | | |
351 | | - | |
| 368 | + | |
352 | 369 | | |
353 | 370 | | |
354 | 371 | | |
| |||
362 | 379 | | |
363 | 380 | | |
364 | 381 | | |
365 | | - | |
366 | | - | |
| 382 | + | |
| 383 | + | |
367 | 384 | | |
368 | 385 | | |
369 | 386 | | |
| |||
947 | 964 | | |
948 | 965 | | |
949 | 966 | | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
950 | 998 | | |
951 | 999 | | |
952 | 1000 | | |
| |||
1830 | 1878 | | |
1831 | 1879 | | |
1832 | 1880 | | |
1833 | | - | |
| 1881 | + | |
1834 | 1882 | | |
1835 | 1883 | | |
1836 | 1884 | | |
1837 | | - | |
| 1885 | + | |
1838 | 1886 | | |
1839 | 1887 | | |
1840 | 1888 | | |
1841 | | - | |
| 1889 | + | |
1842 | 1890 | | |
1843 | 1891 | | |
1844 | 1892 | | |
1845 | | - | |
| 1893 | + | |
1846 | 1894 | | |
1847 | 1895 | | |
1848 | 1896 | | |
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
595 | 595 | | |
596 | 596 | | |
597 | 597 | | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
598 | 604 | | |
599 | 605 | | |
600 | 606 | | |
| |||
0 commit comments