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

Correctly join calculated number of parcels per sale to sales view #334

Conversation

wrridgeway
Copy link
Member

Joining calculated number of sales currently uses an adjusted document number against an un-adjusted document number.

@wrridgeway wrridgeway self-assigned this Mar 8, 2024
@wrridgeway wrridgeway linked an issue Mar 8, 2024 that may be closed by this pull request
@wrridgeway
Copy link
Member Author

wrridgeway commented Mar 8, 2024

Reviewing the data sent by Bill, it seems some sales were getting filtered out during ingest by the sale.num_parcels_sale <= 2 condition in our SQL pull. This was because some sales had NULL values for num_parcels_sold due to a bad join condition.

select
    new.pin,
    new.sale_date,
    new.doc_no,
    new.num_parcels_sale as new,
    old.num_parcels_sale as old
from "z_ci_333-correctly-join-calculated-number-of-parcels-per-sale-to-sales-view_default".vw_pin_sale new
left join default.vw_pin_sale old
    on new.pin = old.pin
    and new.doc_no = old.doc_no
where new.pin = '14313050581003'
pin sale_date doc_no new old
14313050581003 5/26/2016 1620350014 1 1
14313050581003 6/5/2018 1816206243 1 1
14313050581003 5/17/2021 2121008004 1  

@wrridgeway wrridgeway marked this pull request as ready for review March 8, 2024 16:39
@wrridgeway wrridgeway requested a review from a team as a code owner March 8, 2024 16:39
@@ -130,7 +130,8 @@ unique_sales AS (
) AS sale_filter_deed_type
FROM {{ source('iasworld', 'sales') }} AS sales
LEFT JOIN calculated
ON sales.instruno = calculated.instruno
ON NULLIF(REPLACE(sales.instruno, 'D', ''), '')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculated AS (
    SELECT
        instruno,
        COUNT(*) AS nopar_calculated
    FROM (
        SELECT DISTINCT
            parid,
            NULLIF(REPLACE(instruno, 'D', ''), '') AS instruno
        FROM {{ source('iasworld', 'sales') }}
        WHERE deactivat IS NULL
            AND cur = 'Y'
    )
    GROUP BY instruno
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeeep, that'll do it. We'll need to re-ingest sales for modeling.

@wrridgeway
Copy link
Member Author

Count of number of sales with <= 2 for number of parcels per sale now vs NULL previously:

select
    new.year,
    count(*) as "new sales"
from "z_ci_333-correctly-join-calculated-number-of-parcels-per-sale-to-sales-view_default".vw_pin_sale new
left join default.vw_pin_sale old
    on new.doc_no = old.doc_no and new.pin = old.pin
where new.num_parcels_sale <= 2 and old.num_parcels_sale IS NULL
group by new.year
order by new.year desc
year new sales
2023 8745
2022 9545
2021 15162
2020 5909
2019 87
2018 33
2017 19
2016 15
2015 21
2014 12
2013 8
2012 11
2011 2
2010 2
2008 2
2007 1
2006 2
2004 1
2003 1
2002 2
2001 1
2000 1

Copy link
Member

@dfsnow dfsnow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright @wrridgeway, this looks good to go. We'll need to re-export some things. See email for full follow-ups.

@@ -130,7 +130,8 @@ unique_sales AS (
) AS sale_filter_deed_type
FROM {{ source('iasworld', 'sales') }} AS sales
LEFT JOIN calculated
ON sales.instruno = calculated.instruno
ON NULLIF(REPLACE(sales.instruno, 'D', ''), '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeeep, that'll do it. We'll need to re-ingest sales for modeling.

@wrridgeway wrridgeway merged commit 899090a into master Mar 8, 2024
7 checks passed
@wrridgeway wrridgeway deleted the 333-correctly-join-calculated-number-of-parcels-per-sale-to-sales-view branch March 8, 2024 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Correctly join calculated number of parcels per sale to sales view
2 participants