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

first pass: unit test typing #839

Closed
wants to merge 4 commits into from
Closed

first pass: unit test typing #839

wants to merge 4 commits into from

Conversation

jtcohen6
Copy link
Contributor

requires case-insensitivity changes in dbt-labs/dbt-core#9131

@jtcohen6 jtcohen6 requested a review from MichelleArk November 21, 2023 23:23
@cla-bot cla-bot bot added the cla:yes label Nov 21, 2023
Copy link
Contributor

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the dbt-snowflake contributing guide.


from dbt.adapters.base.column import Column
from dbt.exceptions import DbtRuntimeError


@dataclass
class SnowflakeColumn(Column):
TYPE_LABELS: ClassVar[Dict[str, str]] = {
"FIXED": "NUMERIC",
Copy link
Contributor Author

@jtcohen6 jtcohen6 Nov 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this means model contract errors will now say NUMERIC instead of FIXED — and they will say this for all fixed-precision numeric types, including integers, because INT on Snowflake is just an alias for NUMERIC(38,0).

Compilation Error in model my_model (models/my_model.sql)
  This model has an enforced contract that failed.
  Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.

  | column_name | definition_type | contract_type | mismatch_reason    |
  | ----------- | --------------- | ------------- | ------------------ |
  | ID          | NUMERIC         | TEXT          | data type mismatch |

This is more helpful IMO, because numeric is a real type that Snowflake will actually allow you to write in SQL!

Floating-point types will still appear as REAL, and dbt will detect mismatch:

Compilation Error in model my_model (models/my_model.sql)
  This model has an enforced contract that failed.
  Please ensure the name, data_type, and number of columns in your contract match the columns in your model's definition.

  | column_name | definition_type | contract_type | mismatch_reason    |
  | ----------- | --------------- | ------------- | ------------------ |
  | ID          | NUMERIC         | REAL          | data type mismatch |


from dbt.adapters.base.column import Column
from dbt.exceptions import DbtRuntimeError


@dataclass
class SnowflakeColumn(Column):
TYPE_LABELS: ClassVar[Dict[str, str]] = {
Copy link
Contributor Author

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 has STRING -> TEXT. I haven't included it here because these are true aliases on Snowflake.

@jtcohen6 jtcohen6 closed this Feb 19, 2024
@mikealfare mikealfare deleted the jerco/unit-test-types branch July 17, 2024 23:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant