diff --git a/.changes/unreleased/Features-20220926-105700.yaml b/.changes/unreleased/Features-20220926-105700.yaml new file mode 100644 index 000000000..61e0ac741 --- /dev/null +++ b/.changes/unreleased/Features-20220926-105700.yaml @@ -0,0 +1,7 @@ +kind: Features +body: Migrate dbt-utils current_timestamp macros into core + adapters +time: 2022-09-26T10:57:00.942765-07:00 +custom: + Author: colin-rogers-dbt + Issue: "324" + PR: "323" diff --git a/dbt/include/bigquery/macros/adapters.sql b/dbt/include/bigquery/macros/adapters.sql index cbfba2627..07cf3c3e5 100644 --- a/dbt/include/bigquery/macros/adapters.sql +++ b/dbt/include/bigquery/macros/adapters.sql @@ -109,17 +109,6 @@ {%- endmacro %} -{% macro bigquery__current_timestamp() -%} - CURRENT_TIMESTAMP() -{%- endmacro %} - - -{% macro bigquery__snapshot_string_as_time(timestamp) -%} - {%- set result = 'TIMESTAMP("' ~ timestamp ~ '")' -%} - {{ return(result) }} -{%- endmacro %} - - {% macro bigquery__list_schemas(database) -%} {{ return(adapter.list_schemas(database)) }} {% endmacro %} diff --git a/dbt/include/bigquery/macros/utils/timestamps.sql b/dbt/include/bigquery/macros/utils/timestamps.sql new file mode 100644 index 000000000..cdcbfd51e --- /dev/null +++ b/dbt/include/bigquery/macros/utils/timestamps.sql @@ -0,0 +1,12 @@ +{% macro bigquery__current_timestamp() -%} + current_timestamp() +{%- endmacro %} + +{% macro bigquery__snapshot_string_as_time(timestamp) -%} + {%- set result = 'TIMESTAMP("' ~ timestamp ~ '")' -%} + {{ return(result) }} +{%- endmacro %} + +{% macro bigquery__current_timestamp_backcompat() -%} + current_timestamp +{%- endmacro %} diff --git a/tests/functional/adapter/utils/test_timestamps.py b/tests/functional/adapter/utils/test_timestamps.py new file mode 100644 index 000000000..2f35e40ee --- /dev/null +++ b/tests/functional/adapter/utils/test_timestamps.py @@ -0,0 +1,18 @@ +import pytest +from dbt.tests.adapter.utils.test_timestamps import BaseCurrentTimestamps + + +class TestCurrentTimestampBigQuery(BaseCurrentTimestamps): + @pytest.fixture(scope="class") + def expected_schema(self): + return { + "current_timestamp": "TIMESTAMP", + "current_timestamp_in_utc_backcompat": "TIMESTAMP", + "current_timestamp_backcompat": "TIMESTAMP", + } + + @pytest.fixture(scope="class") + def expected_sql(self): + return """select current_timestamp() as current_timestamp, + current_timestamp as current_timestamp_in_utc_backcompat, + current_timestamp as current_timestamp_backcompat""" \ No newline at end of file