make_resource¶
Type of operation: Metadata
Description¶
Creates a Resource dataset from an input Event or Interval dataset.
make_resource
must specify a primary key when the verb input dataset has
none. If no primary key is specified, the input’s primary key will be used
in the output.
For Event datasets, make_resource
collapses adjacent events that contain
the same primary key value and column values, and uses the first time such
event is observed as Valid From
. The end result is a dataset that stores
snapshots of the state of the observed entity, as a resource.
For Interval datasets, make_resource
will behave as though the input is
an Event dataset whose timestamp column is the “Valid From” column, and the
“Valid To” column will be used as a default validfor
.
The Valid To
of the row is determined by the minimal of the following three
things:
the timestamp of the next distinct event
Valid From
+ the expression optionally specified invalidfor
Valid From
+ theexpiry
option value.
If an expiry
value is not provided, the default is 24 hours (86,400 seconds.)
Using the expiry
option costs less than using the more flexible validfor
argument. If you can live with a constant maximum resource lifetime, using
something like options(expiry:24h)
is the most efficient option.
Note that make_resource
cannot be used to directly convert a Table dataset
to a Resource dataset. To do this, first convert the Table dataset to an
Event dataset using make_event
or to an Interval dataset using make_interval
,
and then you can use make_resource
.
Behavior of make_resource
verb when handling events with same key arriving
at the same time is undefined. Current implementation will handle them in a best
effort manner, and merge the events by picking a random non-null values for each column.
Usage¶
make_resource [ options ], [ columnbinding_1, columnbinding_2, ... ], [ primarykey ], [ validfor ]
Argument |
Type |
Optional |
Repeatable |
Restrictions |
---|---|---|---|---|
options |
options |
yes |
no |
constant |
columnbinding |
expression |
yes |
yes |
none |
primarykey |
primarykey |
yes |
no |
none |
validfor |
validfor |
yes |
no |
none |
Options¶
Option |
Type |
Meaning |
---|---|---|
expiry |
duration |
How long a Resource lifetime is extended after an observed state change. |
Accelerable¶
make_resource is always accelerable if the input is accelerable. A dataset that only uses accelerable verbs can be accelerated, making queries on the dataset respond faster.
Examples¶
make_resource options(expiry:duration_hr(1)), col1:col1, primary_key(pk1, pk2)
From the input Event dataset, creates a Resource dataset with the primary key (pk1, pk2) and column col1 with an expiry period of 1 hour.
make_resource col1:col1, primary_key(pk1, pk2), valid_for(duration(col2))
From the input Event dataset, creates a Resource dataset with the primary key (pk1, pk2) and column col1 with an expiry period determined by column col2.
make_resource col1:col1, primary_key(pk1, pk2)
From the input Interval dataset, creates a Resource dataset with the primary key (pk1, pk2) and column col1 with an expiry period determined by the input dataset’s “Valid To” column.
make_resource col1:col1
Assume the verb input is an Event dataset with a primary key (pk1, pk2) and additional columns col1 and col2. The above OPAL creates a Resource dataset with the primary key (pk1, pk2) and column col1 with the default 24-hour expiry period. Notice that the input primary key is propagated to the output, since there is no primary_key
clause.
make_resource col1:col1, primary_key(pk1)
Assume the verb input is an Event dataset with a primary key (pk1, pk2) and additional columns col1 and col2. The above OPAL creates a Resource dataset with the primary key (pk1) and column col1 with the default 24-hour expiry period. Notice that the primary_key
clause overrides the primary key of the verb’s input dataset.
Aliases¶
makeresource
(deprecated)