Skip to content

Commit

Permalink
Port tests for lift + shift for cross-db macros from dbt-spark (#118)
Browse files Browse the repository at this point in the history
### Description

Ports tests for lift + shift for cross-db macros from [dbt-labs/dbt-spark#359](dbt-labs/dbt-spark#359).
  • Loading branch information
ueshin authored Jul 11, 2022
1 parent 7d652d4 commit 4ad47da
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ def dbt_profile_target(request):
def skip_by_profile_type(request):
profile_type = request.config.getoption("--profile")
if request.node.get_closest_marker("skip_profile"):
if request.node.get_closest_marker("skip_profile").args[0] == profile_type:
pytest.skip(f"skipped on '{profile_type}' profile")
for skip_profile_type in request.node.get_closest_marker("skip_profile").args:
if skip_profile_type == profile_type:
pytest.skip(f"skipped on '{profile_type}' profile")
61 changes: 61 additions & 0 deletions tests/functional/adapter/utils/fixture_listagg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# SparkSQL does not support 'order by' for its 'listagg' equivalent
# the argument is ignored, so let's ignore those fields when checking equivalency

models__test_listagg_no_order_by_sql = """
with data as (
select * from {{ ref('data_listagg') }}
),
data_output as (
select * from {{ ref('data_listagg_output') }}
),
calculate as (
/*
select
group_col,
{{ listagg('string_text', "'_|_'", "order by order_col") }} as actual,
'bottom_ordered' as version
from data
group by group_col
union all
select
group_col,
{{ listagg('string_text', "'_|_'", "order by order_col", 2) }} as actual,
'bottom_ordered_limited' as version
from data
group by group_col
union all
*/
select
group_col,
{{ listagg('string_text', "', '") }} as actual,
'comma_whitespace_unordered' as version
from data
where group_col = 3
group by group_col
union all
select
group_col,
{{ listagg('DISTINCT string_text', "','") }} as actual,
'distinct_comma' as version
from data
where group_col = 3
group by group_col
union all
select
group_col,
{{ listagg('string_text') }} as actual,
'no_params' as version
from data
where group_col = 3
group by group_col
)
select
calculate.actual,
data_output.expected
from calculate
left join data_output
on calculate.group_col = data_output.group_col
and calculate.version = data_output.version
"""
117 changes: 117 additions & 0 deletions tests/functional/adapter/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import pytest

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_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_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

# requires modification
from dbt.tests.adapter.utils.test_listagg import BaseListagg
from dbt.tests.adapter.utils.fixture_listagg import models__test_listagg_yml
from tests.functional.adapter.utils.fixture_listagg import models__test_listagg_no_order_by_sql


class TestAnyValue(BaseAnyValue):
pass


class TestBoolOr(BaseBoolOr):
pass


class TestCastBoolToText(BaseCastBoolToText):
pass


class TestConcat(BaseConcat):
pass


class TestDateAdd(BaseDateAdd):
pass


# This test generates a super long create table sentence that exceeds HiveMetastore's limit
@pytest.mark.skip_profile("databricks_cluster", "databricks_sql_endpoint")
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


# SparkSQL does not support 'order by' for its 'listagg' equivalent
# the argument is ignored, so let's ignore those fields when checking equivalency
class TestListagg(BaseListagg):
@pytest.fixture(scope="class")
def models(self):
return {
"test_listagg.yml": models__test_listagg_yml,
"test_listagg.sql": self.interpolate_macro_namespace(
models__test_listagg_no_order_by_sql, "listagg"
),
}


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 4ad47da

Please sign in to comment.