From ae6e1b43e6c57ec8afbd550236a1d59ec668df4e Mon Sep 17 00:00:00 2001 From: Doug Beatty <44704949+dbeatty10@users.noreply.github.com> Date: Fri, 17 Jun 2022 08:56:06 -0600 Subject: [PATCH] Lift + shift for cross-db macros (#597) * Initialize lift + shift, dateadd + datediff * Install branches of all plugins * Use dispatch for passthrough behavior * Only support dbt-core >= 1.2 * Switch to alternative dev branches * Lift and shift cross-database macros, fixtures, and tests into dbt-core and adapters * Test `current_timestamp()` adapter definition vs. original dbt-utils * Split out the `current_timestamp` work into its own separate effort (#599) * Reinstate original `current_timestamp` implementation * Reinstate original `type_*` implementations * Reinstate original `current_timestamp_in_utc` implementation * Kick out the `current_timestamp` + `type_*` tests * Preserve `dbt_utils` as one more step along the dispatch train * Remove branch identifiers Co-authored-by: Jeremy Cohen --- dev-requirements.txt | 7 +- macros/cross_db_utils/any_value.sql | 16 +- macros/cross_db_utils/bool_or.sql | 23 +-- macros/cross_db_utils/cast_bool_to_text.sql | 12 +- macros/cross_db_utils/concat.sql | 4 +- macros/cross_db_utils/date_trunc.sql | 12 +- macros/cross_db_utils/dateadd.sql | 34 +---- macros/cross_db_utils/datediff.sql | 67 +-------- .../cross_db_utils/escape_single_quotes.sql | 19 +-- macros/cross_db_utils/except.sql | 13 +- macros/cross_db_utils/hash.sql | 10 +- macros/cross_db_utils/intersect.sql | 13 +- macros/cross_db_utils/last_day.sql | 39 +---- macros/cross_db_utils/length.sql | 22 +-- macros/cross_db_utils/listagg.sql | 103 +------------ macros/cross_db_utils/literal.sql | 7 +- macros/cross_db_utils/position.sql | 23 +-- macros/cross_db_utils/replace.sql | 16 +- macros/cross_db_utils/right.sql | 39 +---- macros/cross_db_utils/safe_cast.sql | 17 +-- macros/cross_db_utils/split_part.sql | 69 +-------- .../cross_db_utils/fixture_any_value.py | 61 -------- .../cross_db_utils/fixture_bool_or.py | 63 -------- .../fixture_cast_bool_to_text.py | 30 ---- .../cross_db_utils/fixture_concat.py | 36 ----- .../fixture_current_timestamp.py | 20 --- .../fixture_current_timestamp_in_utc.py | 20 --- .../cross_db_utils/fixture_date_trunc.py | 41 ----- .../cross_db_utils/fixture_dateadd.py | 41 ----- .../cross_db_utils/fixture_datediff.py | 66 --------- .../fixture_escape_single_quotes.py | 25 ---- .../cross_db_utils/fixture_except.py | 65 -------- .../functional/cross_db_utils/fixture_hash.py | 35 ----- .../cross_db_utils/fixture_intersect.py | 59 -------- .../cross_db_utils/fixture_last_day.py | 40 ----- .../cross_db_utils/fixture_length.py | 36 ----- .../cross_db_utils/fixture_listagg.py | 111 -------------- .../cross_db_utils/fixture_position.py | 36 ----- .../cross_db_utils/fixture_replace.py | 40 ----- .../cross_db_utils/fixture_right.py | 36 ----- .../cross_db_utils/fixture_safe_cast.py | 34 ----- .../cross_db_utils/fixture_split_part.py | 50 ------- .../cross_db_utils/fixture_string_literal.py | 20 --- .../cross_db_utils/fixture_type_bigint.py | 36 ----- .../cross_db_utils/fixture_type_boolean.py | 36 ----- .../cross_db_utils/fixture_type_float.py | 36 ----- .../cross_db_utils/fixture_type_int.py | 36 ----- .../cross_db_utils/fixture_type_numeric.py | 36 ----- .../cross_db_utils/fixture_type_string.py | 36 ----- .../cross_db_utils/fixture_type_timestamp.py | 36 ----- .../cross_db_utils/test_any_value.py | 28 ---- .../functional/cross_db_utils/test_bool_or.py | 28 ---- .../cross_db_utils/test_cast_bool_to_text.py | 19 --- .../functional/cross_db_utils/test_concat.py | 24 --- .../cross_db_utils/test_current_timestamp.py | 19 --- .../test_current_timestamp_in_utc.py | 19 --- .../cross_db_utils/test_date_trunc.py | 24 --- .../functional/cross_db_utils/test_dateadd.py | 40 ----- .../cross_db_utils/test_datediff.py | 24 --- .../test_escape_single_quotes.py | 45 ------ .../functional/cross_db_utils/test_except.py | 72 --------- tests/functional/cross_db_utils/test_hash.py | 24 --- .../cross_db_utils/test_intersect.py | 70 --------- .../cross_db_utils/test_last_day.py | 24 --- .../functional/cross_db_utils/test_length.py | 24 --- .../functional/cross_db_utils/test_listagg.py | 28 ---- .../cross_db_utils/test_position.py | 24 --- .../functional/cross_db_utils/test_replace.py | 24 --- tests/functional/cross_db_utils/test_right.py | 24 --- .../cross_db_utils/test_safe_cast.py | 24 --- .../cross_db_utils/test_split_part.py | 24 --- .../cross_db_utils/test_string_literal.py | 19 --- .../cross_db_utils/test_type_bigint.py | 25 ---- .../cross_db_utils/test_type_boolean.py | 25 ---- .../cross_db_utils/test_type_float.py | 25 ---- .../cross_db_utils/test_type_int.py | 25 ---- .../cross_db_utils/test_type_numeric.py | 25 ---- .../cross_db_utils/test_type_string.py | 25 ---- .../cross_db_utils/test_type_timestamp.py | 25 ---- tests/functional/cross_db_utils/test_utils.py | 140 ++++++++++++++++++ 80 files changed, 222 insertions(+), 2526 deletions(-) delete mode 100644 tests/functional/cross_db_utils/fixture_any_value.py delete mode 100644 tests/functional/cross_db_utils/fixture_bool_or.py delete mode 100644 tests/functional/cross_db_utils/fixture_cast_bool_to_text.py delete mode 100644 tests/functional/cross_db_utils/fixture_concat.py delete mode 100644 tests/functional/cross_db_utils/fixture_current_timestamp.py delete mode 100644 tests/functional/cross_db_utils/fixture_current_timestamp_in_utc.py delete mode 100644 tests/functional/cross_db_utils/fixture_date_trunc.py delete mode 100644 tests/functional/cross_db_utils/fixture_dateadd.py delete mode 100644 tests/functional/cross_db_utils/fixture_datediff.py delete mode 100644 tests/functional/cross_db_utils/fixture_escape_single_quotes.py delete mode 100644 tests/functional/cross_db_utils/fixture_except.py delete mode 100644 tests/functional/cross_db_utils/fixture_hash.py delete mode 100644 tests/functional/cross_db_utils/fixture_intersect.py delete mode 100644 tests/functional/cross_db_utils/fixture_last_day.py delete mode 100644 tests/functional/cross_db_utils/fixture_length.py delete mode 100644 tests/functional/cross_db_utils/fixture_listagg.py delete mode 100644 tests/functional/cross_db_utils/fixture_position.py delete mode 100644 tests/functional/cross_db_utils/fixture_replace.py delete mode 100644 tests/functional/cross_db_utils/fixture_right.py delete mode 100644 tests/functional/cross_db_utils/fixture_safe_cast.py delete mode 100644 tests/functional/cross_db_utils/fixture_split_part.py delete mode 100644 tests/functional/cross_db_utils/fixture_string_literal.py delete mode 100644 tests/functional/cross_db_utils/fixture_type_bigint.py delete mode 100644 tests/functional/cross_db_utils/fixture_type_boolean.py delete mode 100644 tests/functional/cross_db_utils/fixture_type_float.py delete mode 100644 tests/functional/cross_db_utils/fixture_type_int.py delete mode 100644 tests/functional/cross_db_utils/fixture_type_numeric.py delete mode 100644 tests/functional/cross_db_utils/fixture_type_string.py delete mode 100644 tests/functional/cross_db_utils/fixture_type_timestamp.py delete mode 100644 tests/functional/cross_db_utils/test_any_value.py delete mode 100644 tests/functional/cross_db_utils/test_bool_or.py delete mode 100644 tests/functional/cross_db_utils/test_cast_bool_to_text.py delete mode 100644 tests/functional/cross_db_utils/test_concat.py delete mode 100644 tests/functional/cross_db_utils/test_current_timestamp.py delete mode 100644 tests/functional/cross_db_utils/test_current_timestamp_in_utc.py delete mode 100644 tests/functional/cross_db_utils/test_date_trunc.py delete mode 100644 tests/functional/cross_db_utils/test_dateadd.py delete mode 100644 tests/functional/cross_db_utils/test_datediff.py delete mode 100644 tests/functional/cross_db_utils/test_escape_single_quotes.py delete mode 100644 tests/functional/cross_db_utils/test_except.py delete mode 100644 tests/functional/cross_db_utils/test_hash.py delete mode 100644 tests/functional/cross_db_utils/test_intersect.py delete mode 100644 tests/functional/cross_db_utils/test_last_day.py delete mode 100644 tests/functional/cross_db_utils/test_length.py delete mode 100644 tests/functional/cross_db_utils/test_listagg.py delete mode 100644 tests/functional/cross_db_utils/test_position.py delete mode 100644 tests/functional/cross_db_utils/test_replace.py delete mode 100644 tests/functional/cross_db_utils/test_right.py delete mode 100644 tests/functional/cross_db_utils/test_safe_cast.py delete mode 100644 tests/functional/cross_db_utils/test_split_part.py delete mode 100644 tests/functional/cross_db_utils/test_string_literal.py delete mode 100644 tests/functional/cross_db_utils/test_type_bigint.py delete mode 100644 tests/functional/cross_db_utils/test_type_boolean.py delete mode 100644 tests/functional/cross_db_utils/test_type_float.py delete mode 100644 tests/functional/cross_db_utils/test_type_int.py delete mode 100644 tests/functional/cross_db_utils/test_type_numeric.py delete mode 100644 tests/functional/cross_db_utils/test_type_string.py delete mode 100644 tests/functional/cross_db_utils/test_type_timestamp.py create mode 100644 tests/functional/cross_db_utils/test_utils.py diff --git a/dev-requirements.txt b/dev-requirements.txt index 92c07876..44b1767d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,3 +1,8 @@ pytest pytest-dotenv -dbt-tests-adapter +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-postgres&subdirectory=plugins/postgres +git+https://github.com/dbt-labs/dbt-redshift.git +git+https://github.com/dbt-labs/dbt-snowflake.git +git+https://github.com/dbt-labs/dbt-bigquery.git diff --git a/macros/cross_db_utils/any_value.sql b/macros/cross_db_utils/any_value.sql index 78cb75ba..da4fb055 100644 --- a/macros/cross_db_utils/any_value.sql +++ b/macros/cross_db_utils/any_value.sql @@ -1,17 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro any_value(expression) -%} {{ return(adapter.dispatch('any_value', 'dbt_utils') (expression)) }} {% endmacro %} - {% macro default__any_value(expression) -%} - - any_value({{ expression }}) - -{%- endmacro %} - - -{% macro postgres__any_value(expression) -%} - {#- /*Postgres doesn't support any_value, so we're using min() to get the same result*/ -#} - min({{ expression }}) - -{%- endmacro %} \ No newline at end of file + {{ return(adapter.dispatch('any_value', 'dbt') (expression)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/bool_or.sql b/macros/cross_db_utils/bool_or.sql index ce0a6857..03ab4163 100644 --- a/macros/cross_db_utils/bool_or.sql +++ b/macros/cross_db_utils/bool_or.sql @@ -1,24 +1,9 @@ +{# This is here for backwards compatibility only #} + {% 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 + {{ return(adapter.dispatch('bool_or', 'dbt') (expression)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/cast_bool_to_text.sql b/macros/cross_db_utils/cast_bool_to_text.sql index 5efa9d60..0ffe03fd 100644 --- a/macros/cross_db_utils/cast_bool_to_text.sql +++ b/macros/cross_db_utils/cast_bool_to_text.sql @@ -1,15 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro cast_bool_to_text(field) %} {{ adapter.dispatch('cast_bool_to_text', 'dbt_utils') (field) }} {% endmacro %} - {% macro default__cast_bool_to_text(field) %} - cast({{ field }} as {{ dbt_utils.type_string() }}) -{% endmacro %} - -{% macro redshift__cast_bool_to_text(field) %} - case - when {{ field }} is true then 'true' - when {{ field }} is false then 'false' - end::text + {{ adapter.dispatch('cast_bool_to_text', 'dbt') (field) }} {% endmacro %} diff --git a/macros/cross_db_utils/concat.sql b/macros/cross_db_utils/concat.sql index 7e97e8f8..1425936c 100644 --- a/macros/cross_db_utils/concat.sql +++ b/macros/cross_db_utils/concat.sql @@ -1,9 +1,9 @@ - +{# This is here for backwards compatibility only #} {% macro concat(fields) -%} {{ return(adapter.dispatch('concat', 'dbt_utils')(fields)) }} {%- endmacro %} {% macro default__concat(fields) -%} - {{ fields|join(' || ') }} + {{ return(adapter.dispatch('concat', 'dbt')(fields)) }} {%- endmacro %} diff --git a/macros/cross_db_utils/date_trunc.sql b/macros/cross_db_utils/date_trunc.sql index f9d0364b..695bdbde 100644 --- a/macros/cross_db_utils/date_trunc.sql +++ b/macros/cross_db_utils/date_trunc.sql @@ -1,15 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro date_trunc(datepart, date) -%} {{ return(adapter.dispatch('date_trunc', 'dbt_utils') (datepart, date)) }} {%- endmacro %} {% macro default__date_trunc(datepart, date) -%} - date_trunc('{{datepart}}', {{date}}) -{%- endmacro %} - -{% macro bigquery__date_trunc(datepart, date) -%} - timestamp_trunc( - cast({{date}} as timestamp), - {{datepart}} - ) - + {{ return(adapter.dispatch('date_trunc', 'dbt') (datepart, date)) }} {%- endmacro %} diff --git a/macros/cross_db_utils/dateadd.sql b/macros/cross_db_utils/dateadd.sql index 09c0f115..1cf886e2 100644 --- a/macros/cross_db_utils/dateadd.sql +++ b/macros/cross_db_utils/dateadd.sql @@ -1,37 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro dateadd(datepart, interval, from_date_or_timestamp) %} {{ return(adapter.dispatch('dateadd', 'dbt_utils')(datepart, interval, from_date_or_timestamp)) }} {% endmacro %} - {% macro default__dateadd(datepart, interval, from_date_or_timestamp) %} - - dateadd( - {{ datepart }}, - {{ interval }}, - {{ from_date_or_timestamp }} - ) - -{% endmacro %} - - -{% macro bigquery__dateadd(datepart, interval, from_date_or_timestamp) %} - - datetime_add( - cast( {{ from_date_or_timestamp }} as datetime), - interval {{ interval }} {{ datepart }} - ) - -{% endmacro %} - -{% macro postgres__dateadd(datepart, interval, from_date_or_timestamp) %} - - {{ from_date_or_timestamp }} + ((interval '1 {{ datepart }}') * ({{ interval }})) - -{% endmacro %} - -{# redshift should use default instead of postgres #} -{% macro redshift__dateadd(datepart, interval, from_date_or_timestamp) %} - - {{ return(dbt_utils.default__dateadd(datepart, interval, from_date_or_timestamp)) }} - + {{ return(adapter.dispatch('dateadd', 'dbt')(datepart, interval, from_date_or_timestamp)) }} {% endmacro %} diff --git a/macros/cross_db_utils/datediff.sql b/macros/cross_db_utils/datediff.sql index 2b5d6613..c4ba417f 100644 --- a/macros/cross_db_utils/datediff.sql +++ b/macros/cross_db_utils/datediff.sql @@ -1,66 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro datediff(first_date, second_date, datepart) %} {{ return(adapter.dispatch('datediff', 'dbt_utils')(first_date, second_date, datepart)) }} {% endmacro %} - -{% macro default__datediff(first_date, second_date, datepart) -%} - - datediff( - {{ datepart }}, - {{ first_date }}, - {{ second_date }} - ) - -{%- endmacro %} - - -{% macro bigquery__datediff(first_date, second_date, datepart) -%} - - datetime_diff( - cast({{second_date}} as datetime), - cast({{first_date}} as datetime), - {{datepart}} - ) - -{%- endmacro %} - -{% macro postgres__datediff(first_date, second_date, datepart) -%} - - {% if datepart == 'year' %} - (date_part('year', ({{second_date}})::date) - date_part('year', ({{first_date}})::date)) - {% elif datepart == 'quarter' %} - ({{ dbt_utils.datediff(first_date, second_date, 'year') }} * 4 + date_part('quarter', ({{second_date}})::date) - date_part('quarter', ({{first_date}})::date)) - {% elif datepart == 'month' %} - ({{ dbt_utils.datediff(first_date, second_date, 'year') }} * 12 + date_part('month', ({{second_date}})::date) - date_part('month', ({{first_date}})::date)) - {% elif datepart == 'day' %} - (({{second_date}})::date - ({{first_date}})::date) - {% elif datepart == 'week' %} - ({{ dbt_utils.datediff(first_date, second_date, 'day') }} / 7 + case - when date_part('dow', ({{first_date}})::timestamp) <= date_part('dow', ({{second_date}})::timestamp) then - case when {{first_date}} <= {{second_date}} then 0 else -1 end - else - case when {{first_date}} <= {{second_date}} then 1 else 0 end - end) - {% elif datepart == 'hour' %} - ({{ dbt_utils.datediff(first_date, second_date, 'day') }} * 24 + date_part('hour', ({{second_date}})::timestamp) - date_part('hour', ({{first_date}})::timestamp)) - {% elif datepart == 'minute' %} - ({{ dbt_utils.datediff(first_date, second_date, 'hour') }} * 60 + date_part('minute', ({{second_date}})::timestamp) - date_part('minute', ({{first_date}})::timestamp)) - {% elif datepart == 'second' %} - ({{ dbt_utils.datediff(first_date, second_date, 'minute') }} * 60 + floor(date_part('second', ({{second_date}})::timestamp)) - floor(date_part('second', ({{first_date}})::timestamp))) - {% elif datepart == 'millisecond' %} - ({{ dbt_utils.datediff(first_date, second_date, 'minute') }} * 60000 + floor(date_part('millisecond', ({{second_date}})::timestamp)) - floor(date_part('millisecond', ({{first_date}})::timestamp))) - {% elif datepart == 'microsecond' %} - ({{ dbt_utils.datediff(first_date, second_date, 'minute') }} * 60000000 + floor(date_part('microsecond', ({{second_date}})::timestamp)) - floor(date_part('microsecond', ({{first_date}})::timestamp))) - {% else %} - {{ exceptions.raise_compiler_error("Unsupported datepart for macro datediff in postgres: {!r}".format(datepart)) }} - {% endif %} - -{%- endmacro %} - - -{# redshift should use default instead of postgres #} -{% macro redshift__datediff(first_date, second_date, datepart) -%} - - {{ return(dbt_utils.default__datediff(first_date, second_date, datepart)) }} - -{%- endmacro %} +{% macro default__datediff(first_date, second_date, datepart) %} + {{ return(adapter.dispatch('datediff', 'dbt')(first_date, second_date, datepart)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/escape_single_quotes.sql b/macros/cross_db_utils/escape_single_quotes.sql index d024f16f..2461d7da 100644 --- a/macros/cross_db_utils/escape_single_quotes.sql +++ b/macros/cross_db_utils/escape_single_quotes.sql @@ -1,18 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro escape_single_quotes(expression) %} {{ return(adapter.dispatch('escape_single_quotes', 'dbt_utils') (expression)) }} {% endmacro %} -{# /*Default to replacing a single apostrophe with two apostrophes: they're -> they''re*/ #} -{% macro default__escape_single_quotes(expression) -%} -{{ expression | replace("'","''") }} -{%- endmacro %} - -{# /*Snowflake uses a single backslash: they're -> they\'re. The second backslash is to escape it from Jinja */ #} -{% macro snowflake__escape_single_quotes(expression) -%} -{{ expression | replace("'", "\\'") }} -{%- endmacro %} - -{# /*BigQuery uses a single backslash: they're -> they\'re. The second backslash is to escape it from Jinja */ #} -{% macro bigquery__escape_single_quotes(expression) -%} -{{ expression | replace("'", "\\'") }} -{%- endmacro %} +{% macro default__escape_single_quotes(expression) %} + {{ return(adapter.dispatch('escape_single_quotes', 'dbt') (expression)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/except.sql b/macros/cross_db_utils/except.sql index 9bb75b86..2c2f268b 100644 --- a/macros/cross_db_utils/except.sql +++ b/macros/cross_db_utils/except.sql @@ -1,16 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro except() %} {{ return(adapter.dispatch('except', 'dbt_utils')()) }} {% endmacro %} - {% macro default__except() %} - - except - + {{ return(adapter.dispatch('except', 'dbt')()) }} {% endmacro %} - -{% macro bigquery__except() %} - - except distinct - -{% endmacro %} \ No newline at end of file diff --git a/macros/cross_db_utils/hash.sql b/macros/cross_db_utils/hash.sql index d086c2e6..8e3b7566 100644 --- a/macros/cross_db_utils/hash.sql +++ b/macros/cross_db_utils/hash.sql @@ -1,13 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro hash(field) -%} {{ return(adapter.dispatch('hash', 'dbt_utils') (field)) }} {%- endmacro %} - {% macro default__hash(field) -%} - md5(cast({{field}} as {{dbt_utils.type_string()}})) -{%- endmacro %} - - -{% macro bigquery__hash(field) -%} - to_hex({{dbt_utils.default__hash(field)}}) + {{ return(adapter.dispatch('hash', 'dbt') (field)) }} {%- endmacro %} diff --git a/macros/cross_db_utils/intersect.sql b/macros/cross_db_utils/intersect.sql index b53c72f3..b99abc13 100644 --- a/macros/cross_db_utils/intersect.sql +++ b/macros/cross_db_utils/intersect.sql @@ -1,16 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro intersect() %} {{ return(adapter.dispatch('intersect', 'dbt_utils')()) }} {% endmacro %} - {% macro default__intersect() %} - - intersect - -{% endmacro %} - -{% macro bigquery__intersect() %} - - intersect distinct - + {{ return(adapter.dispatch('intersect', 'dbt')()) }} {% endmacro %} diff --git a/macros/cross_db_utils/last_day.sql b/macros/cross_db_utils/last_day.sql index 18ca161c..dc108731 100644 --- a/macros/cross_db_utils/last_day.sql +++ b/macros/cross_db_utils/last_day.sql @@ -1,3 +1,5 @@ +{# This is here for backwards compatibility only #} + /* This function has been tested with dateparts of month and quarters. Further testing is required to validate that it will work on other dateparts. @@ -7,39 +9,6 @@ testing is required to validate that it will work on other dateparts. {{ return(adapter.dispatch('last_day', 'dbt_utils') (date, datepart)) }} {% endmacro %} - -{%- macro default_last_day(date, datepart) -%} - cast( - {{dbt_utils.dateadd('day', '-1', - dbt_utils.dateadd(datepart, '1', dbt_utils.date_trunc(datepart, date)) - )}} - as date) -{%- endmacro -%} - - -{% macro default__last_day(date, datepart) -%} - {{dbt_utils.default_last_day(date, datepart)}} -{%- endmacro %} - - -{% macro postgres__last_day(date, datepart) -%} - - {%- if datepart == 'quarter' -%} - -- postgres dateadd does not support quarter interval. - cast( - {{dbt_utils.dateadd('day', '-1', - dbt_utils.dateadd('month', '3', dbt_utils.date_trunc(datepart, date)) - )}} - as date) - {%- else -%} - {{dbt_utils.default_last_day(date, datepart)}} - {%- endif -%} - -{%- endmacro %} - -{# redshift should use default instead of postgres #} -{% macro redshift__last_day(date, datepart) %} - - {{ return(dbt_utils.default__last_day(date, datepart)) }} - +{% macro default__last_day(date, datepart) %} + {{ return(adapter.dispatch('last_day', 'dbt') (date, datepart)) }} {% endmacro %} diff --git a/macros/cross_db_utils/length.sql b/macros/cross_db_utils/length.sql index 8c2e265c..ce4de567 100644 --- a/macros/cross_db_utils/length.sql +++ b/macros/cross_db_utils/length.sql @@ -1,21 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro length(expression) -%} {{ return(adapter.dispatch('length', 'dbt_utils') (expression)) }} {% endmacro %} - -{% macro default__length(expression) %} - - length( - {{ expression }} - ) - -{%- endmacro -%} - - -{% macro redshift__length(expression) %} - - len( - {{ expression }} - ) - -{%- endmacro -%} \ No newline at end of file +{% macro default__length(expression) -%} + {{ return(adapter.dispatch('length', 'dbt') (expression)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/listagg.sql b/macros/cross_db_utils/listagg.sql index 1d19a54f..7db195ff 100644 --- a/macros/cross_db_utils/listagg.sql +++ b/macros/cross_db_utils/listagg.sql @@ -1,104 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro listagg(measure, delimiter_text="','", order_by_clause=none, limit_num=none) -%} {{ return(adapter.dispatch('listagg', 'dbt_utils') (measure, delimiter_text, order_by_clause, limit_num)) }} {%- endmacro %} -{% macro default__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} - - {% if limit_num -%} - array_to_string( - array_slice( - array_agg( - {{ measure }} - ){% if order_by_clause -%} - within group ({{ order_by_clause }}) - {%- endif %} - ,0 - ,{{ limit_num }} - ), - {{ delimiter_text }} - ) - {%- else %} - listagg( - {{ measure }}, - {{ delimiter_text }} - ) - {% if order_by_clause -%} - within group ({{ order_by_clause }}) - {%- endif %} - {%- endif %} - -{%- endmacro %} - -{% macro bigquery__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} - - string_agg( - {{ measure }}, - {{ delimiter_text }} - {% if order_by_clause -%} - {{ order_by_clause }} - {%- endif %} - {% if limit_num -%} - limit {{ limit_num }} - {%- endif %} - ) - -{%- endmacro %} - -{% macro postgres__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} - - {% if limit_num -%} - array_to_string( - (array_agg( - {{ measure }} - {% if order_by_clause -%} - {{ order_by_clause }} - {%- endif %} - ))[1:{{ limit_num }}], - {{ delimiter_text }} - ) - {%- else %} - string_agg( - {{ measure }}, - {{ delimiter_text }} - {% if order_by_clause -%} - {{ order_by_clause }} - {%- endif %} - ) - {%- endif %} - +{% macro default__listagg(measure, delimiter_text="','", order_by_clause=none, limit_num=none) -%} + {{ return(adapter.dispatch('listagg', 'dbt') (measure, delimiter_text, order_by_clause, limit_num)) }} {%- endmacro %} - -{# if there are instances of delimiter_text within your measure, you cannot include a limit_num #} -{% macro redshift__listagg(measure, delimiter_text, order_by_clause, limit_num) -%} - - {% if limit_num -%} - {% set ns = namespace() %} - {% set ns.delimiter_text_regex = delimiter_text|trim("'") %} - {% set special_chars %}\,^,$,.,|,?,*,+,(,),[,],{,}{% endset %} - {%- for char in special_chars.split(',') -%} - {% set escape_char %}\\{{ char }}{% endset %} - {% set ns.delimiter_text_regex = ns.delimiter_text_regex|replace(char,escape_char) %} - {%- endfor -%} - - {% set regex %}'([^{{ ns.delimiter_text_regex }}]+{{ ns.delimiter_text_regex }}){1,{{ limit_num - 1}}}[^{{ ns.delimiter_text_regex }}]+'{% endset %} - regexp_substr( - listagg( - {{ measure }}, - {{ delimiter_text }} - ) - {% if order_by_clause -%} - within group ({{ order_by_clause }}) - {%- endif %} - ,{{ regex }} - ) - {%- else %} - listagg( - {{ measure }}, - {{ delimiter_text }} - ) - {% if order_by_clause -%} - within group ({{ order_by_clause }}) - {%- endif %} - {%- endif %} - -{%- endmacro %} \ No newline at end of file diff --git a/macros/cross_db_utils/literal.sql b/macros/cross_db_utils/literal.sql index c2291467..de0a6c43 100644 --- a/macros/cross_db_utils/literal.sql +++ b/macros/cross_db_utils/literal.sql @@ -1,8 +1,9 @@ +{# This is here for backwards compatibility only #} {%- macro string_literal(value) -%} {{ return(adapter.dispatch('string_literal', 'dbt_utils') (value)) }} {%- endmacro -%} -{% macro default__string_literal(value) -%} - '{{ value }}' -{%- endmacro %} +{%- macro default__string_literal(value) -%} + {{ return(adapter.dispatch('string_literal', 'dbt') (value)) }} +{%- endmacro -%} diff --git a/macros/cross_db_utils/position.sql b/macros/cross_db_utils/position.sql index a67b7aa2..d819f0d3 100644 --- a/macros/cross_db_utils/position.sql +++ b/macros/cross_db_utils/position.sql @@ -1,22 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro position(substring_text, string_text) -%} {{ return(adapter.dispatch('position', 'dbt_utils') (substring_text, string_text)) }} {% endmacro %} - -{% macro default__position(substring_text, string_text) %} - - position( - {{ substring_text }} in {{ string_text }} - ) - -{%- endmacro -%} - -{% macro bigquery__position(substring_text, string_text) %} - - strpos( - {{ string_text }}, - {{ substring_text }} - - ) - -{%- endmacro -%} +{% macro default__position(substring_text, string_text) -%} + {{ return(adapter.dispatch('position', 'dbt') (substring_text, string_text)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/replace.sql b/macros/cross_db_utils/replace.sql index ef27d8fc..43c6befa 100644 --- a/macros/cross_db_utils/replace.sql +++ b/macros/cross_db_utils/replace.sql @@ -1,15 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro replace(field, old_chars, new_chars) -%} {{ return(adapter.dispatch('replace', 'dbt_utils') (field, old_chars, new_chars)) }} {% endmacro %} - -{% macro default__replace(field, old_chars, new_chars) %} - - replace( - {{ field }}, - {{ old_chars }}, - {{ new_chars }} - ) - - -{% endmacro %} \ No newline at end of file +{% macro default__replace(field, old_chars, new_chars) -%} + {{ return(adapter.dispatch('replace', 'dbt') (field, old_chars, new_chars)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/right.sql b/macros/cross_db_utils/right.sql index 8ae1640f..3488ac56 100644 --- a/macros/cross_db_utils/right.sql +++ b/macros/cross_db_utils/right.sql @@ -1,38 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro right(string_text, length_expression) -%} {{ return(adapter.dispatch('right', 'dbt_utils') (string_text, length_expression)) }} {% endmacro %} -{% macro default__right(string_text, length_expression) %} - - right( - {{ string_text }}, - {{ length_expression }} - ) - -{%- endmacro -%} - -{% macro bigquery__right(string_text, length_expression) %} - - case when {{ length_expression }} = 0 - then '' - else - substr( - {{ string_text }}, - -1 * ({{ length_expression }}) - ) - end - -{%- endmacro -%} - -{% macro snowflake__right(string_text, length_expression) %} - - case when {{ length_expression }} = 0 - then '' - else - right( - {{ string_text }}, - {{ length_expression }} - ) - end - -{%- endmacro -%} \ No newline at end of file +{% macro default__right(string_text, length_expression) -%} + {{ return(adapter.dispatch('right', 'dbt') (string_text, length_expression)) }} +{% endmacro %} diff --git a/macros/cross_db_utils/safe_cast.sql b/macros/cross_db_utils/safe_cast.sql index 8569eecd..10edaa21 100644 --- a/macros/cross_db_utils/safe_cast.sql +++ b/macros/cross_db_utils/safe_cast.sql @@ -1,20 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro safe_cast(field, type) %} {{ return(adapter.dispatch('safe_cast', 'dbt_utils') (field, type)) }} {% endmacro %} - {% macro default__safe_cast(field, type) %} - {# most databases don't support this function yet - so we just need to use cast #} - cast({{field}} as {{type}}) -{% endmacro %} - - -{% macro snowflake__safe_cast(field, type) %} - try_cast({{field}} as {{type}}) -{% endmacro %} - - -{% macro bigquery__safe_cast(field, type) %} - safe_cast({{field}} as {{type}}) + {{ return(adapter.dispatch('safe_cast', 'dbt') (field, type)) }} {% endmacro %} diff --git a/macros/cross_db_utils/split_part.sql b/macros/cross_db_utils/split_part.sql index 2f9daeac..112ba672 100644 --- a/macros/cross_db_utils/split_part.sql +++ b/macros/cross_db_utils/split_part.sql @@ -1,72 +1,9 @@ +{# This is here for backwards compatibility only #} + {% macro split_part(string_text, delimiter_text, part_number) %} {{ return(adapter.dispatch('split_part', 'dbt_utils') (string_text, delimiter_text, part_number)) }} {% endmacro %} - {% macro default__split_part(string_text, delimiter_text, part_number) %} - - split_part( - {{ string_text }}, - {{ delimiter_text }}, - {{ part_number }} - ) - -{% endmacro %} - - -{% macro _split_part_negative(string_text, delimiter_text, part_number) %} - - split_part( - {{ string_text }}, - {{ delimiter_text }}, - length({{ string_text }}) - - length( - replace({{ string_text }}, {{ delimiter_text }}, '') - ) + 2 {{ part_number }} - ) - -{% endmacro %} - - -{% macro postgres__split_part(string_text, delimiter_text, part_number) %} - - {% if part_number >= 0 %} - {{ dbt_utils.default__split_part(string_text, delimiter_text, part_number) }} - {% else %} - {{ dbt_utils._split_part_negative(string_text, delimiter_text, part_number) }} - {% endif %} - -{% endmacro %} - - -{% macro redshift__split_part(string_text, delimiter_text, part_number) %} - - {% if part_number >= 0 %} - {{ dbt_utils.default__split_part(string_text, delimiter_text, part_number) }} - {% else %} - {{ dbt_utils._split_part_negative(string_text, delimiter_text, part_number) }} - {% endif %} - -{% endmacro %} - - -{% macro bigquery__split_part(string_text, delimiter_text, part_number) %} - - {% if part_number >= 0 %} - split( - {{ string_text }}, - {{ delimiter_text }} - )[safe_offset({{ part_number - 1 }})] - {% else %} - split( - {{ string_text }}, - {{ delimiter_text }} - )[safe_offset( - length({{ string_text }}) - - length( - replace({{ string_text }}, {{ delimiter_text }}, '') - ) + 1 - )] - {% endif %} - + {{ return(adapter.dispatch('split_part', 'dbt') (string_text, delimiter_text, part_number)) }} {% endmacro %} diff --git a/tests/functional/cross_db_utils/fixture_any_value.py b/tests/functional/cross_db_utils/fixture_any_value.py deleted file mode 100644 index 81ac11d5..00000000 --- a/tests/functional/cross_db_utils/fixture_any_value.py +++ /dev/null @@ -1,61 +0,0 @@ - -# any_value - -seeds__data_any_value_csv = """id,key_name,static_col -1,abc,dbt -2,abc,dbt -3,jkl,dbt -4,jkl,dbt -5,jkl,dbt -6,xyz,test -""" - - -seeds__data_any_value_expected_csv = """key_name,static_col,num_rows -abc,dbt,2 -jkl,dbt,3 -xyz,test,1 -""" - - -models__test_any_value_sql = """ -with data as ( - - select * from {{ ref('data_any_value') }} - -), - -data_output as ( - - select * from {{ ref('data_any_value_expected') }} - -), - -calculate as ( - select - key_name, - {{ dbt_utils.any_value('static_col') }} as static_col, - count(id) as num_rows - from data - group by key_name -) - -select - calculate.num_rows as actual, - data_output.num_rows as expected -from calculate -left join data_output -on calculate.key_name = data_output.key_name -and calculate.static_col = data_output.static_col -""" - - -models__test_any_value_yml = """ -version: 2 -models: - - name: test_any_value - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_bool_or.py b/tests/functional/cross_db_utils/fixture_bool_or.py deleted file mode 100644 index ca76a54a..00000000 --- a/tests/functional/cross_db_utils/fixture_bool_or.py +++ /dev/null @@ -1,63 +0,0 @@ - -# bool_or - -seeds__data_bool_or_csv = """key,val1,val2 -abc,1,1 -abc,1,0 -def,1,0 -hij,1,1 -hij,1, -klm,1,0 -klm,1, -""" - - -seeds__data_bool_or_expected_csv = """key,value -abc,true -def,false -hij,true -klm,false -""" - - -models__test_bool_or_sql = """ -with data as ( - - select * from {{ ref('data_bool_or') }} - -), - -data_output as ( - - select * from {{ ref('data_bool_or_expected') }} - -), - -calculate as ( - - select - key, - {{ dbt_utils.bool_or('val1 = val2') }} as value - from data - group by key - -) - -select - calculate.value as actual, - data_output.value as expected -from calculate -left join data_output -on calculate.key = data_output.key -""" - - -models__test_bool_or_yml = """ -version: 2 -models: - - name: test_bool_or - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_cast_bool_to_text.py b/tests/functional/cross_db_utils/fixture_cast_bool_to_text.py deleted file mode 100644 index acdf13e0..00000000 --- a/tests/functional/cross_db_utils/fixture_cast_bool_to_text.py +++ /dev/null @@ -1,30 +0,0 @@ - -# cast_bool_to_text - -models__test_cast_bool_to_text_sql = """ -with data as ( - - select 0=1 as input, 'false' as expected union all - select 1=1 as input, 'true' as expected union all - select null as input, null as expected - -) - -select - - {{ dbt_utils.cast_bool_to_text("input") }} as actual, - expected - -from data -""" - - -models__test_cast_bool_to_text_yml = """ -version: 2 -models: - - name: test_cast_bool_to_text - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_concat.py b/tests/functional/cross_db_utils/fixture_concat.py deleted file mode 100644 index 778d8bd3..00000000 --- a/tests/functional/cross_db_utils/fixture_concat.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# concat - -seeds__data_concat_csv = """input_1,input_2,output -a,b,ab -a,,a -,b,b -,, -""" - - -models__test_concat_sql = """ -with data as ( - - select * from {{ ref('data_concat') }} - -) - -select - {{ dbt_utils.concat(['input_1', 'input_2']) }} as actual, - output as expected - -from data -""" - - -models__test_concat_yml = """ -version: 2 -models: - - name: test_concat - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_current_timestamp.py b/tests/functional/cross_db_utils/fixture_current_timestamp.py deleted file mode 100644 index dcd38aa2..00000000 --- a/tests/functional/cross_db_utils/fixture_current_timestamp.py +++ /dev/null @@ -1,20 +0,0 @@ - -# current_timestamp - -# TODO how can we test this better? -models__test_current_timestamp_sql = """ -select - {{ dbt_utils.current_timestamp() }} as actual, - {{ dbt_utils.current_timestamp() }} as expected -""" - - -models__test_current_timestamp_yml = """ -version: 2 -models: - - name: test_current_timestamp - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_current_timestamp_in_utc.py b/tests/functional/cross_db_utils/fixture_current_timestamp_in_utc.py deleted file mode 100644 index 61caef35..00000000 --- a/tests/functional/cross_db_utils/fixture_current_timestamp_in_utc.py +++ /dev/null @@ -1,20 +0,0 @@ - -# current_timestamp_in_utc - -# TODO how can we test this better? -models__test_current_timestamp_in_utc_sql = """ -select - {{ dbt_utils.current_timestamp_in_utc() }} as actual, - {{ dbt_utils.current_timestamp_in_utc() }} as expected -""" - - -models__test_current_timestamp_in_utc_yml = """ -version: 2 -models: - - name: test_current_timestamp_in_utc - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_date_trunc.py b/tests/functional/cross_db_utils/fixture_date_trunc.py deleted file mode 100644 index 91eb5c23..00000000 --- a/tests/functional/cross_db_utils/fixture_date_trunc.py +++ /dev/null @@ -1,41 +0,0 @@ - -# date_trunc - -seeds__data_date_trunc_csv = """updated_at,day,month -2018-01-05 12:00:00,2018-01-05,2018-01-01 -,, -""" - - -models__test_date_trunc_sql = """ -with data as ( - - select * from {{ ref('data_date_trunc') }} - -) - -select - cast({{dbt_utils.date_trunc('day', 'updated_at') }} as date) as actual, - day as expected - -from data - -union all - -select - cast({{ dbt_utils.date_trunc('month', 'updated_at') }} as date) as actual, - month as expected - -from data -""" - - -models__test_date_trunc_yml = """ -version: 2 -models: - - name: test_date_trunc - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_dateadd.py b/tests/functional/cross_db_utils/fixture_dateadd.py deleted file mode 100644 index 95d8cce5..00000000 --- a/tests/functional/cross_db_utils/fixture_dateadd.py +++ /dev/null @@ -1,41 +0,0 @@ - -# dateadd - -seeds__data_dateadd_csv = """from_time,interval_length,datepart,result -2018-01-01 01:00:00,1,day,2018-01-02 01:00:00 -2018-01-01 01:00:00,1,month,2018-02-01 01:00:00 -2018-01-01 01:00:00,1,year,2019-01-01 01:00:00 -2018-01-01 01:00:00,1,hour,2018-01-01 02:00:00 -,1,day, -""" - - -models__test_dateadd_sql = """ -with data as ( - - select * from {{ ref('data_dateadd') }} - -) - -select - case - when datepart = 'hour' then cast({{ dbt_utils.dateadd('hour', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}}) - when datepart = 'day' then cast({{ dbt_utils.dateadd('day', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}}) - when datepart = 'month' then cast({{ dbt_utils.dateadd('month', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}}) - when datepart = 'year' then cast({{ dbt_utils.dateadd('year', 'interval_length', 'from_time') }} as {{dbt_utils.type_timestamp()}}) - else null - end as actual, - result as expected - -from data -""" - -models__test_dateadd_yml = """ -version: 2 -models: - - name: test_dateadd - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_datediff.py b/tests/functional/cross_db_utils/fixture_datediff.py deleted file mode 100644 index 0ac216a6..00000000 --- a/tests/functional/cross_db_utils/fixture_datediff.py +++ /dev/null @@ -1,66 +0,0 @@ - -# datediff - -seeds__data_datediff_csv = """first_date,second_date,datepart,result -2018-01-01 01:00:00,2018-01-02 01:00:00,day,1 -2018-01-01 01:00:00,2018-02-01 01:00:00,month,1 -2018-01-01 01:00:00,2019-01-01 01:00:00,year,1 -2018-01-01 01:00:00,2018-01-01 02:00:00,hour,1 -2018-01-01 01:00:00,2018-01-01 02:01:00,minute,61 -2018-01-01 01:00:00,2018-01-01 02:00:01,second,3601 -2019-12-31 00:00:00,2019-12-27 00:00:00,week,-1 -2019-12-31 00:00:00,2019-12-30 00:00:00,week,0 -2019-12-31 00:00:00,2020-01-02 00:00:00,week,0 -2019-12-31 00:00:00,2020-01-06 02:00:00,week,1 -,2018-01-01 02:00:00,hour, -2018-01-01 02:00:00,,hour, -""" - - -models__test_datediff_sql = """ -with data as ( - - select * from {{ ref('data_datediff') }} - -) - -select - - case - when datepart = 'second' then {{ dbt_utils.datediff('first_date', 'second_date', 'second') }} - when datepart = 'minute' then {{ dbt_utils.datediff('first_date', 'second_date', 'minute') }} - when datepart = 'hour' then {{ dbt_utils.datediff('first_date', 'second_date', 'hour') }} - when datepart = 'day' then {{ dbt_utils.datediff('first_date', 'second_date', 'day') }} - when datepart = 'week' then {{ dbt_utils.datediff('first_date', 'second_date', 'week') }} - when datepart = 'month' then {{ dbt_utils.datediff('first_date', 'second_date', 'month') }} - when datepart = 'year' then {{ dbt_utils.datediff('first_date', 'second_date', 'year') }} - else null - end as actual, - result as expected - -from data - --- Also test correct casting of literal values. - -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "microsecond") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "millisecond") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "second") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "minute") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "hour") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "day") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-03 00:00:00.000000'", "week") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "month") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "quarter") }} as actual, 1 as expected -union all select {{ dbt_utils.datediff("'1999-12-31 23:59:59.999999'", "'2000-01-01 00:00:00.000000'", "year") }} as actual, 1 as expected -""" - - -models__test_datediff_yml = """ -version: 2 -models: - - name: test_datediff - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_escape_single_quotes.py b/tests/functional/cross_db_utils/fixture_escape_single_quotes.py deleted file mode 100644 index 3264d056..00000000 --- a/tests/functional/cross_db_utils/fixture_escape_single_quotes.py +++ /dev/null @@ -1,25 +0,0 @@ - -# escape_single_quotes - -models__test_escape_single_quotes_quote_sql = """ -select '{{ dbt_utils.escape_single_quotes("they're") }}' as actual, 'they''re' as expected union all -select '{{ dbt_utils.escape_single_quotes("they are") }}' as actual, 'they are' as expected -""" - - -# The expected literal is 'they\'re'. The second backslash is to escape it from Python. -models__test_escape_single_quotes_backslash_sql = """ -select '{{ dbt_utils.escape_single_quotes("they're") }}' as actual, 'they\\'re' as expected union all -select '{{ dbt_utils.escape_single_quotes("they are") }}' as actual, 'they are' as expected -""" - - -models__test_escape_single_quotes_yml = """ -version: 2 -models: - - name: test_escape_single_quotes - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_except.py b/tests/functional/cross_db_utils/fixture_except.py deleted file mode 100644 index 013b7943..00000000 --- a/tests/functional/cross_db_utils/fixture_except.py +++ /dev/null @@ -1,65 +0,0 @@ - -# except - -seeds__data_except_a_csv = """id -1 -2 -3 -""" - -seeds__data_except_b_csv = """id -3 -4 -5 -""" - -seeds__data_except_a_minus_b_csv = """id -1 -2 -""" - -seeds__data_except_b_minus_a_csv = """id -4 -5 -""" - -models__data_except_empty_sql = """ -select * from {{ ref('data_except_a') }} -where 0=1 -""" - -models__test_except_a_minus_b_sql = """ -select * from {{ ref('data_except_a') }} -{{ dbt_utils.except() }} -select * from {{ ref('data_except_b') }} -""" - -models__test_except_b_minus_a_sql = """ -select * from {{ ref('data_except_b') }} -{{ dbt_utils.except() }} -select * from {{ ref('data_except_a') }} -""" - -models__test_except_a_minus_a_sql = """ -select * from {{ ref('data_except_a') }} -{{ dbt_utils.except() }} -select * from {{ ref('data_except_a') }} -""" - -models__test_except_a_minus_empty_sql = """ -select * from {{ ref('data_except_a') }} -{{ dbt_utils.except() }} -select * from {{ ref('data_except_empty') }} -""" - -models__test_except_empty_minus_a_sql = """ -select * from {{ ref('data_except_empty') }} -{{ dbt_utils.except() }} -select * from {{ ref('data_except_a') }} -""" - -models__test_except_empty_minus_empty_sql = """ -select * from {{ ref('data_except_empty') }} -{{ dbt_utils.except() }} -select * from {{ ref('data_except_empty') }} -""" diff --git a/tests/functional/cross_db_utils/fixture_hash.py b/tests/functional/cross_db_utils/fixture_hash.py deleted file mode 100644 index 1f0b5543..00000000 --- a/tests/functional/cross_db_utils/fixture_hash.py +++ /dev/null @@ -1,35 +0,0 @@ - -# hash - -seeds__data_hash_csv = """input_1,output -ab,187ef4436122d1cc2f40dc2b92f0eba0 -a,0cc175b9c0f1b6a831c399e269772661 -1,c4ca4238a0b923820dcc509a6f75849b -,d41d8cd98f00b204e9800998ecf8427e -""" - - -models__test_hash_sql = """ -with data as ( - - select * from {{ ref('data_hash') }} - -) - -select - {{ dbt_utils.hash('input_1') }} as actual, - output as expected - -from data -""" - - -models__test_hash_yml = """ -version: 2 -models: - - name: test_hash - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_intersect.py b/tests/functional/cross_db_utils/fixture_intersect.py deleted file mode 100644 index 934d93af..00000000 --- a/tests/functional/cross_db_utils/fixture_intersect.py +++ /dev/null @@ -1,59 +0,0 @@ - -# intersect - -seeds__data_intersect_a_csv = """id -1 -2 -3 -""" - -seeds__data_intersect_b_csv = """id -3 -4 -5 -""" - -seeds__data_intersect_a_overlap_b_csv = """id -3 -""" - -models__data_intersect_empty_sql = """ -select * from {{ ref('data_intersect_a') }} -where 0=1 -""" - -models__test_intersect_a_overlap_b_sql = """ -select * from {{ ref('data_intersect_a') }} -{{ dbt_utils.intersect() }} -select * from {{ ref('data_intersect_b') }} -""" - -models__test_intersect_b_overlap_a_sql = """ -select * from {{ ref('data_intersect_b') }} -{{ dbt_utils.intersect() }} -select * from {{ ref('data_intersect_a') }} -""" - -models__test_intersect_a_overlap_a_sql = """ -select * from {{ ref('data_intersect_a') }} -{{ dbt_utils.intersect() }} -select * from {{ ref('data_intersect_a') }} -""" - -models__test_intersect_a_overlap_empty_sql = """ -select * from {{ ref('data_intersect_a') }} -{{ dbt_utils.intersect() }} -select * from {{ ref('data_intersect_empty') }} -""" - -models__test_intersect_empty_overlap_a_sql = """ -select * from {{ ref('data_intersect_empty') }} -{{ dbt_utils.intersect() }} -select * from {{ ref('data_intersect_a') }} -""" - -models__test_intersect_empty_overlap_empty_sql = """ -select * from {{ ref('data_intersect_empty') }} -{{ dbt_utils.intersect() }} -select * from {{ ref('data_intersect_empty') }} -""" diff --git a/tests/functional/cross_db_utils/fixture_last_day.py b/tests/functional/cross_db_utils/fixture_last_day.py deleted file mode 100644 index 72fbd352..00000000 --- a/tests/functional/cross_db_utils/fixture_last_day.py +++ /dev/null @@ -1,40 +0,0 @@ - -# last_day - -seeds__data_last_day_csv = """date_day,date_part,result -2018-01-02,month,2018-01-31 -2018-01-02,quarter,2018-03-31 -2018-01-02,year,2018-12-31 -,month, -""" - - -models__test_last_day_sql = """ -with data as ( - - select * from {{ ref('data_last_day') }} - -) - -select - case - when date_part = 'month' then {{ dbt_utils.last_day('date_day', 'month') }} - when date_part = 'quarter' then {{ dbt_utils.last_day('date_day', 'quarter') }} - when date_part = 'year' then {{ dbt_utils.last_day('date_day', 'year') }} - else null - end as actual, - result as expected - -from data -""" - - -models__test_last_day_yml = """ -version: 2 -models: - - name: test_last_day - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_length.py b/tests/functional/cross_db_utils/fixture_length.py deleted file mode 100644 index e6264741..00000000 --- a/tests/functional/cross_db_utils/fixture_length.py +++ /dev/null @@ -1,36 +0,0 @@ - -# length - -seeds__data_length_csv = """expression,output -abcdef,6 -fishtown,8 -december,8 -www.google.com/path,19 -""" - - -models__test_length_sql = """ -with data as ( - - select * from {{ ref('data_length') }} - -) - -select - - {{ dbt_utils.length('expression') }} as actual, - output as expected - -from data -""" - - -models__test_length_yml = """ -version: 2 -models: - - name: test_length - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_listagg.py b/tests/functional/cross_db_utils/fixture_listagg.py deleted file mode 100644 index 9a2380d6..00000000 --- a/tests/functional/cross_db_utils/fixture_listagg.py +++ /dev/null @@ -1,111 +0,0 @@ - -# listagg - -seeds__data_listagg_csv = """group_col,string_text,order_col -1,a,1 -1,b,2 -1,c,3 -2,a,2 -2,1,1 -2,p,3 -3,g,1 -3,g,2 -3,g,3 -""" - - -seeds__data_listagg_output_csv = """group_col,expected,version -1,"a_|_b_|_c",bottom_ordered -2,"1_|_a_|_p",bottom_ordered -3,"g_|_g_|_g",bottom_ordered -1,"a_|_b",bottom_ordered_limited -2,"1_|_a",bottom_ordered_limited -3,"g_|_g",bottom_ordered_limited -3,"g, g, g",comma_whitespace_unordered -3,"g",distinct_comma -3,"g,g,g",no_params -""" - - -models__test_listagg_sql = """ -with data as ( - - select * from {{ ref('data_listagg') }} - -), - -data_output as ( - - select * from {{ ref('data_listagg_output') }} - -), - -calculate as ( - - select - group_col, - {{ dbt_utils.listagg('string_text', "'_|_'", "order by order_col") }} as actual, - 'bottom_ordered' as version - from data - group by group_col - - union all - - select - group_col, - {{ dbt_utils.listagg('string_text', "'_|_'", "order by order_col", 2) }} as actual, - 'bottom_ordered_limited' as version - from data - group by group_col - - union all - - select - group_col, - {{ dbt_utils.listagg('string_text', "', '") }} as actual, - 'comma_whitespace_unordered' as version - from data - where group_col = 3 - group by group_col - - union all - - select - group_col, - {{ dbt_utils.listagg('DISTINCT string_text', "','") }} as actual, - 'distinct_comma' as version - from data - where group_col = 3 - group by group_col - - union all - - select - group_col, - {{ dbt_utils.listagg('string_text') }} as actual, - 'no_params' as version - from data - where group_col = 3 - group by group_col - -) - -select - calculate.actual, - data_output.expected -from calculate -left join data_output -on calculate.group_col = data_output.group_col -and calculate.version = data_output.version -""" - - -models__test_listagg_yml = """ -version: 2 -models: - - name: test_listagg - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_position.py b/tests/functional/cross_db_utils/fixture_position.py deleted file mode 100644 index 9f66c6a7..00000000 --- a/tests/functional/cross_db_utils/fixture_position.py +++ /dev/null @@ -1,36 +0,0 @@ - -# position - -seeds__data_position_csv = """substring_text,string_text,result -def,abcdef,4 -land,earth,0 -town,fishtown,5 -ember,december,4 -""" - - -models__test_position_sql = """ -with data as ( - - select * from {{ ref('data_position') }} - -) - -select - - {{ dbt_utils.position('substring_text', 'string_text') }} as actual, - result as expected - -from data -""" - - -models__test_position_yml = """ -version: 2 -models: - - name: test_position - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_replace.py b/tests/functional/cross_db_utils/fixture_replace.py deleted file mode 100644 index c9565016..00000000 --- a/tests/functional/cross_db_utils/fixture_replace.py +++ /dev/null @@ -1,40 +0,0 @@ - -# replace - -seeds__data_replace_csv = """string_text,search_chars,replace_chars,result -a,a,b,b -http://google.com,http://,"",google.com -""" - - -models__test_replace_sql = """ -with data as ( - - select - - *, - coalesce(search_chars, '') as old_chars, - coalesce(replace_chars, '') as new_chars - - from {{ ref('data_replace') }} - -) - -select - - {{ dbt_utils.replace('string_text', 'old_chars', 'new_chars') }} as actual, - result as expected - -from data -""" - - -models__test_replace_yml = """ -version: 2 -models: - - name: test_replace - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_right.py b/tests/functional/cross_db_utils/fixture_right.py deleted file mode 100644 index face6ca0..00000000 --- a/tests/functional/cross_db_utils/fixture_right.py +++ /dev/null @@ -1,36 +0,0 @@ - -# right - -seeds__data_right_csv = """string_text,length_expression,output -abcdef,3,def -fishtown,4,town -december,5,ember -december,0, -""" - - -models__test_right_sql = """ -with data as ( - - select * from {{ ref('data_right') }} - -) - -select - - {{ dbt_utils.right('string_text', 'length_expression') }} as actual, - coalesce(output, '') as expected - -from data -""" - - -models__test_right_yml = """ -version: 2 -models: - - name: test_right - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_safe_cast.py b/tests/functional/cross_db_utils/fixture_safe_cast.py deleted file mode 100644 index 918d3bb7..00000000 --- a/tests/functional/cross_db_utils/fixture_safe_cast.py +++ /dev/null @@ -1,34 +0,0 @@ - -# safe_cast - -seeds__data_safe_cast_csv = """field,output -abc,abc -123,123 -, -""" - - -models__test_safe_cast_sql = """ -with data as ( - - select * from {{ ref('data_safe_cast') }} - -) - -select - {{ dbt_utils.safe_cast('field', dbt_utils.type_string()) }} as actual, - output as expected - -from data -""" - - -models__test_safe_cast_yml = """ -version: 2 -models: - - name: test_safe_cast - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_split_part.py b/tests/functional/cross_db_utils/fixture_split_part.py deleted file mode 100644 index ba65a2ab..00000000 --- a/tests/functional/cross_db_utils/fixture_split_part.py +++ /dev/null @@ -1,50 +0,0 @@ - -# split_part - -seeds__data_split_part_csv = """parts,split_on,result_1,result_2,result_3 -a|b|c,|,a,b,c -1|2|3,|,1,2,3 -,|,,, -""" - - -models__test_split_part_sql = """ -with data as ( - - select * from {{ ref('data_split_part') }} - -) - -select - {{ dbt_utils.split_part('parts', 'split_on', 1) }} as actual, - result_1 as expected - -from data - -union all - -select - {{ dbt_utils.split_part('parts', 'split_on', 2) }} as actual, - result_2 as expected - -from data - -union all - -select - {{ dbt_utils.split_part('parts', 'split_on', 3) }} as actual, - result_3 as expected - -from data -""" - - -models__test_split_part_yml = """ -version: 2 -models: - - name: test_split_part - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_string_literal.py b/tests/functional/cross_db_utils/fixture_string_literal.py deleted file mode 100644 index 188208a4..00000000 --- a/tests/functional/cross_db_utils/fixture_string_literal.py +++ /dev/null @@ -1,20 +0,0 @@ - -# string_literal - -models__test_string_literal_sql = """ -select {{ dbt_utils.string_literal("abc") }} as actual, 'abc' as expected union all -select {{ dbt_utils.string_literal("1") }} as actual, '1' as expected union all -select {{ dbt_utils.string_literal("") }} as actual, '' as expected union all -select {{ dbt_utils.string_literal(none) }} as actual, 'None' as expected -""" - - -models__test_string_literal_yml = """ -version: 2 -models: - - name: test_string_literal - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_type_bigint.py b/tests/functional/cross_db_utils/fixture_type_bigint.py deleted file mode 100644 index c1f3ba9f..00000000 --- a/tests/functional/cross_db_utils/fixture_type_bigint.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# type_bigint - -# TODO - implement expected results here -seeds__data_type_bigint_csv = """todo,result -TODO,1 -""" - - -models__test_type_bigint_sql = """ -with data as ( - - select * from {{ ref('data_type_bigint') }} - -) - --- TODO - implement actual logic here -select - - 1 as actual, - 1 as expected - -from data -""" - - -models__test_type_bigint_yml = """ -version: 2 -models: - - name: test_type_bigint - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_type_boolean.py b/tests/functional/cross_db_utils/fixture_type_boolean.py deleted file mode 100644 index fbde496b..00000000 --- a/tests/functional/cross_db_utils/fixture_type_boolean.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# type_boolean - -# TODO - implement expected results here -seeds__data_type_boolean_csv = """todo,result -TODO,1 -""" - - -models__test_type_boolean_sql = """ -with data as ( - - select * from {{ ref('data_type_boolean') }} - -) - --- TODO - implement actual logic here -select - - 1 as actual, - 1 as expected - -from data -""" - - -models__test_type_boolean_yml = """ -version: 2 -models: - - name: test_type_boolean - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_type_float.py b/tests/functional/cross_db_utils/fixture_type_float.py deleted file mode 100644 index 9333f637..00000000 --- a/tests/functional/cross_db_utils/fixture_type_float.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# type_float - -# TODO - implement expected results here -seeds__data_type_float_csv = """todo,result -TODO,1 -""" - - -models__test_type_float_sql = """ -with data as ( - - select * from {{ ref('data_type_float') }} - -) - --- TODO - implement actual logic here -select - - 1 as actual, - 1 as expected - -from data -""" - - -models__test_type_float_yml = """ -version: 2 -models: - - name: test_type_float - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_type_int.py b/tests/functional/cross_db_utils/fixture_type_int.py deleted file mode 100644 index 982a401e..00000000 --- a/tests/functional/cross_db_utils/fixture_type_int.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# type_int - -# TODO - implement expected results here -seeds__data_type_int_csv = """todo,result -TODO,1 -""" - - -models__test_type_int_sql = """ -with data as ( - - select * from {{ ref('data_type_int') }} - -) - --- TODO - implement actual logic here -select - - 1 as actual, - 1 as expected - -from data -""" - - -models__test_type_int_yml = """ -version: 2 -models: - - name: test_type_int - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_type_numeric.py b/tests/functional/cross_db_utils/fixture_type_numeric.py deleted file mode 100644 index a4929cbd..00000000 --- a/tests/functional/cross_db_utils/fixture_type_numeric.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# type_numeric - -# TODO - implement expected results here -seeds__data_type_numeric_csv = """todo,result -TODO,1 -""" - - -models__test_type_numeric_sql = """ -with data as ( - - select * from {{ ref('data_type_numeric') }} - -) - --- TODO - implement actual logic here -select - - 1 as actual, - 1 as expected - -from data -""" - - -models__test_type_numeric_yml = """ -version: 2 -models: - - name: test_type_numeric - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_type_string.py b/tests/functional/cross_db_utils/fixture_type_string.py deleted file mode 100644 index 38a00016..00000000 --- a/tests/functional/cross_db_utils/fixture_type_string.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# type_string - -# TODO - implement expected results here -seeds__data_type_string_csv = """todo,result -TODO,1 -""" - - -models__test_type_string_sql = """ -with data as ( - - select * from {{ ref('data_type_string') }} - -) - --- TODO - implement actual logic here -select - - 1 as actual, - 1 as expected - -from data -""" - - -models__test_type_string_yml = """ -version: 2 -models: - - name: test_type_string - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/fixture_type_timestamp.py b/tests/functional/cross_db_utils/fixture_type_timestamp.py deleted file mode 100644 index 3b28adc8..00000000 --- a/tests/functional/cross_db_utils/fixture_type_timestamp.py +++ /dev/null @@ -1,36 +0,0 @@ - - -# type_timestamp - -# TODO - implement expected results here -seeds__data_type_timestamp_csv = """todo,result -TODO,1 -""" - - -models__test_type_timestamp_sql = """ -with data as ( - - select * from {{ ref('data_type_timestamp') }} - -) - --- TODO - implement actual logic here -select - - 1 as actual, - 1 as expected - -from data -""" - - -models__test_type_timestamp_yml = """ -version: 2 -models: - - name: test_type_timestamp - tests: - - assert_equal: - actual: actual - expected: expected -""" diff --git a/tests/functional/cross_db_utils/test_any_value.py b/tests/functional/cross_db_utils/test_any_value.py deleted file mode 100644 index f0a3acd6..00000000 --- a/tests/functional/cross_db_utils/test_any_value.py +++ /dev/null @@ -1,28 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_any_value import ( - seeds__data_any_value_csv, - seeds__data_any_value_expected_csv, - models__test_any_value_sql, - models__test_any_value_yml, -) - - -class BaseAnyValue(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return { - "data_any_value.csv": seeds__data_any_value_csv, - "data_any_value_expected.csv": seeds__data_any_value_expected_csv, - } - - @pytest.fixture(scope="class") - def models(self): - return { - "test_any_value.yml": models__test_any_value_yml, - "test_any_value.sql": models__test_any_value_sql, - } - - -class TestAnyValue(BaseAnyValue): - pass diff --git a/tests/functional/cross_db_utils/test_bool_or.py b/tests/functional/cross_db_utils/test_bool_or.py deleted file mode 100644 index c8c7a569..00000000 --- a/tests/functional/cross_db_utils/test_bool_or.py +++ /dev/null @@ -1,28 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_bool_or import ( - seeds__data_bool_or_csv, - seeds__data_bool_or_expected_csv, - models__test_bool_or_sql, - models__test_bool_or_yml, -) - - -class BaseBoolOr(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return { - "data_bool_or.csv": seeds__data_bool_or_csv, - "data_bool_or_expected.csv": seeds__data_bool_or_expected_csv - } - - @pytest.fixture(scope="class") - def models(self): - return { - "test_bool_or.yml": models__test_bool_or_yml, - "test_bool_or.sql": models__test_bool_or_sql, - } - - -class TestBoolOr(BaseBoolOr): - pass diff --git a/tests/functional/cross_db_utils/test_cast_bool_to_text.py b/tests/functional/cross_db_utils/test_cast_bool_to_text.py deleted file mode 100644 index 0670cc2a..00000000 --- a/tests/functional/cross_db_utils/test_cast_bool_to_text.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_cast_bool_to_text import ( - models__test_cast_bool_to_text_sql, - models__test_cast_bool_to_text_yml, -) - - -class BaseCastBoolToText(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def models(self): - return { - "test_cast_bool_to_text.yml": models__test_cast_bool_to_text_yml, - "test_cast_bool_to_text.sql": models__test_cast_bool_to_text_sql, - } - - -class TestCastBoolToText(BaseCastBoolToText): - pass diff --git a/tests/functional/cross_db_utils/test_concat.py b/tests/functional/cross_db_utils/test_concat.py deleted file mode 100644 index 1cee2f23..00000000 --- a/tests/functional/cross_db_utils/test_concat.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_concat import ( - seeds__data_concat_csv, - models__test_concat_sql, - models__test_concat_yml, -) - - -class BaseConcat(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_concat.csv": seeds__data_concat_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_concat.yml": models__test_concat_yml, - "test_concat.sql": models__test_concat_sql, - } - - -class TestConcat(BaseConcat): - pass diff --git a/tests/functional/cross_db_utils/test_current_timestamp.py b/tests/functional/cross_db_utils/test_current_timestamp.py deleted file mode 100644 index ba1a52d5..00000000 --- a/tests/functional/cross_db_utils/test_current_timestamp.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_current_timestamp import ( - models__test_current_timestamp_sql, - models__test_current_timestamp_yml, -) - - -class BaseCurrentTimestamp(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def models(self): - return { - "test_current_timestamp.yml": models__test_current_timestamp_yml, - "test_current_timestamp.sql": models__test_current_timestamp_sql, - } - - -class TestCurrentTimestamp(BaseCurrentTimestamp): - pass diff --git a/tests/functional/cross_db_utils/test_current_timestamp_in_utc.py b/tests/functional/cross_db_utils/test_current_timestamp_in_utc.py deleted file mode 100644 index adcedc22..00000000 --- a/tests/functional/cross_db_utils/test_current_timestamp_in_utc.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_current_timestamp_in_utc import ( - models__test_current_timestamp_in_utc_sql, - models__test_current_timestamp_in_utc_yml, -) - - -class BaseCurrentTimestampInUtc(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def models(self): - return { - "test_current_timestamp_in_utc.yml": models__test_current_timestamp_in_utc_yml, - "test_current_timestamp_in_utc.sql": models__test_current_timestamp_in_utc_sql, - } - - -class TestCurrentTimestampInUtc(BaseCurrentTimestampInUtc): - pass diff --git a/tests/functional/cross_db_utils/test_date_trunc.py b/tests/functional/cross_db_utils/test_date_trunc.py deleted file mode 100644 index 6722c2cf..00000000 --- a/tests/functional/cross_db_utils/test_date_trunc.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_date_trunc import ( - seeds__data_date_trunc_csv, - models__test_date_trunc_sql, - models__test_date_trunc_yml, -) - - -class BaseDateTrunc(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_date_trunc.csv": seeds__data_date_trunc_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_date_trunc.yml": models__test_date_trunc_yml, - "test_date_trunc.sql": models__test_date_trunc_sql, - } - - -class TestDateTrunc(BaseDateTrunc): - pass diff --git a/tests/functional/cross_db_utils/test_dateadd.py b/tests/functional/cross_db_utils/test_dateadd.py deleted file mode 100644 index ef9e7910..00000000 --- a/tests/functional/cross_db_utils/test_dateadd.py +++ /dev/null @@ -1,40 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_dateadd import ( - seeds__data_dateadd_csv, - models__test_dateadd_sql, - models__test_dateadd_yml, -) - - -class BaseDateAdd(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "name": "test", - "seeds": { - "test": { - "data_dateadd": { - "+column_types": { - "from_time": "timestamp", - "result": "timestamp", - }, - }, - }, - }, - } - - @pytest.fixture(scope="class") - def seeds(self): - return {"data_dateadd.csv": seeds__data_dateadd_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_dateadd.yml": models__test_dateadd_yml, - "test_dateadd.sql": models__test_dateadd_sql, - } - - -class TestDateAdd(BaseDateAdd): - pass diff --git a/tests/functional/cross_db_utils/test_datediff.py b/tests/functional/cross_db_utils/test_datediff.py deleted file mode 100644 index 6a58eae7..00000000 --- a/tests/functional/cross_db_utils/test_datediff.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_datediff import ( - seeds__data_datediff_csv, - models__test_datediff_sql, - models__test_datediff_yml, -) - - -class BaseDateDiff(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_datediff.csv": seeds__data_datediff_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_datediff.yml": models__test_datediff_yml, - "test_datediff.sql": models__test_datediff_sql, - } - - -class TestDateDiff(BaseDateDiff): - pass diff --git a/tests/functional/cross_db_utils/test_escape_single_quotes.py b/tests/functional/cross_db_utils/test_escape_single_quotes.py deleted file mode 100644 index 1462ee5e..00000000 --- a/tests/functional/cross_db_utils/test_escape_single_quotes.py +++ /dev/null @@ -1,45 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_escape_single_quotes import ( - models__test_escape_single_quotes_quote_sql, - models__test_escape_single_quotes_backslash_sql, - models__test_escape_single_quotes_yml, -) - - -class BaseEscapeSingleQuotesQuote(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def models(self): - return { - "test_escape_single_quotes.yml": models__test_escape_single_quotes_yml, - "test_escape_single_quotes.sql": models__test_escape_single_quotes_quote_sql, - } - - -class BaseEscapeSingleQuotesBackslash(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def models(self): - return { - "test_escape_single_quotes.yml": models__test_escape_single_quotes_yml, - "test_escape_single_quotes.sql": models__test_escape_single_quotes_backslash_sql, - } - - -@pytest.mark.only_profile("postgres") -class TestEscapeSingleQuotesPostgres(BaseEscapeSingleQuotesQuote): - pass - - -@pytest.mark.only_profile("redshift") -class TestEscapeSingleQuotesRedshift(BaseEscapeSingleQuotesQuote): - pass - - -@pytest.mark.only_profile("snowflake") -class TestEscapeSingleQuotesSnowflake(BaseEscapeSingleQuotesBackslash): - pass - - -@pytest.mark.only_profile("bigquery") -class TestEscapeSingleQuotesBigQuery(BaseEscapeSingleQuotesBackslash): - pass diff --git a/tests/functional/cross_db_utils/test_except.py b/tests/functional/cross_db_utils/test_except.py deleted file mode 100644 index ad0c415c..00000000 --- a/tests/functional/cross_db_utils/test_except.py +++ /dev/null @@ -1,72 +0,0 @@ -import pytest -from dbt.tests.util import run_dbt, check_relations_equal -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_except import ( - seeds__data_except_a_csv, - seeds__data_except_b_csv, - seeds__data_except_a_minus_b_csv, - seeds__data_except_b_minus_a_csv, - models__data_except_empty_sql, - models__test_except_a_minus_b_sql, - models__test_except_b_minus_a_sql, - models__test_except_a_minus_a_sql, - models__test_except_a_minus_empty_sql, - models__test_except_empty_minus_a_sql, - models__test_except_empty_minus_empty_sql, -) - - -class BaseExcept(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return { - "data_except_a.csv": seeds__data_except_a_csv, - "data_except_b.csv": seeds__data_except_b_csv, - "data_except_a_minus_b.csv": seeds__data_except_a_minus_b_csv, - "data_except_b_minus_a.csv": seeds__data_except_b_minus_a_csv, - } - - @pytest.fixture(scope="class") - def models(self): - return { - "data_except_empty.sql": models__data_except_empty_sql, - "test_except_a_minus_b.sql": models__test_except_a_minus_b_sql, - "test_except_b_minus_a.sql": models__test_except_b_minus_a_sql, - "test_except_a_minus_a.sql": models__test_except_a_minus_a_sql, - "test_except_a_minus_empty.sql": models__test_except_a_minus_empty_sql, - "test_except_empty_minus_a.sql": models__test_except_empty_minus_a_sql, - "test_except_empty_minus_empty.sql": models__test_except_empty_minus_empty_sql, - } - - def test_build_assert_equal(self, project): - run_dbt(['deps']) - run_dbt(['build']) - - check_relations_equal( - project.adapter, - ["test_except_a_minus_b", "data_except_a_minus_b"], - ) - check_relations_equal( - project.adapter, - ["test_except_b_minus_a", "data_except_b_minus_a"], - ) - check_relations_equal( - project.adapter, - ["test_except_a_minus_a", "data_except_empty"], - ) - check_relations_equal( - project.adapter, - ["test_except_a_minus_empty", "data_except_a"], - ) - check_relations_equal( - project.adapter, - ["test_except_empty_minus_a", "data_except_empty"], - ) - check_relations_equal( - project.adapter, - ["test_except_empty_minus_empty", "data_except_empty"], - ) - - -class TestExcept(BaseExcept): - pass diff --git a/tests/functional/cross_db_utils/test_hash.py b/tests/functional/cross_db_utils/test_hash.py deleted file mode 100644 index d8454b26..00000000 --- a/tests/functional/cross_db_utils/test_hash.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_hash import ( - seeds__data_hash_csv, - models__test_hash_sql, - models__test_hash_yml, -) - - -class BaseHash(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_hash.csv": seeds__data_hash_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_hash.yml": models__test_hash_yml, - "test_hash.sql": models__test_hash_sql, - } - - -class TestHash(BaseHash): - pass diff --git a/tests/functional/cross_db_utils/test_intersect.py b/tests/functional/cross_db_utils/test_intersect.py deleted file mode 100644 index b7e0ca92..00000000 --- a/tests/functional/cross_db_utils/test_intersect.py +++ /dev/null @@ -1,70 +0,0 @@ -import pytest -from dbt.tests.util import run_dbt, check_relations_equal -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_intersect import ( - seeds__data_intersect_a_csv, - seeds__data_intersect_b_csv, - seeds__data_intersect_a_overlap_b_csv, - models__data_intersect_empty_sql, - models__test_intersect_a_overlap_b_sql, - models__test_intersect_b_overlap_a_sql, - models__test_intersect_a_overlap_a_sql, - models__test_intersect_a_overlap_empty_sql, - models__test_intersect_empty_overlap_a_sql, - models__test_intersect_empty_overlap_empty_sql, -) - - -class BaseIntersect(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return { - "data_intersect_a.csv": seeds__data_intersect_a_csv, - "data_intersect_b.csv": seeds__data_intersect_b_csv, - "data_intersect_a_overlap_b.csv": seeds__data_intersect_a_overlap_b_csv, - } - - @pytest.fixture(scope="class") - def models(self): - return { - "data_intersect_empty.sql": models__data_intersect_empty_sql, - "test_intersect_a_overlap_b.sql": models__test_intersect_a_overlap_b_sql, - "test_intersect_b_overlap_a.sql": models__test_intersect_b_overlap_a_sql, - "test_intersect_a_overlap_a.sql": models__test_intersect_a_overlap_a_sql, - "test_intersect_a_overlap_empty.sql": models__test_intersect_a_overlap_empty_sql, - "test_intersect_empty_overlap_a.sql": models__test_intersect_empty_overlap_a_sql, - "test_intersect_empty_overlap_empty.sql": models__test_intersect_empty_overlap_empty_sql, - } - - def test_build_assert_equal(self, project): - run_dbt(['deps']) - run_dbt(['build']) - - check_relations_equal( - project.adapter, - ["test_intersect_a_overlap_b", "data_intersect_a_overlap_b"], - ) - check_relations_equal( - project.adapter, - ["test_intersect_b_overlap_a", "data_intersect_a_overlap_b"], - ) - check_relations_equal( - project.adapter, - ["test_intersect_a_overlap_a", "data_intersect_a"], - ) - check_relations_equal( - project.adapter, - ["test_intersect_a_overlap_empty", "data_intersect_empty"], - ) - check_relations_equal( - project.adapter, - ["test_intersect_empty_overlap_a", "data_intersect_empty"], - ) - check_relations_equal( - project.adapter, - ["test_intersect_empty_overlap_empty", "data_intersect_empty"], - ) - - -class TestIntersect(BaseIntersect): - pass diff --git a/tests/functional/cross_db_utils/test_last_day.py b/tests/functional/cross_db_utils/test_last_day.py deleted file mode 100644 index f97e53ae..00000000 --- a/tests/functional/cross_db_utils/test_last_day.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_last_day import ( - seeds__data_last_day_csv, - models__test_last_day_sql, - models__test_last_day_yml, -) - - -class BaseLastDay(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_last_day.csv": seeds__data_last_day_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_last_day.yml": models__test_last_day_yml, - "test_last_day.sql": models__test_last_day_sql, - } - - -class TestLastDay(BaseLastDay): - pass diff --git a/tests/functional/cross_db_utils/test_length.py b/tests/functional/cross_db_utils/test_length.py deleted file mode 100644 index de6400ef..00000000 --- a/tests/functional/cross_db_utils/test_length.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_length import ( - seeds__data_length_csv, - models__test_length_sql, - models__test_length_yml, -) - - -class BaseLength(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_length.csv": seeds__data_length_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_length.yml": models__test_length_yml, - "test_length.sql": models__test_length_sql, - } - - -class TestLength(BaseLength): - pass diff --git a/tests/functional/cross_db_utils/test_listagg.py b/tests/functional/cross_db_utils/test_listagg.py deleted file mode 100644 index a62cf183..00000000 --- a/tests/functional/cross_db_utils/test_listagg.py +++ /dev/null @@ -1,28 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_listagg import ( - seeds__data_listagg_csv, - seeds__data_listagg_output_csv, - models__test_listagg_sql, - models__test_listagg_yml, -) - - -class BaseListagg(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return { - "data_listagg.csv": seeds__data_listagg_csv, - "data_listagg_output.csv": seeds__data_listagg_output_csv, - } - - @pytest.fixture(scope="class") - def models(self): - return { - "test_listagg.yml": models__test_listagg_yml, - "test_listagg.sql": models__test_listagg_sql, - } - - -class TestListagg(BaseListagg): - pass diff --git a/tests/functional/cross_db_utils/test_position.py b/tests/functional/cross_db_utils/test_position.py deleted file mode 100644 index 6ab65120..00000000 --- a/tests/functional/cross_db_utils/test_position.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_position import ( - seeds__data_position_csv, - models__test_position_sql, - models__test_position_yml, -) - - -class BasePosition(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_position.csv": seeds__data_position_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_position.yml": models__test_position_yml, - "test_position.sql": models__test_position_sql, - } - - -class TestPosition(BasePosition): - pass diff --git a/tests/functional/cross_db_utils/test_replace.py b/tests/functional/cross_db_utils/test_replace.py deleted file mode 100644 index 6568cbc0..00000000 --- a/tests/functional/cross_db_utils/test_replace.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_replace import ( - seeds__data_replace_csv, - models__test_replace_sql, - models__test_replace_yml, -) - - -class BaseReplace(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_replace.csv": seeds__data_replace_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_replace.yml": models__test_replace_yml, - "test_replace.sql": models__test_replace_sql, - } - - -class TestReplace(BaseReplace): - pass diff --git a/tests/functional/cross_db_utils/test_right.py b/tests/functional/cross_db_utils/test_right.py deleted file mode 100644 index 13b24a81..00000000 --- a/tests/functional/cross_db_utils/test_right.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_right import ( - seeds__data_right_csv, - models__test_right_sql, - models__test_right_yml, -) - - -class BaseRight(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_right.csv": seeds__data_right_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_right.yml": models__test_right_yml, - "test_right.sql": models__test_right_sql, - } - - -class TestRight(BaseRight): - pass diff --git a/tests/functional/cross_db_utils/test_safe_cast.py b/tests/functional/cross_db_utils/test_safe_cast.py deleted file mode 100644 index 979bd5df..00000000 --- a/tests/functional/cross_db_utils/test_safe_cast.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_safe_cast import ( - seeds__data_safe_cast_csv, - models__test_safe_cast_sql, - models__test_safe_cast_yml, -) - - -class BaseSafeCast(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_safe_cast.csv": seeds__data_safe_cast_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_safe_cast.yml": models__test_safe_cast_yml, - "test_safe_cast.sql": models__test_safe_cast_sql, - } - - -class TestSafeCast(BaseSafeCast): - pass diff --git a/tests/functional/cross_db_utils/test_split_part.py b/tests/functional/cross_db_utils/test_split_part.py deleted file mode 100644 index 5968f412..00000000 --- a/tests/functional/cross_db_utils/test_split_part.py +++ /dev/null @@ -1,24 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_split_part import ( - seeds__data_split_part_csv, - models__test_split_part_sql, - models__test_split_part_yml, -) - - -class BaseSplitPart(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_split_part.csv": seeds__data_split_part_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_split_part.yml": models__test_split_part_yml, - "test_split_part.sql": models__test_split_part_sql, - } - - -class TestSplitPart(BaseSplitPart): - pass diff --git a/tests/functional/cross_db_utils/test_string_literal.py b/tests/functional/cross_db_utils/test_string_literal.py deleted file mode 100644 index 9fb01cf7..00000000 --- a/tests/functional/cross_db_utils/test_string_literal.py +++ /dev/null @@ -1,19 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_string_literal import ( - models__test_string_literal_sql, - models__test_string_literal_yml, -) - - -class BaseStringLiteral(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def models(self): - return { - "test_string_literal.yml": models__test_string_literal_yml, - "test_string_literal.sql": models__test_string_literal_sql, - } - - -class TestStringLiteral(BaseStringLiteral): - pass diff --git a/tests/functional/cross_db_utils/test_type_bigint.py b/tests/functional/cross_db_utils/test_type_bigint.py deleted file mode 100644 index 81b04231..00000000 --- a/tests/functional/cross_db_utils/test_type_bigint.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_type_bigint import ( - seeds__data_type_bigint_csv, - models__test_type_bigint_sql, - models__test_type_bigint_yml, -) - - -class BaseTypeBigint(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_type_bigint.csv": seeds__data_type_bigint_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_type_bigint.yml": models__test_type_bigint_yml, - "test_type_bigint.sql": models__test_type_bigint_sql, - } - - -@pytest.mark.skip(reason="TODO - implement this test") -class TestTypeBigint(BaseTypeBigint): - pass diff --git a/tests/functional/cross_db_utils/test_type_boolean.py b/tests/functional/cross_db_utils/test_type_boolean.py deleted file mode 100644 index 83c7d765..00000000 --- a/tests/functional/cross_db_utils/test_type_boolean.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_type_boolean import ( - seeds__data_type_boolean_csv, - models__test_type_boolean_sql, - models__test_type_boolean_yml, -) - - -class BaseTypeBoolean(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_type_boolean.csv": seeds__data_type_boolean_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_type_boolean.yml": models__test_type_boolean_yml, - "test_type_boolean.sql": models__test_type_boolean_sql, - } - - -@pytest.mark.skip(reason="TODO - implement this test") -class TestTypeBoolean(BaseTypeBoolean): - pass diff --git a/tests/functional/cross_db_utils/test_type_float.py b/tests/functional/cross_db_utils/test_type_float.py deleted file mode 100644 index 90380979..00000000 --- a/tests/functional/cross_db_utils/test_type_float.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_type_float import ( - seeds__data_type_float_csv, - models__test_type_float_sql, - models__test_type_float_yml, -) - - -class BaseTypeFloat(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_type_float.csv": seeds__data_type_float_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_type_float.yml": models__test_type_float_yml, - "test_type_float.sql": models__test_type_float_sql, - } - - -@pytest.mark.skip(reason="TODO - implement this test") -class TestTypeFloat(BaseTypeFloat): - pass diff --git a/tests/functional/cross_db_utils/test_type_int.py b/tests/functional/cross_db_utils/test_type_int.py deleted file mode 100644 index d05669ef..00000000 --- a/tests/functional/cross_db_utils/test_type_int.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_type_int import ( - seeds__data_type_int_csv, - models__test_type_int_sql, - models__test_type_int_yml, -) - - -class BaseTypeInt(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_type_int.csv": seeds__data_type_int_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_type_int.yml": models__test_type_int_yml, - "test_type_int.sql": models__test_type_int_sql, - } - - -@pytest.mark.skip(reason="TODO - implement this test") -class TestTypeInt(BaseTypeInt): - pass diff --git a/tests/functional/cross_db_utils/test_type_numeric.py b/tests/functional/cross_db_utils/test_type_numeric.py deleted file mode 100644 index a337e575..00000000 --- a/tests/functional/cross_db_utils/test_type_numeric.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_type_numeric import ( - seeds__data_type_numeric_csv, - models__test_type_numeric_sql, - models__test_type_numeric_yml, -) - - -class BaseTypeNumeric(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_type_numeric.csv": seeds__data_type_numeric_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_type_numeric.yml": models__test_type_numeric_yml, - "test_type_numeric.sql": models__test_type_numeric_sql, - } - - -@pytest.mark.skip(reason="TODO - implement this test") -class TestTypeNumeric(BaseTypeNumeric): - pass diff --git a/tests/functional/cross_db_utils/test_type_string.py b/tests/functional/cross_db_utils/test_type_string.py deleted file mode 100644 index 16e9478e..00000000 --- a/tests/functional/cross_db_utils/test_type_string.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_type_string import ( - seeds__data_type_string_csv, - models__test_type_string_sql, - models__test_type_string_yml, -) - - -class BaseTypeString(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_type_string.csv": seeds__data_type_string_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_type_string.yml": models__test_type_string_yml, - "test_type_string.sql": models__test_type_string_sql, - } - - -@pytest.mark.skip(reason="TODO - implement this test") -class TestTypeString(BaseTypeString): - pass diff --git a/tests/functional/cross_db_utils/test_type_timestamp.py b/tests/functional/cross_db_utils/test_type_timestamp.py deleted file mode 100644 index 3244f5c3..00000000 --- a/tests/functional/cross_db_utils/test_type_timestamp.py +++ /dev/null @@ -1,25 +0,0 @@ -import pytest -from tests.functional.cross_db_utils.base_cross_db_macro import BaseCrossDbMacro -from tests.functional.cross_db_utils.fixture_type_timestamp import ( - seeds__data_type_timestamp_csv, - models__test_type_timestamp_sql, - models__test_type_timestamp_yml, -) - - -class BaseTypeTimestamp(BaseCrossDbMacro): - @pytest.fixture(scope="class") - def seeds(self): - return {"data_type_timestamp.csv": seeds__data_type_timestamp_csv} - - @pytest.fixture(scope="class") - def models(self): - return { - "test_type_timestamp.yml": models__test_type_timestamp_yml, - "test_type_timestamp.sql": models__test_type_timestamp_sql, - } - - -@pytest.mark.skip(reason="TODO - implement this test") -class TestTypeTimestamp(BaseTypeTimestamp): - pass diff --git a/tests/functional/cross_db_utils/test_utils.py b/tests/functional/cross_db_utils/test_utils.py new file mode 100644 index 00000000..17eed66e --- /dev/null +++ b/tests/functional/cross_db_utils/test_utils.py @@ -0,0 +1,140 @@ +import os +import pytest +from dbt.tests.util import run_dbt +from dbt.tests.adapter.utils.base_utils import BaseUtils +from dbt.tests.adapter.utils.test_any_value import BaseAnyValue +from dbt.tests.adapter.utils.test_bool_or import BaseBoolOr +from dbt.tests.adapter.utils.test_cast_bool_to_text import BaseCastBoolToText +from dbt.tests.adapter.utils.test_concat import BaseConcat +from dbt.tests.adapter.utils.test_dateadd import BaseDateAdd +from dbt.tests.adapter.utils.test_datediff import BaseDateDiff +from dbt.tests.adapter.utils.test_date_trunc import BaseDateTrunc +from dbt.tests.adapter.utils.test_escape_single_quotes import BaseEscapeSingleQuotesQuote +from dbt.tests.adapter.utils.test_escape_single_quotes import BaseEscapeSingleQuotesBackslash +from dbt.tests.adapter.utils.test_except import BaseExcept +from dbt.tests.adapter.utils.test_hash import BaseHash +from dbt.tests.adapter.utils.test_intersect import BaseIntersect +from dbt.tests.adapter.utils.test_last_day import BaseLastDay +from dbt.tests.adapter.utils.test_length import BaseLength +from dbt.tests.adapter.utils.test_listagg import BaseListagg +from dbt.tests.adapter.utils.test_position import BasePosition +from dbt.tests.adapter.utils.test_replace import BaseReplace +from dbt.tests.adapter.utils.test_right import BaseRight +from dbt.tests.adapter.utils.test_safe_cast import BaseSafeCast +from dbt.tests.adapter.utils.test_split_part import BaseSplitPart +from dbt.tests.adapter.utils.test_string_literal import BaseStringLiteral + + +class BaseDbtUtilsBackCompat(BaseUtils): + # install this repo as a package + @pytest.fixture(scope="class") + def packages(self): + return {"packages": [{"local": os.getcwd()}]} + + # call the macros from the 'dbt_utils' namespace + # instead of the unspecified / global namespace + def macro_namespace(self): + return "dbt_utils" + + # actual test sequence needs to run 'deps' first + def test_build_assert_equal(self, project): + run_dbt(['deps']) + super().test_build_assert_equal(project) + + +# order matters for this multiple inheritance: leftmost "wins" +# prioritize this package's macros +class TestAnyValue(BaseDbtUtilsBackCompat, BaseAnyValue): + pass + + +class TestBoolOr(BaseDbtUtilsBackCompat, BaseBoolOr): + pass + + +class TestCastBoolToText(BaseDbtUtilsBackCompat, BaseCastBoolToText): + pass + + +class TestConcat(BaseDbtUtilsBackCompat, BaseConcat): + pass + + +class TestDateAdd(BaseDbtUtilsBackCompat, BaseDateAdd): + pass + + +class TestDateDiff(BaseDbtUtilsBackCompat, BaseDateDiff): + pass + + +class TestDateTrunc(BaseDbtUtilsBackCompat, BaseDateTrunc): + pass + + +@pytest.mark.only_profile("postgres") +class TestEscapeSingleQuotesPostgres(BaseDbtUtilsBackCompat, BaseEscapeSingleQuotesQuote): + pass + + +@pytest.mark.only_profile("redshift") +class TestEscapeSingleQuotesRedshift(BaseDbtUtilsBackCompat, BaseEscapeSingleQuotesQuote): + pass + + +@pytest.mark.only_profile("snowflake") +class TestEscapeSingleQuotesSnowflake(BaseDbtUtilsBackCompat, BaseEscapeSingleQuotesBackslash): + pass + + +@pytest.mark.only_profile("bigquery") +class TestEscapeSingleQuotesBigQuery(BaseDbtUtilsBackCompat, BaseEscapeSingleQuotesBackslash): + pass + + +class TestExcept(BaseDbtUtilsBackCompat, BaseExcept): + pass + + +class TestHash(BaseDbtUtilsBackCompat, BaseHash): + pass + + +class TestIntersect(BaseDbtUtilsBackCompat, BaseIntersect): + pass + + +class TestLastDay(BaseDbtUtilsBackCompat, BaseLastDay): + pass + + +class TestLength(BaseDbtUtilsBackCompat, BaseLength): + pass + + +class TestListagg(BaseDbtUtilsBackCompat, BaseListagg): + pass + + +class TestPosition(BaseDbtUtilsBackCompat, BasePosition): + pass + + +class TestReplace(BaseDbtUtilsBackCompat, BaseReplace): + pass + + +class TestRight(BaseDbtUtilsBackCompat, BaseRight): + pass + + +class TestSafeCast(BaseDbtUtilsBackCompat, BaseSafeCast): + pass + + +class TestSplitPart(BaseDbtUtilsBackCompat, BaseSplitPart): + pass + + +class TestStringLiteral(BaseDbtUtilsBackCompat, BaseStringLiteral): + pass