Commit 528ca74
authored
fix: avoid panic in date_bin compute_distance near i64::MIN (#22408)
## Which issue does this PR close?
- Closes #22215.
## Rationale for this change
`date_bin` panics with `attempt to subtract with overflow` when the
source timestamp sits near `i64::MIN` because `compute_distance` does
`time_diff - (time_diff % stride)` and then `time_delta - stride` on raw
`i64`. The scalar pipeline already maps `Err` from `bin_fn` into `NULL`,
so the fix is to surface the overflow as a normal error.
## What changes are included in this PR?
- Convert `compute_distance` to return `Result<i64>` and use
`checked_sub`.
- Propagate the result through `date_bin_nanos_interval` and
`date_bin_months_interval`, plus replace the trailing `origin +
time_delta` with `checked_add`.
## Are these changes tested?
Yes. Added `test_date_bin_compute_distance_i64_min` which previously
panicked and now returns `NULL`. Ran `cargo test -p datafusion-functions
--lib -- datetime::date_bin`, `cargo fmt --check`, and `cargo clippy -p
datafusion-functions --lib --tests --no-deps`.
## Are there any user-facing changes?
Queries that previously panicked on extreme timestamps now return `NULL`
(consistent with the existing out-of-range behavior covered by
`test_date_bin_out_of_range`).1 parent 0469e5e commit 528ca74
2 files changed
Lines changed: 84 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
328 | 328 | | |
329 | 329 | | |
330 | 330 | | |
331 | | - | |
| 331 | + | |
332 | 332 | | |
333 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
334 | 339 | | |
335 | 340 | | |
336 | 341 | | |
337 | | - | |
338 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
339 | 353 | | |
340 | 354 | | |
341 | 355 | | |
342 | | - | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
343 | 362 | | |
344 | | - | |
| 363 | + | |
345 | 364 | | |
346 | 365 | | |
347 | 366 | | |
| |||
357 | 376 | | |
358 | 377 | | |
359 | 378 | | |
360 | | - | |
| 379 | + | |
361 | 380 | | |
362 | 381 | | |
363 | 382 | | |
| |||
1341 | 1360 | | |
1342 | 1361 | | |
1343 | 1362 | | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
1344 | 1411 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
70 | 80 | | |
0 commit comments