From 5514820b62b5305506a9a30d45f2ba6de5fd2564 Mon Sep 17 00:00:00 2001 From: Finn van Krieken Date: Tue, 31 Dec 2024 15:23:14 -0500 Subject: [PATCH] add test to ensure all of lots area assigned --- products/cdbg/macros/test_sum.sql | 9 +++++++++ .../cdbg/models/intermediate/_intermediate_models.yml | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 products/cdbg/macros/test_sum.sql diff --git a/products/cdbg/macros/test_sum.sql b/products/cdbg/macros/test_sum.sql new file mode 100644 index 000000000..ffc9f76df --- /dev/null +++ b/products/cdbg/macros/test_sum.sql @@ -0,0 +1,9 @@ +{% test sum_by(model, group_by, target_column, val, precision=4) %} + +SELECT + {{ group_by }}, sum({{ target_column }}) AS sum, array_agg( {{target_column }}) AS vals +FROM {{ model }} +GROUP BY {{ group_by }} +HAVING round(sum({{ target_column }})::numeric, {{ precision }}) <> {{ val }} + +{% endtest %} diff --git a/products/cdbg/models/intermediate/_intermediate_models.yml b/products/cdbg/models/intermediate/_intermediate_models.yml index c200e5511..d5937f1f9 100644 --- a/products/cdbg/models/intermediate/_intermediate_models.yml +++ b/products/cdbg/models/intermediate/_intermediate_models.yml @@ -33,7 +33,7 @@ models: - name: bbl - name: block_group_geoid - name: overlap_ratio - + - name: int__lot_block_groups description: >- unique intersections of pluto lots and census block groups with proportion of lot in block group, @@ -45,6 +45,12 @@ models: tests: - dbt_utils.unique_combination_of_columns: combination_of_columns: [bbl, block_group_geoid] + - sum_by: + group_by: bbl + target_column: overlap_ratio + val: 1 + config: + severity: warn - name: int__tracts description: residential area and low-to-moderate income data aggregated by census tract