diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d3eb456..5a27416b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/integration_tests/data/cross_db/data_bool_or.csv b/integration_tests/data/cross_db/data_bool_or.csv new file mode 100644 index 00000000..97ea2ab5 --- /dev/null +++ b/integration_tests/data/cross_db/data_bool_or.csv @@ -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, \ No newline at end of file diff --git a/integration_tests/data/cross_db/data_bool_or_expected.csv b/integration_tests/data/cross_db/data_bool_or_expected.csv new file mode 100644 index 00000000..14f6e92d --- /dev/null +++ b/integration_tests/data/cross_db/data_bool_or_expected.csv @@ -0,0 +1,5 @@ +key,value +abc,true +def,false +hij,true +klm,false \ No newline at end of file diff --git a/integration_tests/models/cross_db_utils/schema.yml b/integration_tests/models/cross_db_utils/schema.yml index 6de8eaf4..dbe7a8f4 100644 --- a/integration_tests/models/cross_db_utils/schema.yml +++ b/integration_tests/models/cross_db_utils/schema.yml @@ -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: diff --git a/integration_tests/models/cross_db_utils/test_bool_or.sql b/integration_tests/models/cross_db_utils/test_bool_or.sql new file mode 100644 index 00000000..7375d1e4 --- /dev/null +++ b/integration_tests/models/cross_db_utils/test_bool_or.sql @@ -0,0 +1,5 @@ +select + key, + {{ dbt_utils.bool_or('val1 = val2') }} as value +from {{ ref('data_bool_or' )}} +group by key \ No newline at end of file diff --git a/macros/cross_db_utils/bool_or.sql b/macros/cross_db_utils/bool_or.sql new file mode 100644 index 00000000..ce0a6857 --- /dev/null +++ b/macros/cross_db_utils/bool_or.sql @@ -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 %} \ No newline at end of file