Skip to content

Commit

Permalink
Merge pull request #12 from fishtown-analytics/feature/compare-querie…
Browse files Browse the repository at this point in the history
…s-percent-of-total

Feature/compare queries percent of total
  • Loading branch information
Claire Carroll authored Oct 3, 2019
2 parents 88ad370 + b523777 commit 5a4a3d3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ relations. It is largely based on the [equality](https://github.com/fishtown-ana
test in dbt-utils. By default, the generated query returns a summary of audit
results, like so:

| in_a | in_b | count |
|-------|-------|-------|
| True | True | 6870 |
| True | False | 9 |
| False | True | 9 |
| in_a | in_b | count | percent_of_total |
|-------|-------|------:|-----------------:|
| True | True | 6870 | 99.74 |
| True | False | 9 | 0.13 |
| False | True | 9 | 0.13 |

The generated SQL also contains commented-out SQL that you can use to check
the rows that do not match perfectly:
Expand Down Expand Up @@ -105,7 +105,7 @@ two queries, and summarizes how many records match perfectly (note: a primary
key is required to match values across the two queries).

| match_status | count | percent_of_total |
|-----------------------------|--------|------------------|
|-----------------------------|-------:|-----------------:|
| ✅: perfect match | 37,721 | 79.03 |
| ✅: both are null | 5,789 | 12.13 |
| 🤷: missing from b | 25 | 0.05 |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
in_a,in_b,count
True,True,2
in_a,in_b,count,percent_of_total
True,True,2,100
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
in_a,in_b,count
True,True,1
True,False,1
False,True,1
in_a,in_b,count,percent_of_total
True,True,1,33.33
True,False,1,33.33
False,True,1,33.33
6 changes: 5 additions & 1 deletion macros/compare_queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ summary_stats as (
-- where not (in_a and in_b)
-- order by {{ primary_key ~ ", " if primary_key is not none }} in_a desc, in_b desc

select * from summary_stats
select
*,
round(100.0 * count / sum(count) over (), 2) as percent_of_total

from summary_stats
order by in_a desc, in_b desc

{% endmacro %}

0 comments on commit 5a4a3d3

Please sign in to comment.