Skip to content

feat: add tip on the time_bucket SQL function - #10

Open
fusionet24 wants to merge 2 commits into
mainfrom
claude/databricks-sept-release-explainer-eo72uv
Open

fusionet24 wants to merge 2 commits into
mainfrom
claude/databricks-sept-release-explainer-eo72uv

Conversation

@fusionet24

Copy link
Copy Markdown
Owner

What

Adds a short explainer on time_bucket, released 8 September 2026, and a /s/time-bucket short 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 gap date_trunc leaves: 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:

  1. 15-minute latency windows. Six API requests grouped by time_bucket, showing the half-open [start, start + bucketSize) boundary: the event at exactly 09:15:00 opens the second window rather than closing the first, so nothing is double counted.
  2. The same data re-anchored with origin set to 00:05, moving the grid to :05/:20/:35/:50. The two events either side of 09:15:00 that the default grid split now share a bucket.
  3. A fiscal quarter starting 1 February, next to 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: bucketSize and origin are folded at plan time so neither can come from a column, the session time zone moves daily buckets on TIMESTAMP but not TIMESTAMP_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 why date_trunc remains the right call for weeks.

Notes for review

  • Every output block was computed by hand against the documented bucket arithmetic rather than copied from the reference page's examples.
  • The page has no executable chunks, so no _freeze artifact is needed.
  • Follows the structure and voice of the existing Unity Catalog/Transactions.qmd tip.

🤖 Generated with Claude Code

https://claude.ai/code/session_018nGDkf2tGUxHXMpRbr9GvM


Generated by Claude Code

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
Copilot AI lite review requested due to automatic review settings September 11, 2026 14:11

Copy link
Copy Markdown
Owner Author

Heads up on validation: Validate Site and Deploy does not run on open PRs. Its triggers are push to main/feature/*, pull_request on types: [closed], the Sunday schedule, and manual dispatch — so a branch like this one gets no render check until after merge.

I ran it locally instead, with Quarto 1.8.24 (version: release, same as the workflow):

  • quarto render on the new page succeeds, and the page lands in the home listing with its title, description, and the Data Engineering / sql / time-series categories.
  • Three SQL blocks and the comparison table render as expected; the Watch for links resolve.
  • The only warnings are the pre-existing "unable to read listing preview image" ones that every tip in the repo emits, since none set image:.
  • No executable chunks, so nothing is added under _freeze.

The diff is the two intended files only — I reverted the site/.quarto/ cache and site/.gitignore churn that rendering produces locally.


Generated by Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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-bucket short-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.

Comment thread site/tips/Data Engineering/TimeBucket.qmd Outdated
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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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_NTZ has no time zone, so saying it buckets in UTC is misleading: its value and bucket boundaries are independent of spark.sql.session.timeZone, rather than being converted to UTC. Please describe it as session-time-zone independent and reserve the session-time-zone behavior for TIMESTAMP.
**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, while date_trunc('week', ...) uses Monday. Because the table recommends time_bucket for 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 events references make these snippets fail when pasted: no events table or CTE is defined, despite the page promising no setup and complete runnable statements. Please add a small VALUES source (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

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.

2 participants