Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

consolidate timestamp macros #273

Merged
merged 21 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
a109d47
consolidate timestamp macros
colin-rogers-dbt Sep 22, 2022
731c013
add testing changes
colin-rogers-dbt Sep 23, 2022
02f2c50
deleting extra timestamps.sql
colin-rogers-dbt Sep 23, 2022
9d8b024
changie entry
colin-rogers-dbt Sep 23, 2022
ac50377
Merge branch 'main' into consolidateTimestampMacros
colin-rogers-dbt Sep 23, 2022
105d46b
fix backcompat
colin-rogers-dbt Sep 23, 2022
8e5453b
Merge branch 'main' into consolidateTimestampMacros
colin-rogers-dbt Sep 23, 2022
883dbd1
Merge branch 'consolidateTimestampMacros' of https://github.com/dbt-l…
colin-rogers-dbt Sep 23, 2022
c07d9c6
Update Breaking Changes-20220923-112314.yaml
colin-rogers-dbt Sep 26, 2022
7c6617f
Update dev-requirements.txt
colin-rogers-dbt Sep 27, 2022
fcadd52
Merge branch 'main' into consolidateTimestampMacros
colin-rogers-dbt Sep 27, 2022
1fa8615
Merge branch 'consolidateTimestampMacros' of https://github.com/dbt-l…
colin-rogers-dbt Sep 27, 2022
c33d72e
remove current_timestamp_in_utc
colin-rogers-dbt Sep 28, 2022
331d14d
fix backcompat
colin-rogers-dbt Sep 29, 2022
e7d5864
Merge branch 'main' of https://github.com/dbt-labs/dbt-snowflake
colin-rogers-dbt Sep 29, 2022
837f837
Merge branch 'main' into consolidateTimestampMacros
colin-rogers-dbt Sep 29, 2022
1896507
change test import
colin-rogers-dbt Sep 30, 2022
ed01401
fix BaseCurrentTimestamps import
colin-rogers-dbt Sep 30, 2022
5ce70e5
update dev-requirements
colin-rogers-dbt Sep 30, 2022
09b62d6
Update change log body
colin-rogers-dbt Sep 30, 2022
8ce23ec
fix changie log
colin-rogers-dbt Sep 30, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Feature-20220923-112314.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Feature
body: Migrate dbt-utils current_timestamp macros into core + adapters
time: 2022-09-23T11:23:14.312738-07:00
custom:
Author: colin-rogers-dbt
Issue: "276"
PR: "273"
15 changes: 0 additions & 15 deletions dbt/include/snowflake/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,6 @@
{{ return(load_result('check_schema_exists').table) }}
{%- endmacro %}

{% macro snowflake__current_timestamp() -%}
convert_timezone('UTC', current_timestamp())
{%- endmacro %}


{% macro snowflake__snapshot_string_as_time(timestamp) -%}
{%- set result = "to_timestamp_ntz('" ~ timestamp ~ "')" -%}
{{ return(result) }}
{%- endmacro %}


{% macro snowflake__snapshot_get_time() -%}
to_timestamp_ntz({{ current_timestamp() }})
{%- endmacro %}


{% macro snowflake__rename_relation(from_relation, to_relation) -%}
{% call statement('rename_relation') -%}
Expand Down
20 changes: 20 additions & 0 deletions dbt/include/snowflake/macros/utils/timestamps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% macro snowflake__current_timestamp() -%}
convert_timezone('UTC', current_timestamp())
{%- endmacro %}

{% macro snowflake__snapshot_string_as_time(timestamp) -%}
{%- set result = "to_timestamp_ntz('" ~ timestamp ~ "')" -%}
{{ return(result) }}
{%- endmacro %}

{% macro snowflake__snapshot_get_time() -%}
to_timestamp_ntz({{ current_timestamp() }})
{%- endmacro %}

{% macro snowflake__current_timestamp_backcompat() %}
current_timestamp::{{ type_timestamp() }}
{% endmacro %}

{% macro snowflake__current_timestamp_in_utc_backcompat() %}
convert_timezone('UTC', {{ snowflake__current_timestamp_backcompat() }})::{{ type_timestamp() }}
{% endmacro %}
31 changes: 31 additions & 0 deletions tests/functional/adapter/test_timestamps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import imp
import pytest
from dbt.tests.adapter.utils.test_timestamps import BaseCurrentTimestamps

_MODEL_CURRENT_TIMESTAMP = """
SELECT {{current_timestamp()}} as current_timestamp,
{{current_timestamp_in_utc_backcompat()}} as current_timestamp_in_utc_backcompat,
{{current_timestamp_backcompat()}} as current_timestamp_backcompat
"""


class TestCurrentTimestampSnowflake(BaseCurrentTimestamps):
@pytest.fixture(scope="class")
def models(self):
return {"get_current_timestamp.sql": _MODEL_CURRENT_TIMESTAMP}

@pytest.fixture(scope="class")
def expected_schema(self):
return {
"CURRENT_TIMESTAMP": "TIMESTAMP_TZ",
"CURRENT_TIMESTAMP_IN_UTC_BACKCOMPAT": "TIMESTAMP_NTZ",
"CURRENT_TIMESTAMP_BACKCOMPAT": "TIMESTAMP_NTZ",
}
colin-rogers-dbt marked this conversation as resolved.
Show resolved Hide resolved

@pytest.fixture(scope="class")
def expected_sql(self):
return """
select convert_timezone('UTC', current_timestamp()) as current_timestamp,
convert_timezone('UTC', current_timestamp::TIMESTAMP)::TIMESTAMP as current_timestamp_in_utc_backcompat,
current_timestamp::TIMESTAMP as current_timestamp_backcompat
"""