diff --git a/README.md b/README.md index a8e03d3..9ccd5aa 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,21 @@ performance improvements (idempotent indexes) on raw tables and select marts. --- +## dbt Semantic Layer + +This project defines a dbt Semantic Layer on top of the Olist marts: + +- **Semantic model**: `olist_sales_daily` on top of `mart_olist__sales_daily` + - Time dimension: `order_date` (day granularity) + - Measures: `daily_revenue`, `daily_orders`, `daily_items` +- **Metrics**: + - `total_revenue` (simple metric on `daily_revenue`) + - `total_orders` (simple metric on `daily_orders`) +- **Time spine**: + - `time_spine_daily` – one row per `date_day` between 2016-01-01 and 2018-12-31, declared as the project time spine for MetricFlow. + +--- + ## Project Structure ```text dbt_project/ diff --git a/dbt_project/models/marts/olist/schema.yml b/dbt_project/models/marts/olist/schema.yml index 221ee67..348653c 100644 --- a/dbt_project/models/marts/olist/schema.yml +++ b/dbt_project/models/marts/olist/schema.yml @@ -47,10 +47,12 @@ models: - order_id - order_item_id - - name: mart_olist__sales_daily + time_spine: + standard_granularity_column: order_date columns: - name: order_date + granularity: day tests: [not_null, unique] - name: orders tests: diff --git a/dbt_project/models/marts/olist/semantic_sales.yml b/dbt_project/models/marts/olist/semantic_sales.yml new file mode 100644 index 0000000..73db12c --- /dev/null +++ b/dbt_project/models/marts/olist/semantic_sales.yml @@ -0,0 +1,50 @@ +semantic_models: + - name: olist_sales_daily + description: "Daily sales metrics for Olist; one row per day." + model: ref('mart_olist__sales_daily') + + # Dimensión de tiempo principal + defaults: + agg_time_dimension: order_date + + # Entidad lógica dueña de las dimensiones/medidas + entities: + - name: olist_day + type: primary + + dimensions: + - name: order_date + type: time + type_params: + time_granularity: day + + measures: + - name: daily_revenue + description: "Total revenue per day." + agg: sum + expr: revenue + + - name: daily_orders + description: "Total number of orders per day." + agg: sum + expr: orders + + - name: daily_items + description: "Total items sold per day." + agg: sum + expr: items + +metrics: + - name: total_revenue + description: "Total revenue across all days." + label: Total revenue + type: simple + type_params: + measure: daily_revenue + + - name: total_orders + description: "Total number of orders." + label: Total orders + type: simple + type_params: + measure: daily_orders