feat: expand dbt models

This commit is contained in:
Stijnvandenbroek
2026-03-04 18:18:36 +00:00
parent 3e51d630e6
commit 65134183ca
9 changed files with 253 additions and 33 deletions

View File

@@ -0,0 +1,47 @@
-- Intermediate model: enrich each listing with its most recent asking price
-- and the last recorded sold price from the price history.
with listings as (
select * from {{ ref('stg_funda_listings') }}
),
price_history as (
select * from {{ ref('stg_funda_price_history') }}
),
latest_asking as (
select distinct on (global_id)
global_id,
price as latest_asking_price,
price_date as latest_asking_date
from price_history
where
price_source = 'Funda'
and price_status = 'asking_price'
order by global_id asc, price_date desc
),
latest_sold as (
select distinct on (global_id)
global_id,
price as sold_price,
price_date as sold_date
from price_history
where price_status = 'sold'
order by global_id asc, price_date desc
),
enriched as (
select
l.*,
la.latest_asking_price,
la.latest_asking_date,
ls.sold_price,
ls.sold_date,
ls.sold_price is not null as is_sold
from listings as l
left join latest_asking as la on l.global_id = la.global_id
left join latest_sold as ls on l.global_id = ls.global_id
)
select * from enriched

View File

@@ -0,0 +1,26 @@
version: 2
models:
- name: int_funda_listings_enriched
description: >
Listings joined with the most recent asking price and last sold price from price history. One
row per listing.
meta:
dagster:
group: funda
columns:
- name: global_id
description: Funda internal listing ID.
tests:
- unique
- not_null
- name: latest_asking_price
description: Most recent asking price from Funda price history.
- name: latest_asking_date
description: Date of the most recent asking price event.
- name: sold_price
description: Price at which the listing was sold, if applicable.
- name: sold_date
description: Date the listing was sold, if applicable.
- name: is_sold
description: True when a sold price event exists for this listing.