Skip to content

roundInterval

Description

Returns an interval rounded down to a specified precision. All time units smaller than the specified timeunit are zeroed out.

Syntax

Like many functions in DataPrime, roundInterval supports two notations, function and method notation. These interchangeable forms allow flexibility in how you structure expressions.

roundInterval(interval: interval, scale: timeunit): interval
(interval: interval).roundInterval(scale: timeunit): interval

Arguments

NameTypeRequiredDescription
intervalintervaltrueThe interval to round
scaletimeunittrueThe unit to round to, zeroing out smaller units

Example

Use case: Bucket intervals into whole hours

Logs contain a time_taken interval. Use roundInterval to reduce precision to hours, then format and group by these buckets.

[
{ "time_taken": "2h10m15s" },
{ "time_taken": "3h8m15s" },
{ "time_taken": "5d2h22m46s" },
{ "time_taken": "53m15s" }
]
create time_bucket from roundInterval(time_taken, 'h')
create time_bucket from time_taken.roundInterval('h')

Output

[
{ "time_taken": "2h10m15s", "time_bucket": "2h" },
{ "time_taken": "5d2h22m46s",  "time_bucket": "5d2h" },
{ "time_taken": "3h10m15s", "time_bucket": "3h" },
{ "time_taken": "53m15s",   "time_bucket": "0ns" }
]