Metric
Metric features are great for aggregations from one-to-many relations. It is commonly used to enrich an entity with aggregated fields from one-to-many related assets or entities.
Simple metric feature
In this example, we define simple metric
features for the entity customer
:
# customer.yml
features:
- type: metric
name: orders_count
asset: db_prod.core.orders
measure: orders_count
data_type: number
filters: null
- type: metric
name: successful_orders_count
asset: db_prod.core.orders
measure: orders_count
data_type: number
time_field: order_date
filters:
- type: field
field: order_status
operator: is
values:
- success
type
type
The feature type.
In case of metric features, it should be set to metric
.
name
name
Give the metric feature a name.
asset
asset
The data asset with the measure to be aggregated to the level of our entity.
asset
should be the full path: "db.schema.name".
join_name
[optional]
join_name
[optional]In case multiple join patterns are defined between an entity and a data asset, join_name
is used to determine which join path to use for a specific feature.
For more information about using multiple join paths between an entity and a data asset, visit the related data assets page.
data_type
[optional]
data_type
[optional]Specify the feature data type.
If no data_type specified, Lynk will assume the data type is string
.
The options for data types are:
string
For any type of string data type
number
For any type of number data type. For example: integer, float, decimal etc..
datetime
For any type of time-based data type. For example: date, timestamp, datetime etc..
bool
For boolean data type.
time_field
[optional]
time_field
[optional]Specifies which asset time field to use in case of time-based aggregation is applied to the metric. If not specified, Lynk will use the asset's default time_field
.
See time aggregation for more information on how time fields are being used for time-based metric aggregations.
measure
measure
The name of the measure we would like to aggregate from the related asset to the level of our entity.
filters
filters
Custom filters to be applied on the data asset. See filters page for in depth information on how to apply filters.
Understanding Metric features
In case we have a many-to-one relationship between a Data Asset and an Entity, and we need to enrich the entity with some aggregation from the Data Asset - we can define which measure to enrich the entity by.
To better understand how Field features work, look the following diagram;

The above diagram shows an example when a customer (entity) has many orders (data asset). That means, each customer
can be associated with many rows in db.schema.orders
.
In this case, we took the measure total_price
which translates to the aggregate definition SUM(total_price)
and adding it to the customer entity as a metric feature.
Last updated