Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate mydec sales into vw_pin_sale #588

Open
wants to merge 127 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 122 commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
1bf7a95
Try adding new view
wagnerlmichael Sep 9, 2024
4b154ec
Add docs
wagnerlmichael Sep 9, 2024
b984a63
Remove trailing comma
wagnerlmichael Sep 9, 2024
32bbb73
Remove hanging comment
wagnerlmichael Sep 9, 2024
72ba940
remove dead references
wagnerlmichael Sep 9, 2024
229f28d
Remove comma
wagnerlmichael Sep 9, 2024
4ccb968
Try to correct mydec CTA
wagnerlmichael Sep 9, 2024
325f420
Remove comma
wagnerlmichael Sep 9, 2024
8e54d9a
Add seller name
wagnerlmichael Sep 9, 2024
8218d6e
Try some coalesces
wagnerlmichael Sep 9, 2024
483791b
Add souurce sale info
wagnerlmichael Sep 9, 2024
a29fd03
Try coalescing
wagnerlmichael Sep 9, 2024
cc9b0cd
Update pin sale for outer join
wagnerlmichael Sep 10, 2024
92e1368
Aadd full outer join
wagnerlmichael Sep 10, 2024
a0fc872
Add indicator
wagnerlmichael Sep 10, 2024
236d4fd
Try different indicator
wagnerlmichael Sep 10, 2024
10068d8
Add num sales and is_multisale
wagnerlmichael Sep 10, 2024
c2f99cc
Fix coalesce
wagnerlmichael Sep 10, 2024
7641134
Revert pin sale
wagnerlmichael Sep 10, 2024
b3be3f3
Add mydec filters
wagnerlmichael Sep 11, 2024
76a4ef4
Add iasworld filters
wagnerlmichael Sep 11, 2024
30fc3a3
Add sale_10k_filter
wagnerlmichael Sep 11, 2024
75e3956
Add more from pin sale
wagnerlmichael Sep 11, 2024
bfaee09
Add year column
wagnerlmichael Sep 11, 2024
7afdce4
Add sales val cols
wagnerlmichael Sep 11, 2024
2a82467
Remove same status changes
wagnerlmichael Sep 12, 2024
6eb1089
Try new view solution
wagnerlmichael Sep 16, 2024
78b9c79
Add missing cols
wagnerlmichael Sep 16, 2024
777cd39
Try full outer join
wagnerlmichael Sep 16, 2024
1bd4834
Add m columns
wagnerlmichael Sep 16, 2024
3d99d69
Change cte name
wagnerlmichael Sep 17, 2024
50b8d22
Remove experimental view
wagnerlmichael Sep 17, 2024
80113f6
Edit comments
wagnerlmichael Sep 17, 2024
13d69cb
Fix aliases and add line ignores
wagnerlmichael Sep 17, 2024
a46ebb3
remove eda qmd
wagnerlmichael Sep 17, 2024
7c8c084
Remove docs for experimental table
wagnerlmichael Sep 17, 2024
5e67742
Add column in docs
wagnerlmichael Sep 17, 2024
9df5f66
Change test limmit
wagnerlmichael Sep 17, 2024
b336245
Update dbt/models/default/default.vw_pin_sale.sql
wagnerlmichael Sep 18, 2024
9e3a340
Fix sale date ranges
wagnerlmichael Sep 18, 2024
ef3e1ac
Add mydec_date change
wagnerlmichael Sep 18, 2024
0ea03f4
Add better version of sale_date calc
wagnerlmichael Sep 18, 2024
7ea265f
Make is_mydec_date more readable
wagnerlmichael Sep 18, 2024
a8398c7
Add proper 365 calculation
wagnerlmichael Sep 20, 2024
2513f76
Merge branch 'master' into 583-create-a-sales-view-that-combines-iasw…
wagnerlmichael Sep 20, 2024
b180593
Remove dup test
wagnerlmichael Sep 20, 2024
fb49913
Switch to is_mydec_date
wagnerlmichael Sep 20, 2024
e651755
Try a refactor for 365 calc
wagnerlmichael Sep 25, 2024
a41fa49
Try a refactor for 365 calc
wagnerlmichael Sep 25, 2024
6924b06
Start fixing sql format errors
wagnerlmichael Sep 25, 2024
9a1f8c2
Start fixing sql format errors
wagnerlmichael Sep 25, 2024
251bb65
Try adding deed type partition
wagnerlmichael Sep 30, 2024
2c8a9c8
Try fixing deed type
wagnerlmichael Sep 30, 2024
8fb9764
Try fixing 365
wagnerlmichael Sep 30, 2024
33b5bdb
Revert sale key change
wagnerlmichael Sep 30, 2024
62bb6a1
Revert sale key change
wagnerlmichael Sep 30, 2024
1a447f7
Revert sale key change
wagnerlmichael Sep 30, 2024
fb481a3
Correct cte calls
wagnerlmichael Sep 30, 2024
a5f7004
Correct column name alias
wagnerlmichael Sep 30, 2024
a5d069e
Correct column name alias
wagnerlmichael Sep 30, 2024
78fc25d
Correct column name alias
wagnerlmichael Sep 30, 2024
19fd594
Try making less than equal to or less than
wagnerlmichael Sep 30, 2024
a1227b3
Revert change
wagnerlmichael Sep 30, 2024
a69042f
Remove iasworld source filter on 365 calc
wagnerlmichael Oct 1, 2024
2225441
Try another strategy
wagnerlmichael Oct 1, 2024
77683f7
Try another strategy
wagnerlmichael Oct 1, 2024
377f20b
Remove redundant cte
wagnerlmichael Oct 2, 2024
f8152b7
Try first pass at sale filter fix
wagnerlmichael Oct 8, 2024
929eae6
Fix reference for mydec date column
wagnerlmichael Oct 8, 2024
f838d8f
Try fixing col refs
wagnerlmichael Oct 8, 2024
629f38f
Try fixing col refs
wagnerlmichael Oct 8, 2024
224061e
Try fixing col refs
wagnerlmichael Oct 8, 2024
e3c0e9a
Try fixing col refs
wagnerlmichael Oct 8, 2024
05fe0c7
Correct mydec alias
wagnerlmichael Oct 8, 2024
4c30b34
Correct mydec alias
wagnerlmichael Oct 8, 2024
6de42f5
Fix year col name
wagnerlmichael Oct 8, 2024
95ad519
Fix year col name
wagnerlmichael Oct 8, 2024
b9a6186
Fix year col name
wagnerlmichael Oct 8, 2024
ac8268a
Fix year ref
wagnerlmichael Oct 8, 2024
60f4cf7
Fix mydec date
wagnerlmichael Oct 8, 2024
c644766
Fix mydec col ref
wagnerlmichael Oct 9, 2024
2615579
Switch date for boolean
wagnerlmichael Oct 9, 2024
121828f
Revert year ref
wagnerlmichael Oct 9, 2024
4155f10
Try separate ias date ref
wagnerlmichael Oct 9, 2024
64d9977
Correct table ref
wagnerlmichael Oct 9, 2024
eec996c
Fix sale_date calc
wagnerlmichael Oct 9, 2024
f8d08dc
Try old logic to fix is_mydec ind
wagnerlmichael Oct 9, 2024
20bb738
Fix ref
wagnerlmichael Oct 9, 2024
c5d01b8
Fix ref
wagnerlmichael Oct 9, 2024
14fddb2
Try fusion of the logics
wagnerlmichael Oct 9, 2024
6aee2e6
Add missing comma
wagnerlmichael Oct 9, 2024
bc1b6e6
Fix ref
wagnerlmichael Oct 9, 2024
e0e01a9
Add comma
wagnerlmichael Oct 9, 2024
1469310
Fix ref
wagnerlmichael Oct 9, 2024
bb1ddd1
Fix date ref
wagnerlmichael Oct 9, 2024
7007318
Attempt year fix
wagnerlmichael Oct 9, 2024
f13dfe4
Add some documentation
wagnerlmichael Oct 9, 2024
21472dc
Attempt deed type recode
wagnerlmichael Oct 10, 2024
0958638
Attempt deed type recode
wagnerlmichael Oct 10, 2024
56a2279
Attempt accurate recode
wagnerlmichael Oct 10, 2024
f8cef15
Simplify filter
wagnerlmichael Oct 10, 2024
8d59340
Add comma
wagnerlmichael Oct 10, 2024
d1e5d34
Add deed type coalesce
wagnerlmichael Oct 10, 2024
f63cfdd
Fix ref
wagnerlmichael Oct 10, 2024
27d8ac2
Remove hanging parentheses
wagnerlmichael Oct 10, 2024
ce5adcc
Fix ref
wagnerlmichael Oct 10, 2024
0e05f7c
Remove final 365 coalesce
wagnerlmichael Oct 10, 2024
befe90f
Try reversion to older state
wagnerlmichael Oct 10, 2024
5b1c392
Switch mydec logic
wagnerlmichael Oct 11, 2024
8eccfea
Revert year logic
wagnerlmichael Oct 11, 2024
cd5f435
Fix ref
wagnerlmichael Oct 11, 2024
4fd17d2
Fix ref
wagnerlmichael Oct 11, 2024
a33ac1f
Remove comment
wagnerlmichael Oct 11, 2024
afdc790
Add docs
wagnerlmichael Oct 11, 2024
1b83450
Improve cte names
wagnerlmichael Oct 11, 2024
8e0f7c3
Add some feedback
wagnerlmichael Oct 15, 2024
d089352
Add more docs
wagnerlmichael Oct 15, 2024
96f6e1d
Add PR changes
wagnerlmichael Oct 23, 2024
d6579aa
Add year cast
wagnerlmichael Oct 23, 2024
ad9af37
Fix year calc
wagnerlmichael Oct 23, 2024
cd0d5eb
Add documentation
wagnerlmichael Oct 23, 2024
7a224a5
Add nuance info
wagnerlmichael Oct 23, 2024
cf96232
Standardize year logic
wagnerlmichael Nov 4, 2024
6afe4e3
Remove redundant coalesce
wagnerlmichael Nov 4, 2024
4de96f8
Add missing comma
wagnerlmichael Nov 4, 2024
a2375c6
Update year call dbt/models/default/default.vw_pin_sale.sql
wagnerlmichael Nov 4, 2024
2e7de19
Try wrapping 2020 in single quotes
wagnerlmichael Nov 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 197 additions & 86 deletions dbt/models/default/default.vw_pin_sale.sql
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ unique_sales AS (
-- within the last 12 months for the same price. This filter allows us
-- to filter out those sales.
COALESCE(
EXTRACT(DAY FROM sale_date - same_price_earlier_date) <= 365,
DATE_DIFF(
'day',
same_price_earlier_date,
sale_date
) <= 365,
FALSE
) AS sale_filter_same_sale_within_365
FROM (
Expand All @@ -58,11 +62,11 @@ unique_sales AS (
sales.salekey AS sale_key,
NULLIF(REPLACE(sales.instruno, 'D', ''), '') AS doc_no,
NULLIF(sales.instrtyp, '') AS deed_type,
-- "nopar" is number of parcels sold
COALESCE(
sales.nopar > 1 OR calculated.nopar_calculated > 1,
FALSE
) AS is_multisale,
-- "nopar" is number of parcels sold
CASE
WHEN sales.nopar > 1 THEN sales.nopar ELSE
calculated.nopar_calculated
Expand Down Expand Up @@ -137,7 +141,6 @@ unique_sales AS (
ON sales.parid = tc.parid
AND SUBSTR(sales.saledt, 1, 4) = tc.taxyr
WHERE sales.instruno IS NOT NULL
-- Indicates whether a record has been deactivated
AND sales.deactivat IS NULL
AND sales.cur = 'Y'
AND CAST(SUBSTR(sales.saledt, 1, 4) AS INT) BETWEEN 1997 AND YEAR(
Expand All @@ -146,7 +149,6 @@ unique_sales AS (
AND tc.township_code IS NOT NULL
AND sales.price IS NOT NULL
)
-- Only use max price by pin/sale date
WHERE max_price = 1
AND (bad_doc_no = 1 OR is_multisale = TRUE)
),
Expand All @@ -156,16 +158,19 @@ mydec_sales AS (
SELECT
REPLACE(document_number, 'D', '') AS doc_no,
REPLACE(line_1_primary_pin, '-', '') AS pin,
DATE_PARSE(line_4_instrument_date, '%Y-%m-%d') AS mydec_date,
DATE_PARSE(line_4_instrument_date, '%Y-%m-%d') AS sale_date,
line_5_instrument_type AS mydec_deed_type,
NULLIF(TRIM(seller_name), '') AS seller_name,
NULLIF(TRIM(buyer_name), '') AS buyer_name,
CAST(line_11_full_consideration AS BIGINT) AS sale_price,
line_2_total_parcels AS num_parcels_sale,
COALESCE(line_2_total_parcels > 1, FALSE) AS is_multisale,
COALESCE(line_7_property_advertised = 1, FALSE)
AS mydec_property_advertised,
COALESCE(line_10a = 1, FALSE)
AS mydec_is_installment_contract_fulfilled,
COALESCE(line_10b = 1, FALSE)
AS mydec_is_sale_between_related_individuals_or_corporate_affiliates, -- noqa
COALESCE(line_10b = 1, FALSE) --noqa
AS mydec_is_sale_between_related_individuals_or_corporate_affiliates, --noqa
COALESCE(line_10c = 1, FALSE)
AS mydec_is_transfer_of_less_than_100_percent_interest,
COALESCE(line_10d = 1, FALSE)
Expand All @@ -183,7 +188,7 @@ mydec_sales AS (
COALESCE(line_10j = 1, FALSE)
AS mydec_is_seller_buyer_a_relocation_company,
COALESCE(line_10k = 1, FALSE)
AS mydec_is_seller_buyer_a_financial_institution_or_government_agency, -- noqa
AS mydec_is_seller_buyer_a_financial_institution_or_government_agency, --noqa
COALESCE(line_10l = 1, FALSE)
AS mydec_is_buyer_a_real_estate_investment_trust,
COALESCE(line_10m = 1, FALSE)
Expand All @@ -204,10 +209,6 @@ mydec_sales AS (
AS mydec_homestead_exemption_senior_citizens,
line_10s_senior_citizens_assessment_freeze
AS mydec_homestead_exemption_senior_citizens_assessment_freeze,
-- Flag for booting outlier PTAX-203 sales from modeling and
-- reporting. Used in combination with sale_filter upper and lower,
-- which finds sales more than 2 SD from the year, town, and
-- class mean
(
COALESCE(line_10b, 0) + COALESCE(line_10c, 0)
+ COALESCE(line_10d, 0) + COALESCE(line_10e, 0)
Expand All @@ -218,15 +219,14 @@ mydec_sales AS (
COUNT() OVER (
PARTITION BY line_1_primary_pin, line_4_instrument_date
) AS num_single_day_sales,
year_of_sale
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
year_of_sale AS year
FROM {{ source('sale', 'mydec') }}
WHERE line_2_total_parcels = 1 -- Remove multisales
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
)
/* Some sales in mydec have multiple rows for one pin on a given sale date.
Sometimes they have different dates than iasworld prior to 2021 and when
joined back onto unique_sales will create duplicates by pin/sale date. */
WHERE num_single_day_sales = 1
OR (YEAR(mydec_date) > 2020)
OR YEAR(DATE_PARSE(year, '%Y')) > 2020
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
),

max_version_flag AS (
Expand All @@ -249,93 +249,204 @@ sales_val AS (
sf.run_id AS sv_run_id,
sf.version AS sv_version
FROM
{{ source('sale', 'flag') }}
AS sf
{{ source('sale', 'flag') }} AS sf
INNER JOIN max_version_flag AS mv
ON sf.meta_sale_document_num = mv.meta_sale_document_num
AND sf.version = mv.max_version
),

-- CTE to coalesce iasworld and mydec values prior to
-- constructing filters that depend on coalesced fields
combined_sales AS (
SELECT
COALESCE(uq_sales.pin, md_sales.pin) AS pin_coalesced,
-- For many of the fields we used simple coalesce statement,
-- but some data is a bit more complicated. Prior to 2021,
-- mydec sales and iasworld sales used different sale dates.
-- We preference the mydec sale as they are believed to be more
-- accurate. As of 2021, iasworld utilizes mydec sales, which means
-- we can prioritize iasworld data instead of mydec data.
CASE
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
WHEN md_sales.sale_date IS NOT NULL
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
AND (
uq_sales.sale_date IS NULL
OR md_sales.sale_date != uq_sales.sale_date
)
THEN md_sales.year
ELSE uq_sales.year
END AS year_coalesced,
COALESCE(uq_sales.township_code, tc.township_code)
AS township_code_coalesced, --noqa
COALESCE(uq_sales.nbhd, tc.nbhd) AS nbhd_coalesced,
COALESCE(uq_sales.class, tc.class) AS class_coalesced,
CASE --noqa
WHEN
uq_sales.year < '2021'
THEN COALESCE(md_sales.sale_date, uq_sales.sale_date)
ELSE COALESCE(uq_sales.sale_date, md_sales.sale_date)
END AS sale_date_coalesced,
CASE
-- If uq_sales.doc_no is not NULL, apply the COALESCE logic
WHEN uq_sales.doc_no IS NOT NULL
THEN
COALESCE(COALESCE(
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
md_sales.sale_date IS NOT NULL
OR YEAR(uq_sales.sale_date) >= 2021,
FALSE
), FALSE)
-- If uq_sales.doc_no is NULL, set is_mydec_date to TRUE
ELSE
TRUE
END AS is_mydec_date,
COALESCE(uq_sales.sale_price, md_sales.sale_price)
AS sale_price_coalesced, --noqa
uq_sales.sale_key,
COALESCE(uq_sales.doc_no, md_sales.doc_no) AS doc_no_coalesced, --noqa
COALESCE(uq_sales.deed_type, md_sales.mydec_deed_type)
AS deed_type_coalesced,
COALESCE(uq_sales.seller_name, md_sales.seller_name)
AS seller_name_coalesced,
COALESCE(uq_sales.is_multisale, md_sales.is_multisale)
AS is_multisale_coalesced,
COALESCE(uq_sales.num_parcels_sale, md_sales.num_parcels_sale)
AS num_parcels_sale_coalesced,
COALESCE(uq_sales.buyer_name, md_sales.buyer_name)
AS buyer_name_coalesced,
COALESCE(uq_sales.sale_type, NULL) AS sale_type_coalesced,
uq_sales.max_price,
uq_sales.bad_doc_no,
CASE WHEN uq_sales.doc_no IS NOT NULL THEN 'iasworld' ELSE 'mydec' END
AS source,
md_sales.mydec_deed_type,
md_sales.sale_filter_ptax_flag,
md_sales.mydec_property_advertised,
md_sales.mydec_is_installment_contract_fulfilled,
md_sales.mydec_is_sale_between_related_individuals_or_corporate_affiliates, --noqa
md_sales.mydec_is_transfer_of_less_than_100_percent_interest,
md_sales.mydec_is_court_ordered_sale,
md_sales.mydec_is_sale_in_lieu_of_foreclosure,
md_sales.mydec_is_condemnation,
md_sales.mydec_is_short_sale,
md_sales.mydec_is_bank_reo_real_estate_owned,
md_sales.mydec_is_auction_sale,
md_sales.mydec_is_seller_buyer_a_relocation_company,
md_sales.mydec_is_seller_buyer_a_financial_institution_or_government_agency, --noqa
md_sales.mydec_is_buyer_a_real_estate_investment_trust,
md_sales.mydec_is_buyer_a_pension_fund,
md_sales.mydec_is_buyer_an_adjacent_property_owner,
md_sales.mydec_is_buyer_exercising_an_option_to_purchase,
md_sales.mydec_is_simultaneous_trade_of_property,
md_sales.mydec_is_sale_leaseback,
md_sales.mydec_is_homestead_exemption,
md_sales.mydec_homestead_exemption_general_alternative,
md_sales.mydec_homestead_exemption_senior_citizens,
md_sales.mydec_homestead_exemption_senior_citizens_assessment_freeze
FROM unique_sales AS uq_sales
-- This logic brings in mydec sales that aren't in iasworld.
-- If a doc_no exists in iasworld and mydec, we prioritize iasworld,
-- if it only exists in mydec, we will grab the doc_no from mydec. The
-- 'source' column lets us know which table the doc_no came from and allows
-- us to filter for only iasworld sales or for mydec sales that aren't in
-- iasworld already.
FULL OUTER JOIN mydec_sales AS md_sales ON uq_sales.doc_no = md_sales.doc_no
LEFT JOIN town_class AS tc
ON COALESCE(uq_sales.pin, md_sales.pin) = tc.parid
AND COALESCE(uq_sales.year, md_sales.year) = tc.taxyr
),

-- Handle various filters
add_filter_sales AS (
SELECT
cs.*,
-- Calculate 'sale_filter_same_sale_within_365' using DATE_DIFF
-- Note: the sale_filter_same_sale_within_365 uses both iasworld
-- and mydec doc numbers for the calculation. So if we were to set
-- source = 'iasworld', mydec sales will still influence this filter
CASE
WHEN LAG(cs.sale_date_coalesced) OVER (
PARTITION BY cs.pin_coalesced, cs.sale_price_coalesced
ORDER BY cs.sale_date_coalesced ASC
) IS NOT NULL
THEN
DATE_DIFF(
'day',
LAG(cs.sale_date_coalesced) OVER (
PARTITION BY
cs.pin_coalesced, cs.sale_price_coalesced
ORDER BY cs.sale_date_coalesced ASC
),
cs.sale_date_coalesced
) <= 365
ELSE FALSE
END AS sale_filter_same_sale_within_365,
-- Compute 'sale_filter_less_than_10k'
(cs.sale_price_coalesced <= 10000) AS sale_filter_less_than_10k,
-- Compute 'sale_filter_deed_type'
(
cs.deed_type_coalesced IN ('03', '04', '06')
OR cs.deed_type_coalesced IS NULL
) AS sale_filter_deed_type
FROM combined_sales AS cs
)

SELECT
unique_sales.pin,
-- In the past, mydec sale dates were more precise than iasworld dates
-- which had been truncated
CASE
WHEN
mydec_sales.mydec_date IS NOT NULL
AND mydec_sales.mydec_date != unique_sales.sale_date
THEN mydec_sales.year_of_sale
ELSE unique_sales.year
END AS year,
unique_sales.township_code,
unique_sales.nbhd,
unique_sales.class,
-- In the past, mydec sale dates were more precise than iasworld dates
-- which had been truncated
CASE
WHEN
mydec_sales.mydec_date IS NOT NULL
AND mydec_sales.mydec_date != unique_sales.sale_date
THEN mydec_sales.mydec_date
ELSE unique_sales.sale_date
END AS sale_date,
-- From 2021 on iasWorld uses precise MyDec dates
COALESCE(
mydec_sales.mydec_date IS NOT NULL
OR YEAR(unique_sales.sale_date) >= 2021,
FALSE
) AS is_mydec_date,
unique_sales.sale_price,
unique_sales.sale_key,
unique_sales.doc_no,
unique_sales.deed_type,
COALESCE(unique_sales.seller_name, mydec_sales.seller_name) AS seller_name,
unique_sales.is_multisale,
unique_sales.num_parcels_sale,
COALESCE(unique_sales.buyer_name, mydec_sales.buyer_name) AS buyer_name,
unique_sales.sale_type,
unique_sales.sale_filter_same_sale_within_365,
unique_sales.sale_filter_less_than_10k,
unique_sales.sale_filter_deed_type,
afs.pin_coalesced AS pin,
afs.year_coalesced AS year,
afs.township_code_coalesced AS township_code,
afs.nbhd_coalesced AS nbhd,
afs.class_coalesced AS class,
afs.sale_date_coalesced AS sale_date,
afs.is_mydec_date,
afs.sale_price_coalesced AS sale_price,
afs.sale_key,
afs.doc_no_coalesced AS doc_no,
afs.deed_type_coalesced AS deed_type,
afs.seller_name_coalesced AS seller_name,
afs.is_multisale_coalesced AS is_multisale,
afs.num_parcels_sale_coalesced AS num_parcels_sale,
afs.buyer_name_coalesced AS buyer_name,
afs.sale_type_coalesced AS sale_type,
afs.sale_filter_same_sale_within_365,
afs.sale_filter_less_than_10k,
afs.sale_filter_deed_type,
-- Our sales validation pipeline only validates sales past 2014 due to MyDec
-- limitations. Previous to that values for sv_is_outlier will be NULL, so
-- if we want to both exclude detected outliers and include sales prior to
-- 2014, we need to code everything NULL as FALSE.
COALESCE(sales_val.sv_is_outlier, FALSE) AS sale_filter_is_outlier,
mydec_sales.mydec_deed_type,
mydec_sales.sale_filter_ptax_flag,
mydec_sales.mydec_property_advertised,
mydec_sales.mydec_is_installment_contract_fulfilled,
mydec_sales.mydec_is_sale_between_related_individuals_or_corporate_affiliates, -- noqa
mydec_sales.mydec_is_transfer_of_less_than_100_percent_interest,
mydec_sales.mydec_is_court_ordered_sale,
mydec_sales.mydec_is_sale_in_lieu_of_foreclosure,
mydec_sales.mydec_is_condemnation,
mydec_sales.mydec_is_short_sale,
mydec_sales.mydec_is_bank_reo_real_estate_owned,
mydec_sales.mydec_is_auction_sale,
mydec_sales.mydec_is_seller_buyer_a_relocation_company,
mydec_sales.mydec_is_seller_buyer_a_financial_institution_or_government_agency, -- noqa
mydec_sales.mydec_is_buyer_a_real_estate_investment_trust,
mydec_sales.mydec_is_buyer_a_pension_fund,
mydec_sales.mydec_is_buyer_an_adjacent_property_owner,
mydec_sales.mydec_is_buyer_exercising_an_option_to_purchase,
mydec_sales.mydec_is_simultaneous_trade_of_property,
mydec_sales.mydec_is_sale_leaseback,
mydec_sales.mydec_is_homestead_exemption,
mydec_sales.mydec_homestead_exemption_general_alternative,
mydec_sales.mydec_homestead_exemption_senior_citizens,
mydec_sales.mydec_homestead_exemption_senior_citizens_assessment_freeze,
afs.mydec_deed_type,
afs.sale_filter_ptax_flag,
afs.mydec_property_advertised,
afs.mydec_is_installment_contract_fulfilled,
afs.mydec_is_sale_between_related_individuals_or_corporate_affiliates, --noqa
afs.mydec_is_transfer_of_less_than_100_percent_interest,
afs.mydec_is_court_ordered_sale,
afs.mydec_is_sale_in_lieu_of_foreclosure,
afs.mydec_is_condemnation,
afs.mydec_is_short_sale,
afs.mydec_is_bank_reo_real_estate_owned,
afs.mydec_is_auction_sale,
afs.mydec_is_seller_buyer_a_relocation_company,
afs.mydec_is_seller_buyer_a_financial_institution_or_government_agency, --noqa
afs.mydec_is_buyer_a_real_estate_investment_trust,
afs.mydec_is_buyer_a_pension_fund,
afs.mydec_is_buyer_an_adjacent_property_owner,
afs.mydec_is_buyer_exercising_an_option_to_purchase,
afs.mydec_is_simultaneous_trade_of_property,
afs.mydec_is_sale_leaseback,
afs.mydec_is_homestead_exemption,
afs.mydec_homestead_exemption_general_alternative,
afs.mydec_homestead_exemption_senior_citizens,
afs.mydec_homestead_exemption_senior_citizens_assessment_freeze,
sales_val.sv_is_outlier,
sales_val.sv_is_ptax_outlier,
sales_val.sv_is_heuristic_outlier,
sales_val.sv_outlier_reason1,
sales_val.sv_outlier_reason2,
sales_val.sv_outlier_reason3,
sales_val.sv_run_id,
sales_val.sv_version
FROM unique_sales
LEFT JOIN mydec_sales
ON unique_sales.doc_no = mydec_sales.doc_no
sales_val.sv_version,
afs.source
FROM add_filter_sales AS afs
LEFT JOIN sales_val
ON unique_sales.doc_no = sales_val.meta_sale_document_num;
ON afs.doc_no_coalesced = sales_val.meta_sale_document_num;
5 changes: 4 additions & 1 deletion dbt/models/default/docs.md
wagnerlmichael marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ Sourced from `iasworld.sales`, which is sourced from
- Multicard sales are excluded from `mydec` data because they can't be joined
to `iasworld.sales` (which is only parcel-level) without creating duplicates
- Sales are unique by `doc_no` if multisales are excluded. When multisales are
*not* excluded, sales are unique by `doc_no` and `pin`.
_not_ excluded, sales are unique by `doc_no` and `pin`.
- We include iasworld sales and mydec sales only if the mydec sale isn't already
present in iasworld (calculated by doc_no). This allows us to use mydec sales
for analysis or modeling if the iasworld sales ingest is lags behind mydec.

### Lineage

Expand Down
Loading
Loading