Skip to content

Commit

Permalink
Lift + shift for cross-db macros (#162)
Browse files Browse the repository at this point in the history
* Initialize lift + shift, dateadd + datediff

* Switch to alternative dev branches

* Lift and shift cross-database macros from dbt-utils

* Switch namespace from `dbt_utils` to `dbt`

* Trim trailing whitespace

* Copy functional tests for cross-database macros from dbt-utils

* Remove references to other profiles

* Kick out the `current_timestamp` + `type_*` macros/tests

* Remove branch identifiers

Co-authored-by: Jeremy Cohen <jeremy@dbtlabs.com>
  • Loading branch information
dbeatty10 and jtcohen6 authored Jun 17, 2022
1 parent 8db7d9f commit 51cdc7a
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dbt/include/snowflake/macros/utils/bool_or.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% macro snowflake__bool_or(expression) -%}

boolor_agg({{ expression }})

{%- endmacro %}
4 changes: 4 additions & 0 deletions dbt/include/snowflake/macros/utils/escape_single_quotes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{# /*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 %}
12 changes: 12 additions & 0 deletions dbt/include/snowflake/macros/utils/right.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% macro snowflake__right(string_text, length_expression) %}

case when {{ length_expression }} = 0
then ''
else
right(
{{ string_text }},
{{ length_expression }}
)
end

{%- endmacro -%}
3 changes: 3 additions & 0 deletions dbt/include/snowflake/macros/utils/safe_cast.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro snowflake__safe_cast(field, type) %}
try_cast({{field}} as {{type}})
{% endmacro %}
103 changes: 103 additions & 0 deletions tests/functional/adapter/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import pytest
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 TestAnyValue(BaseAnyValue):
pass


class TestBoolOr(BaseBoolOr):
pass


class TestCastBoolToText(BaseCastBoolToText):
pass


class TestConcat(BaseConcat):
pass


class TestDateAdd(BaseDateAdd):
pass


class TestDateDiff(BaseDateDiff):
pass


class TestDateTrunc(BaseDateTrunc):
pass


class TestEscapeSingleQuotes(BaseEscapeSingleQuotesBackslash):
pass


class TestExcept(BaseExcept):
pass


class TestHash(BaseHash):
pass


class TestIntersect(BaseIntersect):
pass


class TestLastDay(BaseLastDay):
pass


class TestLength(BaseLength):
pass


class TestListagg(BaseListagg):
pass


class TestPosition(BasePosition):
pass


class TestReplace(BaseReplace):
pass


class TestRight(BaseRight):
pass


class TestSafeCast(BaseSafeCast):
pass


class TestSplitPart(BaseSplitPart):
pass


class TestStringLiteral(BaseStringLiteral):
pass

0 comments on commit 51cdc7a

Please sign in to comment.