-
Notifications
You must be signed in to change notification settings - Fork 497
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add safe_divide documentation * add safe_divide macro * add integration test for safe_divide macro * moved macro and documentation to new SQL generator section Co-authored-by: Grace Goheen <[email protected]>
- Loading branch information
1 parent
7eab492
commit f368cec
Showing
5 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
numerator,denominator,output | ||
6,0, | ||
10,5,2 | ||
,, | ||
,0, | ||
17,, | ||
0,, | ||
,9, | ||
0,5,0 |
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,12 @@ | ||
|
||
with data as ( | ||
|
||
select * from {{ ref('data_safe_divide') }} | ||
|
||
) | ||
|
||
select | ||
{{ dbt_utils.safe_divide('numerator', 'denominator') }} as actual, | ||
output as expected | ||
|
||
from data |
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,7 @@ | ||
{% macro safe_divide(numerator, denominator) -%} | ||
{{ return(adapter.dispatch('safe_divide', 'dbt_utils')(numerator, denominator)) }} | ||
{%- endmacro %} | ||
|
||
{% macro default__safe_divide(numerator, denominator) %} | ||
{{ numerator }} / nullif( {{ denominator }}, 0) | ||
{% endmacro %} |