-
Notifications
You must be signed in to change notification settings - Fork 59
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
Lift + shift for cross-db macros #120
Merged
Merged
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c905c2b
Initialize lift + shift, dateadd + datediff
jtcohen6 9268663
Switch to alternative dev branches
dbeatty10 7dc6340
Lift and shift cross-database macros from dbt-utils
dbeatty10 6160a03
Switch namespace from `dbt_utils` to `dbt`
dbeatty10 5cc28d3
Remove conflicting definition of current_timestamp()
dbeatty10 731fb13
Trim trailing whitespace
dbeatty10 0dce93d
Copy functional tests for cross-database macros from dbt-utils
dbeatty10 709a5b6
Remove references to other profiles
dbeatty10 23c492b
Kick out the `current_timestamp` + `type_*` macros/tests
dbeatty10 bc4328e
Specify the namespace explicitly
dbeatty10 0b349a6
Duplicate default implementations into Redshift (to avoid inheritance…
dbeatty10 90d1c6e
Merge branch 'main' into dbeatty/utils-lift-shift
dbeatty10 0ea5ae6
Remove branch identifiers
dbeatty10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% macro redshift__cast_bool_to_text(field) %} | ||
case | ||
when {{ field }} is true then 'true' | ||
when {{ field }} is false then 'false' | ||
end::text | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{#-- redshift should use default instead of postgres --#} | ||
{% macro redshift__dateadd(datepart, interval, from_date_or_timestamp) %} | ||
|
||
dateadd( | ||
{{ datepart }}, | ||
{{ interval }}, | ||
{{ from_date_or_timestamp }} | ||
) | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{#-- redshift should use default instead of postgres --#} | ||
{% macro redshift__datediff(first_date, second_date, datepart) -%} | ||
|
||
datediff( | ||
{{ datepart }}, | ||
{{ first_date }}, | ||
{{ second_date }} | ||
) | ||
|
||
{%- endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{# redshift should use default instead of postgres #} | ||
{% macro redshift__last_day(date, datepart) %} | ||
cast( | ||
{{dbt.dateadd('day', '-1', | ||
dbt.dateadd(datepart, '1', dbt.date_trunc(datepart, date)) | ||
)}} | ||
as date) | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% macro redshift__length(expression) %} | ||
|
||
len( | ||
{{ expression }} | ||
) | ||
|
||
{%- endmacro -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{# 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 %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% macro redshift__split_part(string_text, delimiter_text, part_number) %} | ||
|
||
{% if part_number >= 0 %} | ||
{{ dbt.default__split_part(string_text, delimiter_text, part_number) }} | ||
{% else %} | ||
{{ dbt._split_part_negative(string_text, delimiter_text, part_number) }} | ||
{% endif %} | ||
|
||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(BaseEscapeSingleQuotesQuote): | ||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just need to remove the branch identifiers, rerun tests, then we should be hot to trot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hot to trot 🔥