Skip to content

Commit

Permalink
Add bool or cross db (#504)
Browse files Browse the repository at this point in the history
* Create bool_or cross-db func

* Forgot a comma

* Update CHANGELOG.md
  • Loading branch information
joellabes committed Feb 22, 2022
1 parent 5243381 commit 2cfe8c0
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## New features
- A cross-database implementation of `any_value()` ([#497](https://github.com/dbt-labs/dbt-utils/issues/497), [#501](https://github.com/dbt-labs/dbt-utils/pull/501))
- A cross-database implementation of `bool_or()` ([#504](https://github.com/dbt-labs/dbt-utils/pull/504))

## Under the hood
- also ignore `dbt_packages/` directory [#463](https://github.com/dbt-labs/dbt-utils/pull/463)
Expand Down
8 changes: 8 additions & 0 deletions integration_tests/data/cross_db/data_bool_or.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
key,val1,val2
abc,1,1
abc,1,0
def,1,0
hij,1,1
hij,1,
klm,1,0
klm,1,
5 changes: 5 additions & 0 deletions integration_tests/data/cross_db/data_bool_or_expected.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
key,value
abc,true
def,false
hij,true
klm,false
4 changes: 4 additions & 0 deletions integration_tests/models/cross_db_utils/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ models:
- dbt_utils.equality:
compare_model: ref('data_any_value_expected')

- name: test_bool_or
tests:
- dbt_utils.equality:
compare_model: ref('data_bool_or_expected')

- name: test_concat
tests:
Expand Down
5 changes: 5 additions & 0 deletions integration_tests/models/cross_db_utils/test_bool_or.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
select
key,
{{ dbt_utils.bool_or('val1 = val2') }} as value
from {{ ref('data_bool_or' )}}
group by key
24 changes: 24 additions & 0 deletions macros/cross_db_utils/bool_or.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% macro bool_or(expression) -%}
{{ return(adapter.dispatch('bool_or', 'dbt_utils') (expression)) }}
{% endmacro %}


{% macro default__bool_or(expression) -%}

bool_or({{ expression }})

{%- endmacro %}


{% macro snowflake__bool_or(expression) -%}

boolor_agg({{ expression }})

{%- endmacro %}


{% macro bigquery__bool_or(expression) -%}

logical_or({{ expression }})

{%- endmacro %}

0 comments on commit 2cfe8c0

Please sign in to comment.