TIME_BUCKET
Time bucketing is accomplished through the use of theTIME_BUCKET
function, which calculates the time range in which a given timestamp falls,
based on a set of fixed-width “buckets”, start-aligned to a date/time, and
offset from that start date/time.
The basic form of the TIME_BUCKET function is:
width
width
The number of milliseconds each bucket should span. An
INTERVAL can also be used to specify
the width.timestamp
timestamp
A date/time column or expression, the time portion of which will be used in placing the
corresponding record within the correct time bucket.
offset
offset
The number of milliseconds after (for a positive
offset) or number of milliseconds before
(for a negative offset) the base date/time to which the buckets should be aligned. An
INTERVAL can also be used to specify the offset. The default is no offset.base
base
The starting date/time to which buckets will be aligned. The default is
2000-01-03 00:00:00.Example
Typically,TIME_BUCKET is used in the following type of query:
TIME_BUCKET Example
- Timestamps in the
tscolumn of theexample.host_metricstable will be grouped into buckets - Each bucket will span a
5minute interval - The baseline bucket will start at
2023-02-27 23:57:30(2023-02-28offset by-2.5minutes) and continue through2023-02-28 00:02:30(5minutes from2023-02-27 23:57:30) - Buckets will extend before & after the baseline bucket in contiguous, non-overlapping fashion
- Each result record will show the timestamp in the middle of the bucket’s range
(
+ INTERVAL 2.5 MINUTESfrom the start of each5minute span) and the average CPU usage across the records contained within that date/time range - Gaps in the data will not be filled in with empty buckets—only buckets containing the timestamps
found in the
tscolumn ofexample.host_metricswill be returned in the result set