feat: add tip on the time_bucket SQL function - #10
fusionet24 wants to merge 2 commits into
Conversation
Covers the September 2026 release of time_bucket, which returns the start of the fixed-width window a timestamp falls into, aligned to an origin. The explainer is built around three runnable statements that need no tables: 15-minute latency windows, the same data re-anchored to a grid that starts at :05, and a fiscal quarter that calendar date_trunc cannot express. Closes with guidance on choosing between time_bucket and date_trunc, plus the constant-folding, time zone, and month-clamping behaviour to plan for. Also adds the /s/time-bucket short link. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018nGDkf2tGUxHXMpRbr9GvM
|
Heads up on validation: I ran it locally instead, with Quarto 1.8.24 (
The diff is the two intended files only — I reverted the Generated by Claude Code |
There was a problem hiding this comment.
🟡 Changes recommended
Clarify the bucketSize foldability requirement in the tutorial.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a Databricks SQL time_bucket tutorial with runnable examples and a /s/time-bucket redirect.
Changes:
- Documents fixed-width, origin-aligned bucketing and comparison with
date_trunc. - Adds the
/s/time-bucketshort-link redirect.
File summaries
| File | Summary | Review note |
|---|---|---|
site/tips/Data Engineering/TimeBucket.qmd |
New time_bucket tutorial and examples |
Nit (2 votes): Clarify that CASE must select between separate calls with literal intervals. |
site/staticwebapp.config.json |
Adds the short-link redirect | No review comments. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The foldability note told readers to "branch with CASE over constant widths", which reads as putting the CASE inside the interval argument. That expression references a column, so it is non-foldable and raises the very NON_FOLDABLE_INPUT error the note warns about. Replace it with the working pattern: branch around the time_bucket calls so each one takes a literal interval. Shows both the failing and the working form side by side. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018nGDkf2tGUxHXMpRbr9GvM
There was a problem hiding this comment.
🔵 Needs a closer look
The unresolved moderate issue and two nits should be addressed before approval.
Review details
Suppressed comments (3)
site/tips/Data Engineering/TimeBucket.qmd:186
TIMESTAMP_NTZhas no time zone, so saying it buckets in UTC is misleading: its value and bucket boundaries are independent ofspark.sql.session.timeZone, rather than being converted to UTC. Please describe it as session-time-zone independent and reserve the session-time-zone behavior forTIMESTAMP.
**Time zones differ by type.** `TIMESTAMP_NTZ` buckets in UTC. For `TIMESTAMP`, year-month
site/tips/Data Engineering/TimeBucket.qmd:156
- The promised weekly edge case is missing here:
time_bucket(INTERVAL '7' DAY, ...)uses epoch-anchored Thursday boundaries, whiledate_trunc('week', ...)uses Monday. Because the table recommendstime_bucketfor arbitrary widths, including day widths, omitting this caveat can silently shift weekly reports; please add it before recommending the calendar function.
`time_bucket` with a default origin and a one-unit interval matches `date_trunc` for
seconds, minutes, hours, days, and months. Prefer `date_trunc` there. It reads better, and
it handles weeks, which start on a Monday rather than at the epoch.
site/tips/Data Engineering/TimeBucket.qmd:171
- The
FROM eventsreferences make these snippets fail when pasted: noeventstable or CTE is defined, despite the page promising no setup and complete runnable statements. Please add a smallVALUESsource (to both forms) or label these as schematic examples so the working form can actually be run.
FROM events;
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
What
Adds a short explainer on
time_bucket, released 8 September 2026, and a/s/time-bucketshort link.time_bucket(bucketSize, ts [, origin])returns the start of the fixed-width window a timestamp falls into, aligned to an origin you choose. It fills the gapdate_truncleaves: any window that isn't a calendar unit, and any grid that doesn't start at midnight.Why this one
Picked from the September 2026 platform release notes over the other candidates because it is the only entry that is both broadly useful and fully demonstrable in a copy-paste statement — no table, no preview enrolment, no DDL, no cleanup. Auto CDF and ABAC DENY policies need provisioned state before an example proves anything; the Lakeflow connectors and model additions need external credentials.
Contents
site/tips/Data Engineering/TimeBucket.qmd— three runnable statements, each with its verified output:time_bucket, showing the half-open[start, start + bucketSize)boundary: the event at exactly09:15:00opens the second window rather than closing the first, so nothing is double counted.originset to00:05, moving the grid to:05/:20/:35/:50. The two events either side of09:15:00that the default grid split now share a bucket.date_trunc('quarter', …)on the same timestamp. Two different quarters from one value — the point being that reporting against the wrong one moves revenue between periods.Closes with a table for choosing between the two functions, and the behaviour worth planning for:
bucketSizeandoriginare folded at plan time so neither can come from a column, the session time zone moves daily buckets onTIMESTAMPbut notTIMESTAMP_NTZ, an origin on the 31st clamps in short months, and a default 7-day grid anchors on Thursdays because the epoch was one — which is whydate_truncremains the right call for weeks.Notes for review
_freezeartifact is needed.Unity Catalog/Transactions.qmdtip.🤖 Generated with Claude Code
https://claude.ai/code/session_018nGDkf2tGUxHXMpRbr9GvM
Generated by Claude Code