Skip to content

Commit

Permalink
Fix column transformations for Snowflake
Browse files Browse the repository at this point in the history
  • Loading branch information
psousa50 committed Jan 11, 2024
1 parent bb5fbd1 commit d4bfa65
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion integration-tests/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ vars:
unit_tests_config:
column_transformations:
model_for_column_transformations:
b: upper(b)
column_a: round(##column##, 5)
model_references_model_with_structs:
a: to_json_string(##column##)
verbose: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
select a / 3 as a, b from {{ dbt_unit_testing.ref ('model_a') }}
select a / 3 as column_a, b as column_b from {{ dbt_unit_testing.ref ('model_a') }}
23 changes: 20 additions & 3 deletions integration-tests/tests/unit/model_for_column_transformations.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{{
config(
tags=['unit-test', 'bigquery', 'snowflake', 'postgres']
tags=['unit-test', 'bigquery', 'postgres']
)
}}

{% set column_transformations = {
"a": "round(##column##, 4)"
"column_a": "round(##column##, 4)",
"column_b": "upper(##column##)"
}
%}

Expand All @@ -14,6 +15,22 @@
select 10.0 as a, 'lower' as b
{% endcall %}
{% call dbt_unit_testing.expect() %}
select 3.3333 as a, 'LOWER' as b
select 3.3333 as column_a, 'LOWER' as column_b
{% endcall %}
{% endcall %}

UNION ALL

{% set column_transformations = {
"column_b": "upper(##column##)"
}
%}

{% call dbt_unit_testing.test('model_for_column_transformations', 'should merge config from dbt_project', options={"column_transformations": column_transformations}) %}
{% call dbt_unit_testing.mock_ref ('model_a') %}
select 10.0 as a, 'lower' as b
{% endcall %}
{% call dbt_unit_testing.expect() %}
select 3.33333 as column_a, 'LOWER' as column_b
{% endcall %}
{% endcall %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{
config(
tags=['unit-test', 'snowflake']
)
}}

{% set column_transformations = {
"COLUMN_A": "round(##column##, 4)",
"COLUMN_B": "upper(##column##)"
}
%}

{% call dbt_unit_testing.test('model_for_column_transformations', options={"column_transformations": column_transformations}) %}
{% call dbt_unit_testing.mock_ref ('model_a') %}
select 10.0 as a, 'lower' as b
{% endcall %}
{% call dbt_unit_testing.expect() %}
select 3.3333 as COLUMN_A, 'LOWER' as column_b
{% endcall %}
{% endcall %}
4 changes: 2 additions & 2 deletions run-tests-helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ function run_tests() {
if [ "$PROFILE" == "postgres" ]; then
VERSIONS="1.3.4 1.4.6 1.5.4 1.7.4"
elif [ "$PROFILE" == "bigquery" ]; then
VERSIONS="1.3.2"
VERSIONS="1.7.2"
elif [ "$PROFILE" == "snowflake" ]; then
VERSIONS="1.3.1"
VERSIONS="1.7.1"
else
echo "Invalid profile name: $PROFILE"
exit 1
Expand Down

0 comments on commit d4bfa65

Please sign in to comment.