Skip to main content

AML Reusability Overview

Introduction

Analytics logic can become increasingly complex and difficult to maintain as more models, datasets, and dashboards are added. Analysts may end up reinventing the wheel, duplicating efforts and wasting time building similar functionality across different parts of the system.

One of the key design goals of AML (Analytics Modeling Language) is to make the language highly reusable, addressing this common challenge. Unlike pure data serialization formats like XML, JSON, or YAML, AML provides the ability to define reusable components directly within the language.

These reusability mechanisms enable analysts to factor out and abstract repeated logic, making it easy to share and reuse these components across different datasets and dashboards. This helps reduce duplication, improves maintainability, and increases overall efficiency in the analytics development process.

AML Reusability Overview

Features

Here are the list of reusability features that AML supports:

  • AML Constant: An AML constant allows you to specify a value that can be reused throughout a project.
  • AML Function: An AML function is a reusable block of code designed to perform a specific task.
  • AML Module: An AML module is a directory containing related AML objects and functions together.
  • AML Extend: AML Extend is a function that can be applied on an analytics object to produce a new object that takes on the original properties.
  • AML Partial: AML Partial lets you extract shared logic (such as common dimensions or measures) into a reusable object that can be composed into multiple models.
  • AML String Interpolation: String interpolation is a feature that allows embedding variable values directly into strings.
  • AML If-else: A control-flow expression that conditionally evaluates and returns values, enabling reusable definitions that branch on configuration.

Understanding AML Extend

AML Extend is one of the most powerful reusability features. It has three key properties:

  • Inheritance: When you edit properties in the base objects, these changes propagate to all extending objects.
  • Additive: You can add new properties to the extending objects that do not exist in the base objects.
  • Overriding: You can modify properties that the extending objects inherit from the base objects, without modifying the original properties.

When you use extend(), AML follows these steps:

  1. Clone the object that is being extended
  2. Create a new extending object from the extending code
  3. Merge and resolve any conflicts between these two objects. If a field is defined in both objects, AML always uses the version in the extending object (overriding)

Example:

Model users {
label: 'Users'
dimension id { ... }
}

Model activatedUsers = users.extend({
label: 'Activated users'
dimension activated_at { ... }
})

// Steps:
// 1. Clone the "users" object into a new copy (users_cloned)
// 2. Create a new extending object from the extending code block
// {
// label: 'Activated users'
// dimension activated_at { ... }
// }
// 3. Merge users_cloned to the newly extending object.
// The 'label' field will be overridden by the new value.

// Final result:
Model {
label: 'Activated users'
dimension id { ... }
dimension activated_at { ... }
}

Use Cases

Guide

Please refer to the AML Reusability Guide for detailed steps on how to utilize AML's reusability features.


Open Markdown
Let us know what you think about this document :)