Skip to main content

Origin Model

info

This is part of our beta expression language AQL. Learn more. Request beta.

In AQL, when you apply transformations on a Table or a Field (like select or filter), it outputs a new Table or a Field object that still retains information about the first model that you used.

For example, in the AML layer you have defined a model called order_items, and then you apply some transformations to it:

Model order_items {
dimension item_id {}
dimension order_id
dimension product_id {}
dimension quantity {}
}

Model products {
dimension id {}
dimension price {}
}

Imagine that you use SQL to query these two models:

select
oi.quantity * p.price as item_value
from order_items oi
left join products p on oi.product_id = p.id

After this SQL transformation, you will have a new table with only one column (item_value) and there is no information about order_items or products models.

with order_items_transformed as (
select
order_items.quantity * products.price as item_value
from order_items
left join products on order_items.product_id = products.id
)

// Invalid
select
order_items.order_id
from order_items_transformed

With AQL, the same transformation will also produce a new table with only a value column:

// Output a new virtual 'order_items_transformed' table
order_items | select(item_value: order_items.quantity * products.price)

However, the new table still retains the information about order_items. In this case, order_items is the origin model of the new order_items_transformed table. After the transformation, you can still access information of order_items:

order_items
| select(item_value: order_items.quantity * products.price)
| select(order_items.order_id, order_items.item_id, item_value)

Let us know what you think about this document :)