Model Gold with dbt
This lesson creates the campaign_performance data product with olf product new, writes its dbt model and tests, and deploys it. Gold is the layer that
holds business marts, built in SQL by dbt-trino from the Silver tables.
You will build one Gold mart from the Silver campaigns table and deploy
it, in about 15 minutes.
Start from the project of lesson 3: the
marketing domain and its Floe contract exist.
1. Create the product
Section titled “1. Create the product”olf product new marketing/campaign_performance \ --silver-input campaigns \ --gold-table mart_campaign_performanceCreated product marketing/campaign_performance with 1 Gold table(s): mart_campaign_performance.--silver-input names a Silver table of the domain that the product reads,
and --gold-table a mart it produces. The command adds the product to
lakehouse_code/lakehouse.yaml and creates:
lakehouse_code/├── gold/campaign_performance/│ ├── __init__.py│ └── dbt/│ ├── dbt_project.yml│ ├── packages.yml│ └── models/│ ├── sources.yml│ └── gold/│ ├── mart_campaign_performance.sql│ └── schema.yml└── pipelines/dagster/campaign_performance.py2. Know the generated dbt project
Section titled “2. Know the generated dbt project”You do not edit most of it:
dbt_project.ymlmaterializes every model as an Iceberg table that is replaced on each run, in the catalog of the stage being deployed. Do not hard-code Trino hosts or catalog settings in it: OpenLakeForge renders the dbtprofiles.ymlfor each environment.packages.ymlpulls in the shared OpenLakeForge dbt package fromlibs/.models/sources.ymldeclares the Silver table as a dbt source, in themarketing_silverschema. dbt reads the table Floe owns and does not build a second staging layer.
Ownership follows the layer: Bronze belongs to dlt, Silver to Floe, Gold to
dbt. The Gold namespace is owned by the product and has no domain prefix:
campaign_performance_gold.
3. Write the model
Section titled “3. Write the model”The scaffold generated a placeholder that selects everything from Silver. Replace it with an aggregation by channel:
cat > lakehouse_code/gold/campaign_performance/dbt/models/gold/mart_campaign_performance.sql <<'SQL'with campaigns as ( select campaign_id, cast(campaign_date as date) as campaign_date, channel, cast(spend as double) as spend, cast(conversions as bigint) as conversions from {{ source('silver', 'campaigns') }})
select channel, cast(count(*) as bigint) as campaign_count, cast(sum(spend) as double) as total_spend, cast(sum(conversions) as bigint) as total_conversionsfrom campaignsgroup by channelSQL4. Document and test the model
Section titled “4. Document and test the model”Describe the mart and its columns, and add dbt tests. dbt runs them in the
same dbt build that creates the table, so a failing test fails the run:
cat > lakehouse_code/gold/campaign_performance/dbt/models/gold/schema.yml <<'YAML'version: 2
models: - name: mart_campaign_performance description: Campaign spend and conversions aggregated by channel. columns: - name: channel description: Marketing channel of the campaigns. data_tests: - unique - not_null - name: total_spend description: Sum of campaign spend for the channel.YAML5. Deploy the product
Section titled “5. Deploy the product”The platform is already running, so deploy only the artifacts phase, which
covers everything derived from lakehouse_code/:
olf deploy --provider local --phase artifactsIt reconciles the catalog namespaces, generates the Floe manifests, builds the
project-code image, loads it into the cluster and restarts the Dagster code
location. The namespaces marketing_platform_bronze, marketing_silver and
campaign_performance_gold are created for you; no Terraform change is
needed.
Check it worked
Section titled “Check it worked”olf e2e run --env local --suite fullThe suite discovers products from the project, so campaign_performance is
included without any registration. It launches every product’s job, verifies
the Silver and Gold tables exist and requires rows in every Gold mart,
including mart_campaign_performance. It ends with:
Local OpenLakeForge full e2e validation passed.Then look at the rows themselves. olf query runs SQL against the DEV
stage’s catalog, so a table is named <schema>.<table>:
olf query "SELECT * FROM campaign_performance_gold.mart_campaign_performance ORDER BY channel"It prints one row per marketing channel, with its campaign_count,
total_spend and total_conversions. Add --format csv or --format json
for other output.
What you learned
Section titled “What you learned”olf product newcreates a product-owned dbt project and a Dagster module and registers the product inlakehouse.yaml.olf queryreads any Silver or Gold table of a stage from your machine.- Gold is plain SQL over declared Silver sources; tests run as part of the build.
olf deploy --phase artifactsships code changes without touching the platform.
Orchestrate and schedule: run the product’s job from Dagster and see how scheduling works.
Synced from openlakeforge @ v0.5.0-alpha.1 (1598142), docs/tutorial/04-model-gold-with-dbt.md.