Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bool or cross db #504

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 %}