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

Ensure reporting.vw_pin_most_recent_sale rowcount is correct before ias rollover #698

Conversation

jeancochrane
Copy link
Contributor

@jeancochrane jeancochrane commented Jan 6, 2025

The reporting.vw_pin_most_recent_sale view currently has the wrong number of rows since its query filters iasworld.pardat by YEAR(CURRENT_DATE), but we don't have 2025 data in iasWorld as the rollover hasn't happened yet. We got notified of this bug by our weekly tests, which failed this morning.

This PR updates reporting.vw_pin_most_recent_sale so that it filters pardat for the most recent available year in that table. It also simplifies the rowcount tests for the model to be more accurate and easier to debug.

@jeancochrane jeancochrane marked this pull request as ready for review January 6, 2025 17:44
@jeancochrane jeancochrane requested a review from a team as a code owner January 6, 2025 17:44
@jeancochrane jeancochrane requested a review from dfsnow January 6, 2025 17:45
AND deactivat IS NULL
-- noqa: disable=RF02
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There may be a bug in RF02 in our version of SQLFluff, since this block doesn't seem to me to represent an unqualified reference. It doesn't raise an error, but the warning is annoying, so I ignore it just for this block.

Comment on lines +205 to +207
# Rowcount will typically exceed iasworld.pardat due to sales with
# PINs that are not in pardat, but at a minimum we want one row
# for each PIN that we know about in pardat
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could make this even more accurate by joining to pardat by PIN, but that would make the test more complicated and I think the simple rowcount is good enough to catch cases like the one that inspired this PR.

Copy link
Member

@wrridgeway wrridgeway left a comment

Choose a reason for hiding this comment

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

Thanks for fixing this @jeancochrane. I should check our other views from any use of CURRENT_DATE that might lead to similar issues.

@jeancochrane
Copy link
Contributor Author

I should check our other views from any use of CURRENT_DATE that might lead to similar issues.

I took a quick look, and everything else that uses current_date seems OK to me!

@jeancochrane jeancochrane removed the request for review from dfsnow January 7, 2025 15:38
@jeancochrane jeancochrane merged commit 6a527bb into master Jan 7, 2025
8 checks passed
@jeancochrane jeancochrane deleted the jeancochrane/account-for-ias-rollover-in-most-recent-sale-view branch January 7, 2025 15:39
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.

2 participants