Version:

Entity Var

Learn how to create and use entity_var in your Profiles project.

An entity_var adds a calculated (aggregated) column to the entity var tables and downstream feature views. It calculates a single value for each member of the entity (for example, each user).

entity_vars can be features for a feature view or an input to another entity_var.

- entity_var:
    name: entity_var_name
    select: SQL statement
    default_value: value
    from: inputs/table
    where: condition
    window:
        partition_by:
            - partition_column
    description: Days when the user visited the website along with the number of pages visited per date stamp.
FieldDescription
nameName of the entity_var.
selectSQL state, equivalent to SELECT statement.
fromPath of the input table, equivalent to FROM statement.
default_valueDefault value for null values.
whereFiltering condition, equivalent to WHERE statement.
windowAdds partition_by and/or order_by keys for window functions.
descriptionDescription of the entity_var.

Example

# Basic entity
- entity_var:
    name: first_order_date
    select: min(order_date)
    from: inputs/orders
    description: First order date

# Entity that is not a feature
- entity_var:
    name: last_order_date
    select: max(order_date)
    from: inputs/orders
    is_feature: false

# Using an entity_var as an input
- entity_var:
    name: days_since_last_order
    select: "date_diff(CURRENT_DATE(), date({{user.last_order_date}}), day)"
    description: Days since user last completed an order

# Using a window function
- entity_var:
    name: campaign_source_first_touch
    select: first_value(context_campaign_source)
    from: inputs/rsIdentifies
    where: context_campaign_source is not null and context_campaign_source != ''
    window:
        order_by:
            - timestamp

Questions? Contact us by email or on Slack