diff --git a/.changes/unreleased/Features-20240412-192040.yaml b/.changes/unreleased/Features-20240412-192040.yaml new file mode 100644 index 00000000..dc3f6799 --- /dev/null +++ b/.changes/unreleased/Features-20240412-192040.yaml @@ -0,0 +1,6 @@ +kind: Features +body: Cross-database `cast` macro +time: 2024-04-12T19:20:40.904842-06:00 +custom: + Author: MichelleArk dbeatty10 + Issue: "84" diff --git a/dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py b/dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py new file mode 100644 index 00000000..fe29c706 --- /dev/null +++ b/dbt-tests-adapter/dbt/tests/adapter/utils/fixture_cast.py @@ -0,0 +1,33 @@ +# cast + +seeds__data_cast_csv = """field,output +abc,abc +123,123 +, +""" + + +models__test_cast_sql = """ +with data as ( + + select * from {{ ref('data_cast') }} + +) + +select + {{ cast('field', api.Column.translate_type('string')) }} as actual, + output as expected + +from data +""" + + +models__test_cast_yml = """ +version: 2 +models: + - name: test_cast + data_tests: + - assert_equal: + actual: actual + expected: expected +""" diff --git a/dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py b/dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py new file mode 100644 index 00000000..686b7697 --- /dev/null +++ b/dbt-tests-adapter/dbt/tests/adapter/utils/test_cast.py @@ -0,0 +1,23 @@ +import pytest + +from dbt.tests.adapter.utils import base_utils, fixture_cast + + +class BaseCast(base_utils.BaseUtils): + @pytest.fixture(scope="class") + def seeds(self): + return {"data_cast.csv": fixture_cast.seeds__data_cast_csv} + + @pytest.fixture(scope="class") + def models(self): + return { + "test_cast.yml": fixture_cast.models__test_cast_yml, + "test_cast.sql": self.interpolate_macro_namespace( + self.interpolate_macro_namespace(fixture_cast.models__test_cast_sql, "cast"), + "type_string", + ), + } + + +class TestCast(BaseCast): + pass