-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
603a2bd
commit 969bbb9
Showing
27 changed files
with
652 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,4 @@ | |
|
||
|
||
|
||
version = "1.7.13" | ||
version = "1.8.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,4 +159,4 @@ | |
{%- if not loop.last %} or {% endif -%} | ||
{%- endfor -%} | ||
) | ||
{%- endmacro %} | ||
{%- endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
dbt/include/vertica/macros/materializations/tests/unit.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{%- materialization unit, default -%} | ||
|
||
{% set relations = [] %} | ||
|
||
{% set expected_rows = config.get('expected_rows') %} | ||
{% set expected_sql = config.get('expected_sql') %} | ||
{% set tested_expected_column_names = expected_rows[0].keys() if (expected_rows | length ) > 0 else get_columns_in_query(sql) %} %} | ||
|
||
{%- set target_relation = this.incorporate(type='table') -%} | ||
{%- set temp_relation = make_temp_relation(target_relation)-%} | ||
{% do run_query(get_create_table_as_sql(True, temp_relation, get_empty_subquery_sql(sql))) %} | ||
{%- set columns_in_relation = adapter.get_columns_in_relation(temp_relation) -%} | ||
{%- set column_name_to_data_types = {} -%} | ||
{%- for column in columns_in_relation -%} | ||
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%} | ||
{%- endfor -%} | ||
|
||
{% if not expected_sql %} | ||
{% set expected_sql = get_expected_sql(expected_rows, column_name_to_data_types) %} | ||
{% endif %} | ||
{% set unit_test_sql = get_unit_test_sql(sql, expected_sql, tested_expected_column_names) %} | ||
|
||
{% call statement('main', fetch_result=True) -%} | ||
|
||
{{ unit_test_sql }} | ||
|
||
{%- endcall %} | ||
|
||
{% do adapter.drop_relation(temp_relation) %} | ||
|
||
{{ return({'relations': relations}) }} | ||
|
||
{%- endmaterialization -%} |
104 changes: 104 additions & 0 deletions
104
dbt/include/vertica/macros/unit_test_sql/get_fixture_sql.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{% macro get_fixture_sql(rows, column_name_to_data_types) %} | ||
-- Fixture for {{ model.name }} | ||
{% set default_row = {} %} | ||
|
||
{%- if not column_name_to_data_types -%} | ||
{#-- Use defer_relation IFF it is available in the manifest and 'this' is missing from the database --#} | ||
{%- set this_or_defer_relation = defer_relation if (defer_relation and not load_relation(this)) else this -%} | ||
{%- set columns_in_relation = adapter.get_columns_in_relation(this_or_defer_relation) -%} | ||
|
||
{%- set column_name_to_data_types = {} -%} | ||
{%- for column in columns_in_relation -%} | ||
{#-- This needs to be a case-insensitive comparison --#} | ||
{%- do column_name_to_data_types.update({column.name|lower: column.data_type}) -%} | ||
{%- endfor -%} | ||
{%- endif -%} | ||
|
||
{%- if not column_name_to_data_types -%} | ||
{{ exceptions.raise_compiler_error("Not able to get columns for unit test '" ~ model.name ~ "' from relation " ~ this ~ " because the relation doesn't exist") }} | ||
{%- endif -%} | ||
|
||
{%- for column_name, column_type in column_name_to_data_types.items() -%} | ||
{%- do default_row.update({column_name: (safe_cast("null", column_type) | trim )}) -%} | ||
{%- endfor -%} | ||
|
||
{{ validate_fixture_rows(rows, row_number) }} | ||
|
||
{%- for row in rows -%} | ||
{%- set formatted_row = format_row(row, column_name_to_data_types) -%} | ||
{%- set default_row_copy = default_row.copy() -%} | ||
{%- do default_row_copy.update(formatted_row) -%} | ||
select | ||
{%- for column_name, column_value in default_row_copy.items() %} {{ column_value }} as {{ column_name }}{% if not loop.last -%}, {%- endif %} | ||
{%- endfor %} | ||
{%- if not loop.last %} | ||
union all | ||
{% endif %} | ||
{%- endfor -%} | ||
|
||
{%- if (rows | length) == 0 -%} | ||
select | ||
{%- for column_name, column_value in default_row.items() %} {{ column_value }} as {{ column_name }}{% if not loop.last -%},{%- endif %} | ||
{%- endfor %} | ||
limit 0 | ||
{%- endif -%} | ||
{% endmacro %} | ||
|
||
|
||
{% macro get_expected_sql(rows, column_name_to_data_types) %} | ||
|
||
{%- if (rows | length) == 0 -%} | ||
select * from dbt_internal_unit_test_actual | ||
limit 0 | ||
{%- else -%} | ||
{%- for row in rows -%} | ||
{%- set formatted_row = format_row(row, column_name_to_data_types) -%} | ||
select | ||
{%- for column_name, column_value in formatted_row.items() %} {{ column_value }} as {{ column_name }}{% if not loop.last -%}, {%- endif %} | ||
{%- endfor %} | ||
{%- if not loop.last %} | ||
union all | ||
{% endif %} | ||
{%- endfor -%} | ||
{%- endif -%} | ||
|
||
{% endmacro %} | ||
|
||
{%- macro format_row(row, column_name_to_data_types) -%} | ||
{#-- generate case-insensitive formatted row --#} | ||
{% set formatted_row = {} %} | ||
{%- for column_name, column_value in row.items() -%} | ||
{% set column_name = column_name|lower %} | ||
|
||
{%- if column_name not in column_name_to_data_types %} | ||
{#-- if user-provided row contains column name that relation does not contain, raise an error --#} | ||
{% set fixture_name = "expected output" if model.resource_type == 'unit_test' else ("'" ~ model.name ~ "'") %} | ||
{{ exceptions.raise_compiler_error( | ||
"Invalid column name: '" ~ column_name ~ "' in unit test fixture for " ~ fixture_name ~ "." | ||
"\nAccepted columns for " ~ fixture_name ~ " are: " ~ (column_name_to_data_types.keys()|list) | ||
) }} | ||
{%- endif -%} | ||
|
||
{%- set column_type = column_name_to_data_types[column_name] %} | ||
|
||
{#-- sanitize column_value: wrap yaml strings in quotes, apply cast --#} | ||
{%- set column_value_clean = column_value -%} | ||
{%- if column_value is string -%} | ||
{%- set column_value_clean = dbt.string_literal(dbt.escape_single_quotes(column_value)) -%} | ||
{%- elif column_value is none -%} | ||
{%- set column_value_clean = 'null' -%} | ||
{%- endif -%} | ||
|
||
{%- set row_update = {column_name: safe_cast(column_value_clean, column_type) } -%} | ||
{%- do formatted_row.update(row_update) -%} | ||
{%- endfor -%} | ||
{{ return(formatted_row) }} | ||
{%- endmacro -%} | ||
|
||
{%- macro validate_fixture_rows(rows, row_number) -%} | ||
{{ return(adapter.dispatch('validate_fixture_rows', 'dbt')(rows, row_number)) }} | ||
{%- endmacro -%} | ||
|
||
{%- macro default__validate_fixture_rows(rows, row_number) -%} | ||
{# This is an abstract method for adapter overrides as needed #} | ||
{%- endmacro -%} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% macro cast(field, type) %} | ||
{{ return(adapter.dispatch('cast', 'dbt') (field, type)) }} | ||
{% endmacro %} | ||
|
||
{% macro vertica__cast(field, type) %} | ||
cast({{field}} as {{type}}) | ||
{% endmacro %} |
Oops, something went wrong.