Skip to content

fix bucket() returning constant values unchanged - #7713

Merged
philrz merged 1 commit into
mainfrom
bucket-const-vector
Nov 23, 2026
Merged

philrz merged 1 commit into
mainfrom
bucket-const-vector

Conversation

@philrz

@philrz philrz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

bucket() returned its first argument unchanged, not rounded down to the bucket, whenever that argument was a constant vector. That happens for a literal or other constant expression, and for a column in a BSUP file when a frame holds the same value in every row. So, e.g., bucketing the timestamps in such a file by 1d returned the original timestamps. A SQL CAST(... AS DATE) of a constant, which uses bucket(), kept its time of day the same way. The constant case now truncates like the others.

Trying it out

On current tip of main, commit 85073ef:

$ printf '{t:2024-07-30T10:30:00Z}\n{t:2024-07-30T10:30:00Z}\n' | super -f bsup -o t.bsup -
$ super -version && super -c 'values bucket(t, 1d)' t.bsup && super -c 'values bucket(2024-07-30T10:30:00Z, 1h)'
Version: v0.4.0-114-g85073ef2f
2024-07-30T10:30:00Z
2024-07-30T10:30:00Z
2024-07-30T10:30:00Z

On this branch, commit d6e612b:

$ super -version && super -c 'values bucket(t, 1d)' t.bsup && super -c 'values bucket(2024-07-30T10:30:00Z, 1h)'
Version: v0.4.0-115-gd6e612b43
2024-07-30T00:00:00Z
2024-07-30T00:00:00Z
2024-07-30T10:00:00Z

Testing

  • Two new stanzas in bucket.yaml bucket a constant timestamp and a constant duration, and cast a constant timestamp to DATE in SQL. Both fail on main.
  • make test-unit, make test-system and the book's mdtests pass.

I found this while checking the function docs against main. It's a regression: the truncation was dropped from the constant case in #6723, and it became visible when #7072 moved constant expressions to the vector runtime and #7105 changed how files named on the command line are read. v0.3.0 gives the right answers for both commands above.

@philrz philrz self-assigned this Nov 23, 2026
@philrz
philrz requested a review from a team November 23, 2026 22:17
Comment thread runtime/expr/function/time.go Outdated
typ := b.resultType(tsVec)
ts := vector.IntValue(tsVec, 0)
ts := int64(nano.Ts(vector.IntValue(tsVec, 0)).Trunc(bin))
return vector.NewConstInt(typ, ts, tsVec.Len())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

		return vector.NewConst(b.constBinFlat(tsVec.Any, bin), tsVec.Len())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nwt. I went with your suggestion.

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.
@philrz
philrz force-pushed the bucket-const-vector branch from 47c2b69 to d6e612b Compare November 23, 2026 23:13
@philrz
philrz merged commit f40f389 into main Nov 23, 2026
2 checks passed
@philrz
philrz deleted the bucket-const-vector branch November 23, 2026 23:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants