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.

When we create a metric feature, we apply a measure aggregation to the level of an entity.


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

The feature type. In case of metric features, it should be set to metric.

name

Give the metric feature a name.

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".

asset has to be related to our entity (see related data asset).

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]

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]

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

The name of the measure we would like to aggregate from the related asset to the level of our entity.

Measures are defined on a data asset level. See measures for in depth information on this.

filters

Custom filters to be applied on the data asset. See filters page for in depth information on how to apply filters.

Last updated