From a686ee8692bbd646e754d91d9b9a0a695c8cadf8 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Tue, 21 Nov 2023 18:22:10 -0500 Subject: [PATCH 1/4] Init unit_testing tests --- .../unit_testing/test_unit_testing_types.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/functional/adapter/unit_testing/test_unit_testing_types.py diff --git a/tests/functional/adapter/unit_testing/test_unit_testing_types.py b/tests/functional/adapter/unit_testing/test_unit_testing_types.py new file mode 100644 index 000000000..a548bf4f6 --- /dev/null +++ b/tests/functional/adapter/unit_testing/test_unit_testing_types.py @@ -0,0 +1,19 @@ +import pytest +from dbt.tests.adapter.unit_testing.test_unit_testing_types import BaseUnitTestingTypes + + +class TestBigQueryUnitTestingTypes(BaseUnitTestingTypes): + @pytest.fixture + def data_types(self): + # sql_value, yaml_value + return [ + ["1", "1"], + ["'1'", "1"], + ["cast('true' as boolean)", "true"], + ["cast('2019-01-01' as date)", "2019-01-01"], + ["cast('2013-11-03 00:00:00-07' as TIMESTAMP)", "2013-11-03 00:00:00-07"], + ["['a','b','c']", "['a','b','c']"], + ["[1,2,3]", "[1,2,3]"], + ["cast(1 as NUMERIC)", "1"], + ["""'{"name": "Cooper", "forname": "Alice"}'""", """'{"name": "Cooper", "forname": "Alice"}'"""], + ] From 7173c5184a50d760d1f3d662c0f54e58b1779db3 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Tue, 21 Nov 2023 18:22:33 -0500 Subject: [PATCH 2/4] Repoint dbt-core dev branch --- dev-requirements.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index c37c088f4..8acb22fad 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ # install latest changes in dbt-core # TODO: how to automate switching from develop to version branches? -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-core&subdirectory=core -git+https://github.com/dbt-labs/dbt-core.git#egg=dbt-tests-adapter&subdirectory=tests/adapter +git+https://github.com/dbt-labs/dbt-core.git@jerco/unit-test-case-insensitivity#egg=dbt-core&subdirectory=core +git+https://github.com/dbt-labs/dbt-core.git@jerco/unit-test-case-insensitivity#egg=dbt-tests-adapter&subdirectory=tests/adapter # if version 1.x or greater -> pin to major version # if version 0.x -> pin to minor From a87c136a5b5f37d79e2b9cfb632708fb2d3f61ec Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Tue, 21 Nov 2023 18:22:42 -0500 Subject: [PATCH 3/4] Update TYPE_LABELS + safe_cast --- dbt/adapters/snowflake/column.py | 5 +++++ dbt/include/snowflake/macros/utils/safe_cast.sql | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/dbt/adapters/snowflake/column.py b/dbt/adapters/snowflake/column.py index e5d07b82b..5a7c3b6fc 100644 --- a/dbt/adapters/snowflake/column.py +++ b/dbt/adapters/snowflake/column.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +from typing import Dict, ClassVar from dbt.adapters.base.column import Column from dbt.exceptions import DbtRuntimeError @@ -6,6 +7,10 @@ @dataclass class SnowflakeColumn(Column): + TYPE_LABELS: ClassVar[Dict[str, str]] = { + "FIXED": "NUMERIC", + } + def is_integer(self) -> bool: # everything that smells like an int is actually a NUMBER(38, 0) return False diff --git a/dbt/include/snowflake/macros/utils/safe_cast.sql b/dbt/include/snowflake/macros/utils/safe_cast.sql index 65f9265a2..b3b9c260e 100644 --- a/dbt/include/snowflake/macros/utils/safe_cast.sql +++ b/dbt/include/snowflake/macros/utils/safe_cast.sql @@ -1,3 +1,10 @@ {% macro snowflake__safe_cast(field, type) %} + {#-- Dumb for now --#} + {% if type|lower in ['array', 'variant'] and field is string %} + cast(try_parse_json({{field}}) as {{type}}) + {% elif field is string %} try_cast({{field}} as {{type}}) + {% else %} + cast({{field}} as {{type}}) + {% endif %} {% endmacro %} From 13eb2d2fd6139507a200ec14f50d8917228c11a6 Mon Sep 17 00:00:00 2001 From: Jeremy Cohen Date: Tue, 21 Nov 2023 19:16:09 -0500 Subject: [PATCH 4/4] Fix model contract tests --- tests/functional/adapter/test_constraints.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/adapter/test_constraints.py b/tests/functional/adapter/test_constraints.py index 12c70a6eb..4f4412c83 100644 --- a/tests/functional/adapter/test_constraints.py +++ b/tests/functional/adapter/test_constraints.py @@ -66,7 +66,7 @@ class SnowflakeColumnEqualSetup: @pytest.fixture def int_type(self): - return "FIXED" + return "NUMERIC" @pytest.fixture def schema_int_type(self):