You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "niebayes (via GitHub)" <gi...@apache.org> on 2026/09/15 07:00:03 UTC
[I] Optimize date_bin for the common nanosecond stride cases [datafusion]
niebayes opened a new issue, #25314:
URL: https://github.com/apache/datafusion/issues/25314
## Problem
`date_bin(interval, ts)` is the standard time-series bucketing function
(`GROUP BY date_bin(INTERVAL '1 hour', ts)`). Time-based interval strides
(`INTERVAL '1 hour'`, `'1 day'`, `'1 minute'`, ...) all carry `months == 0`
and take the nanosecond-stride path, which is the overwhelmingly common case
for time-series workloads.
That path processes each value through a per-row hot loop with:
- an indirect call through a function pointer (`BinFunction`),
- a chain of checked arithmetic (`checked_mul`/`checked_sub`/`checked_rem`/
`checked_add`) with error closures,
- a `Result -> Option` conversion per value.
None of this is needed: for a positive nanosecond stride the whole computation
is equivalent to `bin = origin + floor((value*scale - origin)/stride)*stride`,
i.e. a few plain integer ops.
## Proposal
Add a vectorized fast path for the positive nanosecond-stride case: a single
infallible pass of plain integer arithmetic, guarded by a whole-array
min/max safety check (with a margin covering `origin`/`stride`), falling back
to the existing per-value path for pathological inputs / month strides /
TIME types.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org