How can I share logic across multiple models? (Hub and spoke)

Omni allows you to create templated models, which can be shared across different models in your instance. This is a common pattern where a central data team want to provide a core data model to decentralised data functions, and allow them to build on top of that. This could be as part of an enterprise data mesh architecture, or you could be a gaming studio providing common analytics to your individual games.

The first step is to set up your templates. These are the reusable pieces of logic that you want to share between your models. In this example, I create a model called Postgres Template. This is my core (or hub) model. In that I create a new view file:

The template parameter tells Omni that this view file should only be used as an extension to other view files.

I then create another model. This is my spoke model. In the model file, I can import my hub model using the extends parameter.

This will now automatically import all of the elements of the hub model file into my spoke model file (eg. topics, access grants). It also allows me to extend my template views from the core into my spoke view files.

# Reference this view as order_items
schema: public
extends: [ order_items_template ]

dimensions:
...

This will bring the additional fields from order_items_template into my order_items view file, allowing them to be referenced in queries and in new fields.