From d6e612b43c3aff1a9b8895fbc4107e69ae1502e4 Mon Sep 17 00:00:00 2001 From: Phil Rzewski Date: Mon, 23 Nov 2026 14:04:36 -0800 Subject: [PATCH] fix bucket() returning constant values unchanged bucket() returned a constant vector's value without truncating it, so a literal, a BSUP column whose frame has the same value in every row, or a SQL cast of a constant to DATE wasn't truncated. Truncate it like the other cases. --- runtime/expr/function/time.go | 4 +--- runtime/ztests/expr/function/bucket.yaml | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/runtime/expr/function/time.go b/runtime/expr/function/time.go index 2c79eb3e9..7f2362465 100644 --- a/runtime/expr/function/time.go +++ b/runtime/expr/function/time.go @@ -58,9 +58,7 @@ func (b *Bucket) constBin(tsVec vector.Any, bin nano.Duration) vector.Any { } switch tsVec := tsVec.(type) { case *vector.Const: - typ := b.resultType(tsVec) - ts := vector.IntValue(tsVec, 0) - return vector.NewConstInt(typ, ts, tsVec.Len()) + return vector.NewConst(b.constBinFlat(tsVec.Any, bin), tsVec.Len()) case *vector.View: return vector.NewView(b.constBinFlat(tsVec.Any, bin), tsVec.Index) case *vector.Dict: diff --git a/runtime/ztests/expr/function/bucket.yaml b/runtime/ztests/expr/function/bucket.yaml index 7b8fab339..e1772a2fa 100644 --- a/runtime/ztests/expr/function/bucket.yaml +++ b/runtime/ztests/expr/function/bucket.yaml @@ -23,3 +23,21 @@ output: | null error({message:"bucket: first argument is not a timestamp or duration",on:"foo"}) error({message:"bucket: second argument is not a duration",on:"bar"}) + +--- + +# Constant arguments take the constant-vector path. +spq: values bucket(2020-05-26T15:27:47Z, 1h), bucket(3s, 2s), bucket(2020-05-26T15:27:47Z, 0s) + +output: | + 2020-05-26T15:00:00Z + 2s + 2020-05-26T15:27:47Z + +--- + +# A SQL cast of a constant to DATE truncates with bucket. +spq: SELECT CAST(TIMESTAMP '2020-05-26 15:27:47' AS DATE) AS d + +output: | + {d:2020-05-26T00:00:00Z}