Skip to content

Commit e21e44e

Browse files
committed
feat: expand show_sample_rows to model, column, and test level independently of PII
1 parent 0c7136a commit e21e44e

3 files changed

Lines changed: 89 additions & 40 deletions

File tree

macros/edr/materializations/test/test.sql

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@
7676
{% endif %}
7777

7878
{% if disable_test_samples %} {% set sample_limit = 0 %}
79-
{% elif not elementary.is_show_sample_rows_table(flattened_test) %}
80-
{% if elementary.get_config_var("enable_samples_on_show_sample_rows_tags") %}
81-
{% set sample_limit = 0 %}
82-
{% elif elementary.is_pii_table(flattened_test) %} {% set sample_limit = 0 %}
83-
{% elif elementary.should_disable_sampling_for_pii(flattened_test) %}
84-
{% set sample_limit = 0 %}
85-
{% endif %}
79+
{% elif elementary.should_show_sample_rows(flattened_test) %} {# show_sample_rows tag overrides default-hide #}
80+
{% elif elementary.get_config_var("enable_samples_on_show_sample_rows_tags") %}
81+
{% set sample_limit = 0 %}
82+
{% elif elementary.is_pii_table(flattened_test) %} {% set sample_limit = 0 %}
83+
{% elif elementary.should_disable_sampling_for_pii(flattened_test) %}
84+
{% set sample_limit = 0 %}
8685
{% endif %}
8786

8887
{% set result_rows = elementary.query_test_result_rows(

macros/edr/system/system_utils/is_show_sample_rows_table.sql

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{% macro should_show_sample_rows(flattened_test) %}
2+
{% if not elementary.get_config_var("enable_samples_on_show_sample_rows_tags") %}
3+
{% do return(false) %}
4+
{% endif %}
5+
6+
{% set raw_show_tags = elementary.get_config_var("show_sample_rows_tags") %}
7+
{% if raw_show_tags is string %} {% set show_tags = [raw_show_tags | lower] %}
8+
{% else %} {% set show_tags = (raw_show_tags or []) | map("lower") | list %}
9+
{% endif %}
10+
11+
{# Resolve PII tags once — only relevant when PII hiding is also enabled #}
12+
{% set check_pii = elementary.get_config_var("disable_samples_on_pii_tags") %}
13+
{% if check_pii %}
14+
{% set raw_pii_tags = elementary.get_config_var("pii_tags") %}
15+
{% if raw_pii_tags is string %} {% set pii_tags = [raw_pii_tags | lower] %}
16+
{% else %} {% set pii_tags = (raw_pii_tags or []) | map("lower") | list %}
17+
{% endif %}
18+
{% else %} {% set pii_tags = [] %}
19+
{% endif %}
20+
21+
{# Model-level check #}
22+
{% set raw_model_tags = elementary.insensitive_get_dict_value(
23+
flattened_test, "model_tags", []
24+
) %}
25+
{% if raw_model_tags is string %} {% set model_tags = [raw_model_tags | lower] %}
26+
{% else %} {% set model_tags = (raw_model_tags or []) | map("lower") | list %}
27+
{% endif %}
28+
{% if elementary.lists_intersection(model_tags, show_tags) | length > 0 %}
29+
{% if check_pii and elementary.lists_intersection(
30+
model_tags, pii_tags
31+
) | length > 0 %}
32+
{% do return(false) %}
33+
{% endif %}
34+
{% do return(true) %}
35+
{% endif %}
36+
37+
{# Test-level check #}
38+
{% set raw_test_tags = elementary.insensitive_get_dict_value(
39+
flattened_test, "tags", []
40+
) %}
41+
{% if raw_test_tags is string %} {% set test_tags = [raw_test_tags | lower] %}
42+
{% else %} {% set test_tags = (raw_test_tags or []) | map("lower") | list %}
43+
{% endif %}
44+
{% if elementary.lists_intersection(test_tags, show_tags) | length > 0 %}
45+
{% if check_pii and elementary.lists_intersection(
46+
model_tags, pii_tags
47+
) | length > 0 %}
48+
{% do return(false) %}
49+
{% endif %}
50+
{% do return(true) %}
51+
{% endif %}
52+
53+
{# Column-level check: only the test's target column #}
54+
{% set test_column_name = elementary.insensitive_get_dict_value(
55+
flattened_test, "test_column_name"
56+
) %}
57+
{% if test_column_name %}
58+
{% set parent_model_unique_id = elementary.insensitive_get_dict_value(
59+
flattened_test, "parent_model_unique_id"
60+
) %}
61+
{% set parent_model = elementary.get_node(parent_model_unique_id) %}
62+
{% if parent_model %}
63+
{% set column_nodes = parent_model.get("columns", {}) %}
64+
{% for col_name, col_node in column_nodes.items() %}
65+
{% if col_name | lower == test_column_name | lower %}
66+
{% set col_tags = elementary.get_column_tags(col_node) %}
67+
{% if elementary.lists_intersection(
68+
col_tags, show_tags
69+
) | length > 0 %}
70+
{% if check_pii and elementary.lists_intersection(
71+
col_tags, pii_tags
72+
) | length > 0 %}
73+
{% do return(false) %}
74+
{% endif %}
75+
{% do return(true) %}
76+
{% endif %}
77+
{% endif %}
78+
{% endfor %}
79+
{% endif %}
80+
{% endif %}
81+
82+
{% do return(false) %}
83+
{% endmacro %}

0 commit comments

Comments
 (0)