Syntax
Thefields parameter accepts two formats: an object (recommended) or an array.
- Object (recommended)
- Array
Properties
object | array
required
Maps field names from the base table to columns in the aggregated view, specified as
view_name.field_name.- Object format (recommended): Each key is a field from the base view and each value is the corresponding column name in the aggregate table. This format is more explicit and easier to maintain.
-
Array format: A positional array of field names that correspond to columns in the aggregated view in the order they appear in the view’s
sqlstatement.
view_name.field_name[timeframe] — for example, order_items.created_at[month] for a monthly table. In the object format, quote the key, because the brackets are otherwise not valid YAML.When the base view is used in a topic with joins to other tables, you must include the join keys to those dimension tables in the fields mapping for aggregate awareness to work across those joins. Without the join keys, Omni cannot optimize queries that involve joins.string
required
The name of the base view that this aggregated view summarizes.
Examples
Mapping fields to an aggregate table
In this example, you have anorder_items table that contains a few metrics. Using aggregate awareness, you can create a user_facts table that rolls up these metrics.
Let’s take a look at how the fields in the underlying views will map to the fields in the aggregated user_facts view:
To create this view in Omni, the
user_facts.view file would look like this:
- Object (recommended)
- Array
user_facts.view file
users.id is included in the fields mapping. This is the join key between order_items and users, which enables aggregate awareness to work across joins in topics. When a query joins these tables, Omni can use the user_facts materialized view and perform the join against the pre-aggregated table rather than the full order_items table.
Without aggregate awareness, a query requesting these fields would join the underlying tables and aggregate at query time:
Query without aggregate awareness
materialized_query configured, Omni recognizes that user_facts already contains these results and rewrites the query to hit the aggregate table directly, eliminating the join:
Query with aggregate awareness
Using sketch-based approximate aggregates
You can also materialize and map sketch-based approximate aggregates, such as HyperLogLog (HLL). A sketch is a compact binary summary of a column that Omni can roll up from a finer grain to a coarser one. Sketches need two measures in the base view. In this Snowflake example, the baseorder_items view builds the sketch in one measure and derives the estimate in another:
order_items.view file
daily_user_sketches.view file
order_items.user_approx_distinct_count, Omni routes the query to the materialized sketch in daily_user_sketches instead of the base table.
The Aggregate awareness guide covers the supported sketch functions for Snowflake, BigQuery, and Databricks, and when a Snowflake sketch needs HLL_IMPORT.
