OPAL duration conversion¶
Converting to duration¶
OPAL uses values of type duration to store durations of time. Your data may have inputs in units like seconds, milliseconds, or pairs of timestamps.
To convert from seconds to duration, use duration_sec()
:
make_col duration:duration_sec(some_seconds)
To convert from milliseconds to duration, use duration_ms()
:
make_col duration:duration)ms(some_milliseconds)
To convert from two timestamps to duration, use subtraction:
make_col duration:end_time-start_time
Converting from duration¶
Durations are internally stored as nanosecond integers. You can convert a duration to nanoseconds with a simple cast:
make_col nanoseconds:int64(the_duration)
You can convert to some other unit of time by dividing by that time:
make_col hours:the_duration/1h
The duration units supported in OPAL are:
| duration | unit |¶
| nanosecond | 1ns | | microsecond | 1us | | millisecond | 1ms | | second | 1s | | minute | 1m | | hour | 1h | | day | 1d | | week | 1w |
Note that duration literals do not compensate for leap seconds or daylight savings time switch.
In contrast to timestamps, durations will generally participate in aggregations and other operations as if they are numbers, yielding duration results. For example, sum(duration)
or avg(duration)
are well defined operations.