-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace all aggregate land calculations with pulls from agg land view (…
…#77)
- Loading branch information
1 parent
4540f35
commit 8e7a22f
Showing
7 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- A view to properly aggregate land square footage at the PIN level. Parcels | ||
-- can have multiple land lines that are sometimes summed or ignored. | ||
WITH total_influ AS ( | ||
SELECT | ||
land.parid, | ||
land.taxyr, | ||
land.lline, | ||
COUNT(*) | ||
OVER (PARTITION BY land.parid, land.taxyr) | ||
AS num_landlines, | ||
SUM(land.sf) OVER (PARTITION BY land.parid, land.taxyr) AS sf_sum, | ||
-- We explicitly want to take the top line land sf if we're only taking | ||
-- one line. | ||
FIRST_VALUE(land.sf) | ||
OVER (PARTITION BY land.parid, land.taxyr ORDER BY land.lline) | ||
AS sf_top, | ||
SUM(CASE WHEN land.influ IS NULL THEN 0 ELSE 1 END) | ||
OVER (PARTITION BY land.parid, land.taxyr) | ||
AS non_null_influ, | ||
MAX(land.sf) OVER (PARTITION BY land.parid, land.taxyr) AS max_sf, | ||
MIN(land.sf) OVER (PARTITION BY land.parid, land.taxyr) AS min_sf, | ||
-- When the first landline for a pin is deactived we should take the | ||
-- minimum value of lline as the top line. | ||
MIN(land.lline) OVER (PARTITION BY land.parid, land.taxyr) AS top_line | ||
FROM {{ source('iasworld', 'land') }} AS land | ||
WHERE | ||
land.cur = 'Y' | ||
AND land.deactivat IS NULL | ||
) | ||
|
||
SELECT | ||
total_influ.parid AS pin, | ||
total_influ.taxyr AS year, | ||
total_influ.num_landlines, | ||
CASE | ||
-- When there are multiple non-null values for influ across land lines | ||
-- and all sf values are the same, we choose the topline land sf, | ||
-- otherwise we sum land sf. | ||
WHEN | ||
total_influ.non_null_influ > 1 | ||
AND total_influ.max_sf = total_influ.min_sf | ||
THEN total_influ.sf_top | ||
ELSE total_influ.sf_sum | ||
END AS sf | ||
FROM total_influ | ||
WHERE total_influ.lline = total_influ.top_line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../aws-athena/views/default-vw_pin_land.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters