Repository navigation
Commit 53e1210
authored
fix(datetime): error on out-of-range date_bin timestamp bins (apache#26607)
## Which issue does this PR close?
Closes apache#26605.
## Rationale for this change
`date_bin` returns NULL for unrepresentable timestamp bins. Return an
error instead, matching
[PostgreSQL](https://www.db-fiddle.com/f/h3qSHUSRprbzkX9GBkSuY2/0).
I'm not sure whether DataFusion has a specific policy on returning NULL
versus an error here, but the PostgreSQL precedent seems clear.
Returning NULL because we cannot compute a bin for a non-null timestamp
silently hides a computation failure rather than representing missing
input.
This prepares `date_bin` for avoiding aggregate repartitioning in
[apache#25345](apache#25345), similar to
the `date_trunc` optimization in
[apache#26449](apache#26449). It follows
the error behavior established for `date_trunc` in
[apache#25131](apache#25131).
## What changes are included in this PR?
Make scalar and array timestamp-binning failures return `DATE_BIN
timestamp out of range`. Preserve NULL inputs and successful
wider-arithmetic results.
## What is the testing strategy for this PR?
Unit tests and SQLLogicTests cover overflow errors, scalar/array
consistency, NULL preservation, and representable results across
timestamp precisions.
## Are there any user-facing changes?
Previously NULL-producing timestamp-binning failures now fail the query.
---
This PR was developed with AI assistance. All changes have been
reviewed, and I take full responsibility for this contribution.1 parent c92d781 commit 53e1210
3 files changed
Lines changed: 244 additions & 91 deletions
File tree
- datafusion
- functions/src/datetime
- sqllogictest/test_files
- docs/source/user-guide/sql
0 commit comments