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

Fix logic in utils tests #392

Merged
merged 3 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion dbt/include/sqlserver/macros/utils/concat.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% macro sqlserver__concat(fields) -%}
concat({{ fields|join(', ') }}, '')
concat({{ fields|join(', ') }})
{%- endmacro %}
2 changes: 1 addition & 1 deletion dbt/include/sqlserver/macros/utils/hash.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{% macro sqlserver__hash(field) %}
convert(varchar(50), hashbytes('md5', {{field}}), 2)
lower(convert(varchar(50), hashbytes('md5', coalesce(convert(varchar(max), {{field}}), '')), 2))
{% endmacro %}
85 changes: 58 additions & 27 deletions tests/functional/adapter/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,31 @@
from dbt.tests.adapter.utils.test_string_literal import BaseStringLiteral


class TestAnyValueSQLServer(BaseAnyValue):
class BaseFixedMacro:
@pytest.fixture(scope="class")
def macros(self):
return {
"test_assert_equal.sql": """
{% test assert_equal(model, actual, expected) %}
select * from {{ model }}
where {{ actual }} != {{ expected }}
or ({{ actual }} is null and {{ expected }} is not null)
or ({{ expected }} is null and {{ actual }} is not null)
{% endtest %}
"""
}


class TestAnyValueSQLServer(BaseFixedMacro, BaseAnyValue):
pass


@pytest.mark.skip("bool_or not supported in this adapter")
class TestBoolOrSQLServer(BaseBoolOr):
class TestBoolOrSQLServer(BaseFixedMacro, BaseBoolOr):
pass


class TestCastBoolToTextSQLServer(BaseCastBoolToText):
class TestCastBoolToTextSQLServer(BaseFixedMacro, BaseCastBoolToText):
@pytest.fixture(scope="class")
def models(self):
models__test_cast_bool_to_text_sql = """
Expand Down Expand Up @@ -67,51 +82,67 @@ def models(self):
}


class TestConcatSQLServer(BaseConcat):
pass
class TestConcatSQLServer(BaseFixedMacro, BaseConcat):
@pytest.fixture(scope="class")
def seeds(self):
return {
"data_concat.csv": """input_1,input_2,output
a,b,ab
a,,a
,b,b
"""
}


class TestDateTruncSQLServer(BaseDateTrunc):
class TestDateTruncSQLServer(BaseFixedMacro, BaseDateTrunc):
pass


class TestHashSQLServer(BaseHash):
pass
seeds__data_hash_csv = """input_1,output
ab,187ef4436122d1cc2f40dc2b92f0eba0
a,0cc175b9c0f1b6a831c399e269772661
1,c4ca4238a0b923820dcc509a6f75849b
,d41d8cd98f00b204e9800998ecf8427e"""


class TestStringLiteralSQLServer(BaseStringLiteral):
class TestHashSQLServer(BaseFixedMacro, BaseHash):
@pytest.fixture(scope="class")
def seeds(self):
return {"data_hash.csv": seeds__data_hash_csv}


class TestStringLiteralSQLServer(BaseFixedMacro, BaseStringLiteral):
pass


class TestSplitPartSQLServer(BaseSplitPart):
class TestSplitPartSQLServer(BaseFixedMacro, BaseSplitPart):
pass


class TestDateDiffSQLServer(BaseDateDiff):
class TestDateDiffSQLServer(BaseFixedMacro, BaseDateDiff):
pass


class TestEscapeSingleQuotesSQLServer(BaseEscapeSingleQuotesQuote):
class TestEscapeSingleQuotesSQLServer(BaseFixedMacro, BaseEscapeSingleQuotesQuote):
pass


class TestIntersectSQLServer(BaseIntersect):
class TestIntersectSQLServer(BaseFixedMacro, BaseIntersect):
pass


class TestLastDaySQLServer(BaseLastDay):
class TestLastDaySQLServer(BaseFixedMacro, BaseLastDay):
pass


class TestLengthSQLServer(BaseLength):
class TestLengthSQLServer(BaseFixedMacro, BaseLength):
pass


class TestListaggSQLServer(BaseListagg):
class TestListaggSQLServer(BaseFixedMacro, BaseListagg):
# Only supported in SQL Server 2017 and later or cloud versions
# DISTINCT not supported
# limit not supported

@pytest.fixture(scope="class")
def seeds(self):
seeds__data_listagg_output_csv = """group_col,expected,version
Expand Down Expand Up @@ -190,15 +221,15 @@ def models(self):
}


class TestRightSQLServer(BaseRight):
class TestRightSQLServer(BaseFixedMacro, BaseRight):
pass


class TestSafeCastSQLServer(BaseSafeCast):
class TestSafeCastSQLServer(BaseFixedMacro, BaseSafeCast):
pass


class TestDateAddSQLServer(BaseDateAdd):
class TestDateAddSQLServer(BaseFixedMacro, BaseDateAdd):
@pytest.fixture(scope="class")
def project_config_update(self):
return {
Expand All @@ -216,15 +247,15 @@ def project_config_update(self):
}


class TestExceptSQLServer(BaseExcept):
class TestExceptSQLServer(BaseFixedMacro, BaseExcept):
pass


class TestPositionSQLServer(BasePosition):
class TestPositionSQLServer(BaseFixedMacro, BasePosition):
pass


class TestReplaceSQLServer(BaseReplace):
class TestReplaceSQLServer(BaseFixedMacro, BaseReplace):
pass


Expand All @@ -233,15 +264,15 @@ class TestCurrentTimestampSQLServer(BaseCurrentTimestampNaive):


@pytest.mark.skip(reason="arrays not supported")
class TestArrayAppendSQLServer(BaseArrayAppend):
class TestArrayAppendSQLServer(BaseFixedMacro, BaseArrayAppend):
pass


@pytest.mark.skip(reason="arrays not supported")
class TestArrayConcatSQLServer(BaseArrayConcat):
@pytest.mark.skip(reason="arrays not supporteTd")
class TestArrayConcatSQLServer(BaseFixedMacro, BaseArrayConcat):
pass


@pytest.mark.skip(reason="arrays not supported")
class TestArrayConstructSQLServer(BaseArrayConstruct):
class TestArrayConstructSQLServer(BaseFixedMacro, BaseArrayConstruct):
pass