Build a dbt project that analyzes product sales performance by category
harbor run -t snowflake-labs/dbt-product-category-analyticsharbor download snowflake-labs/dbt-product-category-analyticsBuild a dbt project that analyzes product sales performance by category hierarchy.
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.
/app/dbt_projectsales_analyticsmainYou must configure dbt to connect to the database:
profiles.yml with profile name dbt_projecttype: duckdb and the database pathsales_analytics/app/dbt_models_snowflake as the baseln -sfn /app/dbt_models_snowflake /app/dbt_projectprofiles.yml in the project directory with profile name retail_dw_mastertype: snowflake using password authentication:
mainThe database contains the following tables across two schemas:
ORDERS schema:
ORDERS.ORDER_LINES - Line items: order_line_id, order_id, product_id, quantity_ordered, unit_price, line_total, statusORDERS.ORDERS - Orders: order_id, customer_id, status, grand_total, ordered_atPRODUCT schema:
PRODUCT.PRODUCTS - Products: product_id, product_code, product_name, primary_category_id, cost_pricePRODUCT.PRODUCT_CATEGORIES - Categories: category_id, category_code, category_name, parent_category_id, category_levelNote on DuckDB: In DuckDB, the orders table is located at main.orders (not ORDERS.ORDERS). Configure your dbt sources accordingly per backend.
Note on cost_price: The cost_price column in PRODUCTS may contain NULL values. Use coalesce(cost_price, 0) to handle missing costs so that downstream cost and profit calculations do not produce NULLs.
Valid order statuses for analysis: COMPLETED, DELIVERED, SHIPPED
Create a dbt project with the following structure:
Create staging models for:
Define appropriate sources for each schema. On Snowflake, both orders and order_lines are in the ORDERS schema. On DuckDB, order_lines is in the ORDERS schema but orders is in the main schema.
Create int_product_sales.sql that:
Create fct_category_performance.sql that aggregates to the category level:
The final fct_category_performance table must have:
trim(), coalesce(), cast(), round(), nullif() which work on both backends--select specifying model names explicitly