Skip to content

Commit

Permalink
consolidate timestamps (#191)
Browse files Browse the repository at this point in the history
* consolidate timestamps

* add changie and update reqs

* fix whitespace

* fix utc macro

* Update Under the Hood-20220926-101606.yaml

* fix base test class import

* add backcompat to fixture

* add utc backcompat

* remove cruft in timestamps

* add backcompat back

* remove duplicate snapshot macro

* whitespace fix

* fix backcompat macro

* add redshift__current_timestamp_backcompat

* fix test naming and import

* fix base test class import

* update dev-requirements

* Update change log body
  • Loading branch information
colin-rogers-dbt authored Sep 30, 2022
1 parent 8ff1c9e commit 717018a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changes/unreleased/Under the Hood-20220926-101606.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Features
body: Migrate dbt-utils current_timestamp macros into core + adapters
time: 2022-09-26T10:16:06.676737-07:00
custom:
Author: colin-rogers-dbt
Issue: "194"
PR: "191"
14 changes: 0 additions & 14 deletions dbt/include/redshift/macros/adapters.sql
Original file line number Diff line number Diff line change
Expand Up @@ -216,20 +216,6 @@
{{ return(postgres__check_schema_exists(information_schema, schema)) }}
{%- endmacro %}

{% macro redshift__current_timestamp() -%}
getdate()
{%- endmacro %}

{% macro redshift__snapshot_get_time() -%}
{{ current_timestamp() }}::timestamp
{%- endmacro %}


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


{% macro redshift__persist_docs(relation, model, for_relation, for_columns) -%}
{% if for_relation and config.persist_relation_docs() and model.description %}
Expand Down
20 changes: 20 additions & 0 deletions dbt/include/redshift/macros/timestamps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% macro redshift__current_timestamp() -%}
getdate()
{%- endmacro %}

{% macro redshift__snapshot_get_time() -%}
{{ current_timestamp() }}::timestamp
{%- endmacro %}

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

{% macro redshift__current_timestamp_backcompat() -%}
getdate()
{%- endmacro %}

{% macro redshift__current_timestamp_in_utc_backcompat() -%}
getdate()
{%- endmacro %}
20 changes: 20 additions & 0 deletions tests/functional/adapter/utils/test_timestamps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest
from dbt.tests.adapter.utils.test_timestamps import BaseCurrentTimestamps


class TestCurrentTimestampRedshift(BaseCurrentTimestamps):
@pytest.fixture(scope="class")
def expected_schema(self):
return {
"current_timestamp": "timestamp without time zone",
"current_timestamp_in_utc_backcompat": "timestamp without time zone",
"current_timestamp_backcompat": "timestamp without time zone",
}

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

0 comments on commit 717018a

Please sign in to comment.