Standardize and unify data using dbt
harbor run -t snowflake-labs/dbt-consolidateharbor download snowflake-labs/dbt-consolidateThe task is to consolidate staging data into an intermediate layer through standardization and union.
You are given multiple ads datasets. The task is to load these datasets into dbt. Implement a staging view on top of it. Finally, write a model in the intermediate layer that unions all these staging views.
This task supports both DuckDB and Snowflake. Run echo $DB_TYPE in a shell BEFORE you write any code or spawn any subagents — the live env determines which backend the verifier runs against. Do NOT assume a default from this prose. Both /app/dbt_models_duckdb/ and /app/dbt_models_snowflake/ exist on disk; the verifier only checks the project matching the live $DB_TYPE.
DB_TYPE=duckdb$DUCKDB_PATH (default: /app/database/retail.duckdb)DB_TYPE=snowflakeSNOWFLAKE_ACCOUNTSNOWFLAKE_USERSNOWFLAKE_PASSWORDSNOWFLAKE_DATABASE - The clone database to useSNOWFLAKE_SCHEMASNOWFLAKE_WAREHOUSESNOWFLAKE_ROLE (optional)Note: For Snowflake, the entrypoint automatically creates a clone database and sets SNOWFLAKE_DATABASE. The clone is destroyed when the task completes.
These CSV files are provided in /app/data:
googleads.csvmetaads.csvtiktokads.csvLoad this data using dbt seed
googleads.csv: ad_date, clicks, impressions, views, conversionsmetaads.csv: ad_date, clicks, impressions, views_1, views_2, conversionstiktokads.csv: ad_date, clicks, impressions, views_1, conversionsInstall dbt-utils package and run dbt deps in the project directory.
Create a dbt project at /app/dbt_consolidate with profiles in the project directory. The name: field in dbt_project.yml must be set to dbt_consolidate exactly.
retail_dw_masteranalyticsConfigure with type: duckdb and database path /app/consolidate.duckdb.
Configure with type: snowflake using password authentication:
Set DBT_PROFILES_DIR to the project directory.
Staging layer (models/staging/):
The staging views must be prefixed with stg__ads_ for ads data.
Clean the data using simple SQL using following instructions:
views in their names into a single column views.qualify clause. Use a window function to identify and remove duplicate rows. Group rows that have identical content and keep only one per group.Note the names of the staging views:
stg__ads_googleads.sql - cleaned google ads datastg__ads_metaads.sql - cleaned meta ads datastg__ads_tiktokads.sql - cleaned tiktok ads dataStandardize all staging outputs to:
ad_date, clicks, impressions, views, conversions
Column combination rules:
googleads.csv: use views as-is.metaads.csv: views = views_1 + views_2.tiktokads.csv: views = views_1.Intermediate layer (models/int/):
Follow these rules for generating Intermediate Table int__ads_unified.sql:
source column for every ads data that goes into table
Required source values:
googlemetatiktokAdditional Instructions
Create a yaml file for staging and int models named staging.yml and int.yml.
For the int__ads_unified.sql, add dbt_utils.unique_combination_of_columns test for the combination of ad_date and source using dbt utils package.
Verify the pipeline with dbt test command.
qualify clause for deduplication (supported by both DuckDB and Snowflake)row_number() window function for deduplication