Add timezone_aware option for continuous aggregates#132
Open
jonatas wants to merge 2 commits intotimescale:masterfrom
Open
Add timezone_aware option for continuous aggregates#132jonatas wants to merge 2 commits intotimescale:masterfrom
jonatas wants to merge 2 commits intotimescale:masterfrom
Conversation
Introduces `timezone_aware: true` and `timeframe_intervals:` options on
`continuous_aggregates`. When enabled, every generated cagg class gains the
`in_timezone(tz)` scope, which rebuckets UTC cagg rows into local calendar
days without extra caggs or raw-table scans.
The scope wraps the rebucketing in a derived table so chained `.where` calls
work correctly. Benchmarking showed this outperforms permanent SQL VIEWs
because the time_column predicate stays in the inner query where the planner
can apply chunk exclusion.
Also adds `timeframe_intervals:` to support custom SQL intervals for symbolic
timeframe names (e.g. `{ halfhour: '30 minutes' }` covers X:30 UTC offsets
like IST, ACST, IRT, and NST with a single cagg level).
Includes 23 specs, a runnable example script, and docs with a day-boundary
proof showing why sub-daily granularity is required for correct TZ rebucketing.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The `t.timestamptz` shorthand was added in Rails 7.0. The scenic Gemfile pins ActiveRecord to 6.1.x, which does not have this method. Use the generic `t.column :ts, :timestamptz` form instead, which works in both 6.1 and 7.0. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello Timescale friends, I had a need for time zones and I think it fits perfectly on the continuous aggregates helper.
Please, check if this would be useful for the core library.
Summary
timezone_aware: trueoption tocontinuous_aggregates— injects anin_timezone(tz)scope into every generated cagg classtimeframe_intervals:to support custom SQL intervals for symbolic timeframe names (e.g.{ halfhour: '30 minutes' }) covering X:30 UTC offsets like IST, ACST, IRT, and NST(time_column AT TIME ZONE tz)::datewithout extra caggs or raw-table scans.wherecalls work correctlytime_columnpredicate stays in the inner query where the planner can apply chunk exclusionWhy sub-daily granularity matters
The daily cagg buckets by UTC midnight, which always straddles local calendar days for non-UTC zones. Reading from a 30-min cagg and rebucketing by local date gives correct results for every timezone — including X:30 offsets.
Test plan
examples/all_in_one/timezone_aware_caggs.rbdocs/models.md