Repository navigation
Conversation
time_slice rebuilt its slice spec on every row: SliceSpec::new uppercased the unit and start/end flag into new strings, and sub-day slices were floored with i128 division, a software routine. The binder always passes the slice as constants, so the spec is now built once per column when its arguments are scalars, the per-row path staying for everything else; the unit and flag are parsed without allocating, and a slice whose width fits i64 is floored in i64. 100,000 timestamps: 6.3 ms -> 1.3 ms. The expression test-support parser passed time_slice's unit and start/end in the opposite order to the binder; fixed for the new bench. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LxafFsFHwSmtUCVuLehsjK
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
| match time_slice_timestamp(*ts, spec, &tz) { | ||
| Ok(value) => output.push(value), | ||
| Err(error) => { | ||
| ctx.set_error(row, error); |
There was a problem hiding this comment.
Non-blocking testing suggestion: could we add a case where an out-of-range result occurs only in an unselected IF branch? The new tests cover nullable inputs and out-of-range errors separately, but this combination would help verify that the column fast path preserves error masking through ctx.validity.
For example:
SELECT if(
number = 0,
NULL,
time_slice(
to_timestamp(number::int64 - 1),
9223372036854775807,
'second'
)
)
FROM numbers(2);This should return NULL and the Unix epoch without raising an error for the masked-out row. The implementation looks correct to me; this would just lock in that behavior.
⏱ CI timing · Devrun 38924569819 · attempt 2 (wall time includes re-run gap) · 33.6 min (main p50 34.8 min, −1.2 min)
Minutes unless stated; durations exclude queue time unless stated; "max" = longest job in the group. Baseline = median of the last 10 successful runs (Dev: |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Head branch was pushed to by a user without write access

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/
Summary
time_slicerebuilt its slice spec from its arguments on every row:SliceSpec::newuppercased the unit and the start/end flag into two new strings to parse them, and sub-day slices were floored withi128::div_euclid, a software division. The binder always passes the slice length, unit and flag as constants (lower_time_slice_expr), so none of it depends on the row.eq_ignore_ascii_caseinstead of allocating.The expression test-support parser passed
time_slice's unit and start/end in the opposite order to the binder, sotime_slicecould not be evaluated through it. This fixes the order, which the new bench needs.Benchmark
cargo bench -p databend-common-functions --bench bench -- time_slice(new divan group): a 100,000-row timestamp column, rows 0.8s apart, UTC, single thread, median of two rounds. main, the first two changes alone, and the full PR built with the same profile and run back to back on an idle machine.time_slice(ts, 3600, 'second')time_slice(ts, 15, 'minute')time_slice(ts, 1, 'hour', 'end')In SQL, one thread and 100M rows,
sum(to_int64(time_slice(to_timestamp(number * 1000), 3600, 'SECOND')))took 6.9s on 1.2.952-nightly, against 1.1s for the same buckets as integer arithmetic and 0.56s with no bucketing.Tests
Unit Test
Logic Test
Benchmark Test
No Test - Explain why
02_0083_function_time_slice.test, results recorded from 1.2.952-nightly (the per-row path): sub-day slices before the epoch and with mixed-case units, slices wider than i64 microseconds, and out-of-range ends, as scalars and over columns (a timestamp column across 1970, a date column by month and week, a nullable column with a NULL row, a column with one row out of range).issue_20416.test(date and timestamp range bounds, includingtime_slice).Logic tests: the
query/functionsdirectory with--enable_sandboxover the http handler.Existing scalar golden tests unchanged (
cargo test -p databend-common-functions --test it scalars::).cargo fmt --check,cargo clippy -p databend-common-functions -p databend-functions-scalar-datetime -p databend-common-expression-test-support --tests --benches -- -D warnings.Type of change
AI assistance
🤖 Generated with Claude Code
https://claude.ai/code/session_01LxafFsFHwSmtUCVuLehsjK
This change is