More models and knowledge
This commit is contained in:
parent
23a70ed74e
commit
ab581b0fb5
5 changed files with 83 additions and 3 deletions
|
|
@ -27,8 +27,8 @@ clean-targets: # directories to be removed by `dbt clean`
|
|||
# Configuring models
|
||||
# Full documentation: https://docs.getdbt.com/docs/configuring-models
|
||||
|
||||
# In this example config, we tell dbt to build all models in the example/
|
||||
# directory as views. These settings can be overridden in the individual model
|
||||
# files using the `{{ config(...) }}` macro.
|
||||
models:
|
||||
dbtlearn:
|
||||
+materialized: view # Default way to materialize is view
|
||||
dim:
|
||||
+materialized: table
|
||||
|
|
|
|||
16
code_thingies/dbtlearn/models/dim/dim_hosts_cleansed.sql
Normal file
16
code_thingies/dbtlearn/models/dim/dim_hosts_cleansed.sql
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
WITH src_hosts AS(
|
||||
SELECT *
|
||||
FROM {{ ref('src_hosts') }}
|
||||
)
|
||||
SELECT
|
||||
host_id,
|
||||
COALESCE(
|
||||
host_name,
|
||||
'Anonymous'
|
||||
) AS host_name,
|
||||
CASE
|
||||
WHEN flag_is_superhost = 't' THEN true
|
||||
WHEN flag_is_superhost = 'f' THEN false
|
||||
END::bool AS flag_is_superhost
|
||||
FROM
|
||||
src_hosts
|
||||
20
code_thingies/dbtlearn/models/dim/dim_listings_cleansed.sql
Normal file
20
code_thingies/dbtlearn/models/dim/dim_listings_cleansed.sql
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
WITH src_listings AS (
|
||||
SELECT *
|
||||
FROM
|
||||
{{ ref('src_listings') }}
|
||||
)
|
||||
SELECT
|
||||
listing_id,
|
||||
listing_name,
|
||||
room_type,
|
||||
CASE
|
||||
WHEN minimum_nights = 0 THEN 1
|
||||
ELSE minimum_nights
|
||||
END AS mininum_nights,
|
||||
host_id,
|
||||
REPLACE(price_str,'$','')::money AS price,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
src_listings
|
||||
|
||||
19
code_thingies/dbtlearn/models/fact/fact_reviews.sql
Normal file
19
code_thingies/dbtlearn/models/fact/fact_reviews.sql
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{{
|
||||
config(
|
||||
materialized = 'incremental',
|
||||
on_schema_change = 'fail'
|
||||
)
|
||||
}}
|
||||
WITH src_reviews AS (
|
||||
SELECT *
|
||||
FROM
|
||||
{{ ref('src_reviews') }}
|
||||
)
|
||||
SELECT *
|
||||
FROM
|
||||
src_reviews
|
||||
WHERE
|
||||
review_text IS NOT NULL
|
||||
{% if is_incremental() %}
|
||||
AND review_date > (SELECT MAX(review_date) FROM {{ this }})
|
||||
{% endif %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue