-
Notifications
You must be signed in to change notification settings - Fork 179
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
first pass: unit test typing #839
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
from dataclasses import dataclass | ||
from typing import Dict, ClassVar | ||
|
||
from dbt.adapters.base.column import Column | ||
from dbt.exceptions import DbtRuntimeError | ||
|
||
|
||
@dataclass | ||
class SnowflakeColumn(Column): | ||
TYPE_LABELS: ClassVar[Dict[str, str]] = { | ||
"FIXED": "NUMERIC", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this means model contract errors will now say
This is more helpful IMO, because Floating-point types will still appear as
|
||
} | ||
|
||
def is_integer(self) -> bool: | ||
# everything that smells like an int is actually a NUMBER(38, 0) | ||
return False | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"}'"""], | ||
] |
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.
The parent/default
Column.TYPE_LABELS
hasSTRING -> TEXT
. I haven't included it here because these are true aliases on Snowflake.