Push Omni topics to Databricks as metric views
CREATE VIEW ... WITH METRICS statement that you can run directly in Databricks.
How it works
The script calls the Omni API endpoint Retrieve a topic API to retrieve the full topic definition, including its views, dimensions, measures, and relationships. It then:- Identifies the base view (fact table) and its fully qualified table name as the metric view source.
- Maps each dimension and measure to the Databricks metric view YAML format, transforming Omni’s
${field_name}SQL references into Databricks-compatible syntax. - Wraps the YAML in a
CREATE OR REPLACE VIEW ... WITH METRICS LANGUAGE YAMLDDL statement.
Requirements
- Python 3.9 or later. Additionally, this guide uses pip to install Python dependencies, but you can use a different package manager.
- A Databricks connection
- An Omni API key
- Permissions in Omni that allow you to access the model you want to export
- The model ID and topic name for the topic you want to export
Steps
Find your model ID and topic name
You’ll need two values from Omni:
-
Model ID: Open the model IDE and copy the model ID from the URL. The model ID is the UUID in the URL after
/models. In the following URL, for example, the model IDE isabcd1234-5678-90ab-cdef-1234567890ab: -
Topic name: The name of the topic as it appears in the model, such as
order_items.
Run the script
The SDK includes a script that fetches the topic definition and generates Databricks DDL. The script takes the following arguments:Run the script from the SDK directory, for example:The script outputs a
model_id- Required. The ID of the Omni model.topic_id- Required. The name of the topic you want to export.default_catalog- Optional. The name of the Databricks catalog where you want to create the metric view.default_schema- Optional. The name of the Databricks schema where you want to create the metric view.
CREATE OR REPLACE VIEW statement with the topic’s dimensions, measures, and source table formatted as a Databricks metric view.Execute the DDL in Databricks
Copy the generated DDL and run it in your Databricks SQL console. This creates a new metric view in your Unity Catalog with the naming convention Once created, the metric view is available in Databricks like any other Unity Catalog asset. If you have the Unity Catalog integration enabled, the metric view will also sync back into Omni on the next schema refresh.
OMNI__<topic_name>. For example:Example generated DDL for Omni topic