Posts

Showing posts from June, 2024

Macros in dbt | Data Build Tool | Jinja and macros tutorial

Image
  oms_dbt_proj\macros\oms_common.sql {% macro to_celsius ( fahrenheit_column , decimal_places = 1 ) %}   ROUND ( ({{ fahrenheit_column }} - 32 ) * 5 / 9 , {{ decimal_places }}) {% endmacro %} {% macro generate_profit_model ( table_name ) %} SELECT   sales_date ,   SUM ( quantity_sold * unit_sell_price ) as total_revenue ,   SUM ( quantity_sold * unit_purchase_cost ) as total_cost ,   SUM ( quantity_sold * unit_sell_price ) - SUM ( quantity_sold * unit_purchase_cost ) as total_profit FROM {{ source ( 'training' , table_name ) }} GROUP BY sales_date {% endmacro %} oms_dbt_proj\models\profit_uk.sql {{ generate_profit_model ( 'sales_uk' ) }}

DBT doc blocks | DBT Docs | dbt documentation best practices

Image
  oms_config.yml models :   - name : customers_stg     description : Staged customer data from order management system (OMS), with minor row-level transformations.       columns :       - name : Email         description : Customer's Primay Email address for promotions and offers.               tests :           - string_not_empty   - name : employees_stg     description : Staged employees data from order management system (oms), with minor row-level transformations.       columns :       - name : JobTitle         description : Employee's Job Title based on his current Roles and Responsibilities.               tests :           - string_not_empty   - name : orders_stg     description : Staged orders data from order management system (oms), with minor row-level transformations.       columns :       - name : OrderID         description : The primary key for orders_stg table.               tests :           - unique           - not_null       - name : StatusCD         descr