Skip to content

Commit

Permalink
add table level test
Browse files Browse the repository at this point in the history
Signed-off-by: jaga-sknt <[email protected]>
  • Loading branch information
jagabass committed Oct 15, 2024
1 parent 71e5050 commit 0b15945
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@
labels={
"key1": "value1",
"key2": "value2",
},
data_tests={
"test1": {
"key1": "value1",
},
"test2": {
"key2": "value2",
"key3": "value3",
}
},
tests={
"test1": {
"key4": "value4",
"key5": "value5",
}
}
) -%}

Expand All @@ -86,6 +101,15 @@ models:
description: |-
Sample description
tags: ['tag1']
data_tests:
- test1:
key1: value1
- test2:
key2: value2
key3: value3
- test1:
key4: value4
key5: value5
meta:
key1: value1
key2: value2
Expand Down
32 changes: 29 additions & 3 deletions macros/codegen/generate_secured_model_schema_v2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
description=none,
columns={},
tags=[],
labels={}
labels={},
data_tests={},
tests={}
) %}
{{- return(adapter.dispatch('generate_secured_model_schema_v2', 'dbt_data_privacy')(
objective=objective,
Expand All @@ -18,7 +20,9 @@
description=description,
columns=columns,
tags=tags,
labels=labels
labels=labels,
data_tests=data_tests,
tests=tests
)) -}}
{% endmacro %}

Expand All @@ -31,7 +35,9 @@
description=none,
columns=[],
tags=[],
labels={}
labels={},
data_tests={},
tests={}
) %}

{% if columns | length == 0 %}
Expand All @@ -58,6 +64,26 @@ models:
tags: {{ tags | unique | sort | list }}
{%- endif %}
{%- if labels | length > 0 %}
{#- We support both `data_tests` and `tests` for a while -#}
{#- TODO: remove `tests` after dbt no longer supports it -#}
{%- set combined_tests = [] %}
{%- for test_name, test_content in data_tests.items() %}
{%- do combined_tests.append({test_name: [test_content]}) %}
{%- endfor %}
{%- for test_name, test_content in tests.items() %}
{%- do combined_tests.append({test_name: [test_content]}) %}
{%- endfor %}
{%- if combined_tests | length > 0 %}
data_tests:
{%- for test in combined_tests %}
- {{ test.keys() | first }}:
{%- for content in test.values() | first %}
{%- for key, value in content.items() %}
{{ key }}: {{ value }}
{%- endfor %}
{%- endfor %}
{%- endfor %}
{%- endif %}
meta: {%- for k, v in labels.items() %}
{{ k }}: {{ v }}
{%- endfor %}
Expand Down

0 comments on commit 0b15945

Please sign in to comment.