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}