udemy-complete-dbt-bootcamp/code_thingies/dbtlearn/models/fact/fact_reviews.sql
Pablo Martin 3fce12819b Thingies
2023-11-03 10:26:11 +01:00

21 lines
No EOL
455 B
SQL

{{
config(
materialized = 'incremental',
on_schema_change = 'fail'
)
}}
WITH src_reviews AS (
SELECT *
FROM
{{ ref('src_reviews') }}
)
SELECT
{{ dbt_utils.surrogate_key(['listing_id', 'review_date', 'reviewer_name', 'review_text']) }} as review_id,
*
FROM
src_reviews
WHERE
review_text IS NOT NULL
{% if is_incremental() %}
AND review_date > (SELECT MAX(review_date) FROM {{ this }})
{% endif %}