-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[spike] [Snowflake] Support complex types unit testing #9131
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
{% set columns_in_relation = adapter.get_column_schema_from_query(get_empty_subquery_sql(sql)) %} | ||
{%- set column_name_to_data_types = {} -%} | ||
{%- for column in columns_in_relation -%} | ||
{%- do column_name_to_data_types.update({column.name: column.data_type}) -%} | ||
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%} | ||
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. This is naively assuming that the user has provided their columns in all lowercase. We'd obviously want to |
||
{%- endfor -%} | ||
|
||
{% set unit_test_sql = get_unit_test_sql(sql, get_expected_sql(expected_rows, column_name_to_data_types), tested_expected_column_names) %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
|
||
{%- set column_name_to_data_types = {} -%} | ||
{%- for column in columns_in_relation -%} | ||
{%- do column_name_to_data_types.update({column.name: column.data_type}) -%} | ||
{#-- This needs to be a case-insensitive comparison --#} | ||
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%} | ||
{%- endfor -%} | ||
{%- endif -%} | ||
|
||
|
@@ -67,7 +68,7 @@ union all | |
{%- for column_name, column_value in row.items() -%} | ||
{% set row_update = {column_name: column_value} %} | ||
{%- if column_value is string -%} | ||
{%- set row_update = {column_name: safe_cast(dbt.string_literal(column_value), column_name_to_data_types[column_name]) } -%} | ||
{%- set row_update = {column_name: safe_cast(dbt.string_literal(dbt.escape_single_quotes(column_value)), column_name_to_data_types[column_name]) } -%} | ||
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. So that it's: select cast(parse_json('[\'a\',\'b\',\'c\']') as ARRAY) AS tested_column Rather than: select cast(parse_json('['a','b','c']') as ARRAY) AS tested_column |
||
{%- elif column_value is none -%} | ||
{%- set row_update = {column_name: safe_cast('null', column_name_to_data_types[column_name]) } -%} | ||
{%- else -%} | ||
|
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.
If a column name is quoted, Snowflake will preserve its case. The alternative is to lowercase column names in the agate result before we access it here:
dbt-core/core/dbt/task/unit_test.py
Line 162 in e001991
Otherwise, we get one of these: