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

add macro to get columns #516

Merged
merged 13 commits into from
Mar 28, 2022
Prev Previous commit
Next Next commit
add tests
  • Loading branch information
patkearns10 committed Mar 24, 2022
commit 820853f2dfea649501fa394e305335901ac391cf
4 changes: 4 additions & 0 deletions integration_tests/data/sql/data_star_uppercase_columns.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FIELD_1,FIELD_2,FIELD_3
A,B,C
D,E,F
G,H,I
32 changes: 32 additions & 0 deletions integration_tests/macros/assert_equal_values.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% macro assert_equal_values(actual_object, expected_object) %}
{% if not execute %}

{# pass #}

{% elif actual_object != expected_object %}

{% set msg %}
Expected did not match actual

-----------
Actual:
-----------
--->{{ actual_object }}<---

-----------
Expected:
-----------
--->{{ expected_object }}<---
patkearns10 marked this conversation as resolved.
Show resolved Hide resolved

{% endset %}

{{ log(msg, info=True) }}

select 'fail'

{% else %}

select 'ok' limit 0
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be {{ limit_zero() }} - not all databases support limit clauses (notably T-SQL)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!
@joellabes -- this is no longer required, as I switched to using the seed/model method. Should I remove this file then?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that makes sense - the Core team are working on a wider testing suite that I hope will also cover packages - if that wasn't in the pipeline then I'd suggest we kept this around because "we’d need it one day" but I think we'll have a more long term solution soon.


{% endif %}
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% set actual_output = dbt_utils.get_filtered_columns_in_relation(from= ref('data_star_uppercase_columns'), except=['field_1'], output_lower=True) %}

{% set expected_output = ['field_2', 'field_3'] %}

{{ assert_equal_values (actual_output | trim, expected_output | trim) }}
7 changes: 7 additions & 0 deletions integration_tests/tests/test_star_output_lower.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% set actual_output = dbt_utils.star(from=ref('data_star_uppercase_columns'), except=['field_1', 'field_2'], prefix='test_', output_lower=True ) %}

{% set expected_output %}
"field_3" as "test_field_3"
{% endset %}

{{ assert_equal_values (actual_output | trim, expected_output | trim) }}