🎬 Welcome to our latest video!
🔗 Stay Connected:
LinkedIn: / nijamudhinsb12219296
Instagram: / nijamudhin_shagul
Email: [email protected]
📌 Don't forget to like, comment, and subscribe for more amazing content!
🌟 Notes:
------------------
3. The ref() Function
The ref() function in dbt is used to reference other models in your project. This function ensures that the referenced model is run before the current model and helps dbt manage dependencies between models.
Example:
sql
DIM_HOSTS:
SELECT
ID
, UPPER(NAME)AS NAME
, CASE
WHEN IS_SUPERHOST = 'f' THEN 'FALSE'
ELSE 'TRUE'
END AS IS_SUPERHOST
, CREATED_AT
, UPDATED_AT
FROM {{ ref('STG_HOSTS') }}
DIM_LISTINGS:
SELECT
ID AS LISTING_ID
, LISTING_URL
, INITCAP(NAME) AS NAME
, UPPER(ROOM_TYPE)
, MINIMUM_NIGHTS
, HOST_ID
, REPLACE(PRICE,'$')::INT AS PRICE
, CREATED_AT
, UPDATED_AT
FROM {{ ref('STG_LISTINGS') }}
DIM_REVIEWS:
SELECT
LISTING_ID
, DATE::DATE AS DATE
, UPPER(REVIEWER_NAME) AS REVIEWER_NAME
, INITCAP(COMMENTS) AS COMMENTS
, UPPER(SENTIMENT) AS SENTIMENT
FROM {{ ref('STG_REVIEWS') }}
Using ref() ensures that dbt compiles the models in the correct order, and it also supports versioning and testing across different environments.