-
Notifications
You must be signed in to change notification settings - Fork 124
feat: add show_sample_rows tag and extend PII protection to model, column, and test level #973
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
Open
joostboon
wants to merge
12
commits into
master
Choose a base branch
from
feat/add-show-sample-rows-tag
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
df22ed5
feat: add show_sample_rows tag to override PII-based sample hiding
joostboon dfc2003
fix: apply sqlfmt formatting to get_pii_columns_from_parent_model.sql
joostboon ea16e47
chore: add .claude/ to .gitignore
joostboon 7dddc77
fix: use string check for show_sample_rows_tags normalization to avoi…
joostboon 4d7179b
fix: pii tag takes precedence over show_sample_rows tag
joostboon 54faaaa
fix: hide samples by default when enable_samples_on_show_sample_rows_…
joostboon 57fe5c2
feat: expand show_sample_rows to model, column, and test level indepe…
joostboon bddae5d
feat: add test-level pii tag support for consistent behavior with sho…
joostboon 77e5034
docs(code): add explanatory comments to show_sample_rows and PII samp…
joostboon 19f2367
fix: address review findings in show_sample_rows and PII macros
joostboon 605bdd0
style: apply sqlfmt formatting
joostboon d5fbeb3
fix: handle Vertica Decimal special values (Infinity/NaN) in query ru…
joostboon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,6 +27,9 @@ __pycache__/ | |
|
|
||
| # vscode | ||
| .vscode/ | ||
|
|
||
| # Claude Code | ||
| .claude/ | ||
| dbt_internal_packages/ | ||
|
|
||
| /package-lock.yml | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
| {# | ||
| Complements is_pii_table (model-level) and should_disable_sampling_for_pii | ||
| (column-level) by adding test-level PII tag support. A test tagged with a PII | ||
| tag will have its samples disabled, consistent with the other two levels. | ||
| #} | ||
| {% macro is_pii_test(flattened_test) %} | ||
| {% if not elementary.get_config_var("disable_samples_on_pii_tags") %} | ||
| {% do return(false) %} | ||
| {% endif %} | ||
|
|
||
| {% set raw_pii_tags = elementary.get_config_var("pii_tags") %} | ||
| {% if raw_pii_tags is string %} {% set pii_tags = [raw_pii_tags | lower] %} | ||
| {% else %} {% set pii_tags = (raw_pii_tags or []) | map("lower") | list %} | ||
| {% endif %} | ||
|
|
||
| {% set raw_test_tags = elementary.insensitive_get_dict_value( | ||
| flattened_test, "tags", [] | ||
| ) %} | ||
| {% if raw_test_tags is string %} {% set test_tags = [raw_test_tags | lower] %} | ||
| {% else %} {% set test_tags = (raw_test_tags or []) | map("lower") | list %} | ||
| {% endif %} | ||
|
|
||
| {% do return(elementary.lists_intersection(test_tags, pii_tags) | length > 0) %} | ||
| {% endmacro %} |
112 changes: 112 additions & 0 deletions
112
macros/edr/system/system_utils/should_show_sample_rows.sql
This file contains hidden or 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,112 @@ | ||
| {# | ||
| Inverse of PII protection: when enable_samples_on_show_sample_rows_tags is true, | ||
| samples are hidden by default and only shown when the show_sample_rows tag is present. | ||
|
|
||
| Checks three levels in order: model → test → column (test's target column only). | ||
| Returns true if any level has a matching show_sample_rows tag. | ||
|
|
||
| PII precedence: if disable_samples_on_pii_tags is also enabled and the model | ||
| or column has a PII tag, PII wins and this returns false. A model-level PII | ||
| tag blocks show_sample_rows at every level (model, test, and column). | ||
|
|
||
| All tag matching is case-insensitive (tags are normalized to lowercase). | ||
| #} | ||
| {% macro should_show_sample_rows(flattened_test) %} | ||
| {% if not elementary.get_config_var("enable_samples_on_show_sample_rows_tags") %} | ||
| {% do return(false) %} | ||
| {% endif %} | ||
|
|
||
| {% set raw_show_tags = elementary.get_config_var("show_sample_rows_tags") %} | ||
| {% if raw_show_tags is string %} {% set show_tags = [raw_show_tags | lower] %} | ||
| {% else %} {% set show_tags = (raw_show_tags or []) | map("lower") | list %} | ||
| {% endif %} | ||
|
|
||
| {# | ||
| Resolve PII tags once upfront. We use `is string` (not `is iterable`) because | ||
| strings are iterable in Jinja — iterating a string gives individual characters. | ||
| #} | ||
| {% set check_pii = elementary.get_config_var("disable_samples_on_pii_tags") %} | ||
| {% if check_pii %} | ||
| {% set raw_pii_tags = elementary.get_config_var("pii_tags") %} | ||
| {% if raw_pii_tags is string %} {% set pii_tags = [raw_pii_tags | lower] %} | ||
| {% else %} {% set pii_tags = (raw_pii_tags or []) | map("lower") | list %} | ||
| {% endif %} | ||
| {% else %} {% set pii_tags = [] %} | ||
| {% endif %} | ||
|
|
||
| {# Model-level: show_sample_rows on the model applies to all its tests #} | ||
| {% set raw_model_tags = elementary.insensitive_get_dict_value( | ||
| flattened_test, "model_tags", [] | ||
| ) %} | ||
| {% if raw_model_tags is string %} {% set model_tags = [raw_model_tags | lower] %} | ||
| {% else %} {% set model_tags = (raw_model_tags or []) | map("lower") | list %} | ||
| {% endif %} | ||
| {% if elementary.lists_intersection(model_tags, show_tags) | length > 0 %} | ||
| {# PII on the model takes precedence over show_sample_rows on the same model #} | ||
| {% if check_pii and elementary.lists_intersection( | ||
| model_tags, pii_tags | ||
| ) | length > 0 %} | ||
| {% do return(false) %} | ||
| {% endif %} | ||
| {% do return(true) %} | ||
| {% endif %} | ||
|
|
||
| {# Test-level: show_sample_rows on the test definition itself #} | ||
| {% set raw_test_tags = elementary.insensitive_get_dict_value( | ||
| flattened_test, "tags", [] | ||
| ) %} | ||
| {% if raw_test_tags is string %} {% set test_tags = [raw_test_tags | lower] %} | ||
| {% else %} {% set test_tags = (raw_test_tags or []) | map("lower") | list %} | ||
| {% endif %} | ||
| {% if elementary.lists_intersection(test_tags, show_tags) | length > 0 %} | ||
| {# If the model itself is PII-tagged, respect that even for test-level overrides #} | ||
| {% if check_pii and elementary.lists_intersection( | ||
| model_tags, pii_tags | ||
| ) | length > 0 %} | ||
| {% do return(false) %} | ||
| {% endif %} | ||
| {% do return(true) %} | ||
| {% endif %} | ||
|
|
||
| {# | ||
| Column-level: only checks the specific column the test targets (test_column_name), | ||
| not all columns on the model. This avoids showing samples for unrelated columns. | ||
| #} | ||
| {% set test_column_name = elementary.insensitive_get_dict_value( | ||
| flattened_test, "test_column_name" | ||
| ) %} | ||
| {% if test_column_name %} | ||
| {% set parent_model_unique_id = elementary.insensitive_get_dict_value( | ||
| flattened_test, "parent_model_unique_id" | ||
| ) %} | ||
| {% set parent_model = elementary.get_node(parent_model_unique_id) %} | ||
| {% if parent_model %} | ||
| {% set column_nodes = parent_model.get("columns", {}) %} | ||
| {% for col_name, col_node in column_nodes.items() %} | ||
| {% if col_name | lower == test_column_name | lower %} | ||
| {% set col_tags = elementary.get_column_tags(col_node) %} | ||
| {% if elementary.lists_intersection( | ||
| col_tags, show_tags | ||
| ) | length > 0 %} | ||
| {# PII on the column or model takes precedence over show_sample_rows #} | ||
| {% if check_pii and ( | ||
| elementary.lists_intersection(col_tags, pii_tags) | ||
| | length | ||
| > 0 | ||
| or elementary.lists_intersection( | ||
| model_tags, pii_tags | ||
| ) | ||
| | length | ||
| > 0 | ||
| ) %} | ||
| {% do return(false) %} | ||
| {% endif %} | ||
| {% do return(true) %} | ||
| {% endif %} | ||
| {% endif %} | ||
| {% endfor %} | ||
| {% endif %} | ||
| {% endif %} | ||
|
|
||
| {% do return(false) %} | ||
| {% endmacro %} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Inverse of PII protection" can be removed