udemy-complete-dbt-bootcamp/code_thingies/dbtlearn/models/fact/fact_reviews.sql

21 lines
455 B
MySQL
Raw Normal View History

2023-10-30 18:04:19 +01:00
{{
config(
materialized = 'incremental',
on_schema_change = 'fail'
)
}}
WITH src_reviews AS (
SELECT *
FROM
{{ ref('src_reviews') }}
)
2023-11-03 10:26:11 +01:00
SELECT
{{ dbt_utils.surrogate_key(['listing_id', 'review_date', 'reviewer_name', 'review_text']) }} as review_id,
*
2023-10-30 18:04:19 +01:00
FROM
src_reviews
WHERE
review_text IS NOT NULL
{% if is_incremental() %}
AND review_date > (SELECT MAX(review_date) FROM {{ this }})
{% endif %}