AML ReferenceProgrammable Constructs
AML Partial
Use AML Partial to extract the shared logic into a new object, making it ready for reuse across multiple objects
Introduction
Partial allows you to extract the shared logic into a new object, making it ready for reuse across multiple objects.
// highlight-start
// partial_timestamps.aml -- Reusable timestamp dimensions
PartialModel partial_timestamps {
dimension created_at {
type: 'datetime'
definition: @sql {{ #SOURCE.created_at }};;
}
dimension updated_at {
type: 'datetime'
definition: @sql {{ #SOURCE.updated_at }};;
}
}
// highlight-end
// users_base.model.aml -- Base model
Model users_base {
type: 'table'
table_name: 'public.users'
data_source_name: 'demodb'
dimension id { ... }
dimension username { ... }
dimension email { ... }
}
// users.model.aml -- Final model composing base + timestamps
// highlight-next-line
Model users = users_base.extend(partial_timestamps)AML Partial is commonly used in conjunction with AML Extend. See syntax and example usages below for more details.
Each built-in object type has a Partial counterpart: PartialModel, PartialTableModel, PartialQueryModel and PartialDataset.
Syntax
// Declaring a partial object
// type can be any of: Model, TableModel, QueryModel, Dataset
Partial<type> <partialName> {
// properties
}
// Usage: extend a named object with the partial
<type> <newName> = <existingObject>.extend(<partialName>)
// Chaining multiple partials
<type> <newName> = <existingObject>
.extend(<partial1>)
.extend(<partial2>)Example usages
Reusing metrics across multiple datasets
Our recommended approach is to split things into separate files for better organization:
// File 1: Reusable metrics only
PartialDataset revenue_metrics {
metric gmv { ... }
metric mrr { ... }
metric arr { ... }
}// File 2: Base dataset with models and relationships
Dataset company_base {
label: "Company Base"
models: [...]
relationships: [...]
}// File 3: Final dataset that composes the base + metrics
Dataset company = company_base
.extend(revenue_metrics)
.extend({
label: "Company"
})You can reuse the same partial across different datasets:
Dataset store = store_base.extend(revenue_metrics)