From b1dbb259776cb19f0cf4dbea042b1da4875b589e Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 16:09:24 +0000 Subject: [PATCH 1/6] APP-1123: add disable_samples to skip test_result_rows query Thread a new disable_samples parameter from ReportAPI.get_report_data through TestsAPI -> TestsFetcher -> the get_test_results dbt macro. When disable_samples=true, the macro skips the get_result_rows_agate query against test_result_rows entirely instead of relying on the caller to clear sample_data after the SQL has already run. This is consumed by elementary-internal's cloud report generation, where results_sample has zero consumers (522 GB / 249.6M rows scanned per cycle for nothing). The default remains false so OSS users and other callers are unaffected. Co-Authored-By: mika@elementary-data.com --- elementary/monitor/api/report/report.py | 1 + elementary/monitor/api/tests/tests.py | 4 +++ .../dbt_project/macros/get_test_results.sql | 28 +++++++++++++------ elementary/monitor/fetchers/tests/tests.py | 2 ++ 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/elementary/monitor/api/report/report.py b/elementary/monitor/api/report/report.py index 77850333e..7655fe011 100644 --- a/elementary/monitor/api/report/report.py +++ b/elementary/monitor/api/report/report.py @@ -86,6 +86,7 @@ def get_report_data( days_back=days_back, invocations_per_test=test_runs_amount, disable_passed_test_metrics=disable_passed_test_metrics, + disable_samples=disable_samples, ) source_freshnesses_api = SourceFreshnessesAPI( dbt_runner=self.dbt_runner, diff --git a/elementary/monitor/api/tests/tests.py b/elementary/monitor/api/tests/tests.py index ccf16cef4..59afcd608 100644 --- a/elementary/monitor/api/tests/tests.py +++ b/elementary/monitor/api/tests/tests.py @@ -46,6 +46,7 @@ def __init__( days_back: int = 7, invocations_per_test: int = 720, disable_passed_test_metrics: bool = False, + disable_samples: bool = False, ): super().__init__(dbt_runner) self.tests_fetcher = TestsFetcher(dbt_runner=self.dbt_runner) @@ -53,6 +54,7 @@ def __init__( days_back=days_back, invocations_per_test=invocations_per_test, disable_passed_test_metrics=disable_passed_test_metrics, + disable_samples=disable_samples, ) def _get_test_results_db_rows( @@ -60,11 +62,13 @@ def _get_test_results_db_rows( days_back: Optional[int] = 7, invocations_per_test: int = 720, disable_passed_test_metrics: bool = False, + disable_samples: bool = False, ) -> List[TestResultDBRowSchema]: return self.tests_fetcher.get_all_test_results_db_rows( days_back=days_back, invocations_per_test=invocations_per_test, disable_passed_test_metrics=disable_passed_test_metrics, + disable_samples=disable_samples, ) def get_test_results_summary( diff --git a/elementary/monitor/dbt_project/macros/get_test_results.sql b/elementary/monitor/dbt_project/macros/get_test_results.sql index 75b21d31b..9d764329c 100644 --- a/elementary/monitor/dbt_project/macros/get_test_results.sql +++ b/elementary/monitor/dbt_project/macros/get_test_results.sql @@ -1,5 +1,5 @@ -{%- macro get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%} - {{ return(adapter.dispatch('get_test_results', 'elementary_cli')(days_back, invocations_per_test, disable_passed_test_metrics)) }} +{%- macro get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} + {{ return(adapter.dispatch('get_test_results', 'elementary_cli')(days_back, invocations_per_test, disable_passed_test_metrics, disable_samples)) }} {%- endmacro -%} {# @@ -40,7 +40,7 @@ {% do return(test_results) %} {%- endmacro -%} -{%- macro default__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%} +{%- macro default__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} {% set elementary_tests_allowlist_status = ['fail', 'warn'] if disable_passed_test_metrics else ['fail', 'warn', 'pass'] %} {% set select_test_results %} with test_results as ( @@ -111,7 +111,11 @@ {% endset %} {% set test_results_agate = elementary.run_query(test_results_agate_sql) %} - {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} + {% if not disable_samples %} + {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} + {% else %} + {% set test_result_rows_agate = {} %} + {% endif %} {% if not elementary.has_temp_table_support() %} {% do elementary.fully_drop_relation(ordered_test_results_relation) %} {% endif %} @@ -119,7 +123,7 @@ {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status)) %} {%- endmacro -%} -{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%} +{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} {# T-SQL does not allow nested CTEs (WITH inside WITH). current_tests_run_results_query already starts with WITH, so we @@ -165,7 +169,11 @@ {% endset %} {% set test_results_agate = elementary.run_query(test_results_agate_sql) %} - {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} + {% if not disable_samples %} + {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} + {% else %} + {% set test_result_rows_agate = {} %} + {% endif %} {# Clean up intermediate tables #} {% do elementary.fully_drop_relation(base_relation) %} @@ -174,7 +182,7 @@ {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status)) %} {%- endmacro -%} -{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false) -%} +{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} {% do elementary.run_query('drop table if exists ordered_test_results') %} {% set create_table_query %} CREATE TABLE ordered_test_results ( @@ -302,7 +310,11 @@ {% endset %} {% set test_results_agate = elementary.run_query(test_results_agate_sql) %} - {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} + {% if not disable_samples %} + {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} + {% else %} + {% set test_result_rows_agate = {} %} + {% endif %} {% if not elementary.has_temp_table_support() %} {% do elementary.fully_drop_relation(ordered_test_results_relation) %} {% endif %} diff --git a/elementary/monitor/fetchers/tests/tests.py b/elementary/monitor/fetchers/tests/tests.py index ed5706389..6aff79129 100644 --- a/elementary/monitor/fetchers/tests/tests.py +++ b/elementary/monitor/fetchers/tests/tests.py @@ -22,6 +22,7 @@ def get_all_test_results_db_rows( days_back: Optional[int] = 7, invocations_per_test: int = 720, disable_passed_test_metrics: bool = False, + disable_samples: bool = False, ) -> List[TestResultDBRowSchema]: run_operation_response = self.dbt_runner.run_operation( macro_name="elementary_cli.get_test_results", @@ -29,6 +30,7 @@ def get_all_test_results_db_rows( days_back=days_back, invocations_per_test=invocations_per_test, disable_passed_test_metrics=disable_passed_test_metrics, + disable_samples=disable_samples, ), ) test_results = ( From 0e96bc3bc0fe37e0faea23ebbaa944d6612ead78 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 21:22:23 +0000 Subject: [PATCH 2/6] Gate get_test_rows_sample on disable_samples in _process_raw_test_results When disable_samples=true, ensure no sample data leaks via the legacy elementary_test_results.result_rows JSON column. Previously only the test_result_rows table query was skipped; get_test_rows_sample would still return data from the legacy column. Thread disable_samples into _process_raw_test_results and gate the entire get_test_rows_sample call so disable_samples=true means no sample data at all. Co-Authored-By: mika@elementary-data.com --- .../monitor/dbt_project/macros/get_test_results.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/elementary/monitor/dbt_project/macros/get_test_results.sql b/elementary/monitor/dbt_project/macros/get_test_results.sql index 9d764329c..2a54d0b96 100644 --- a/elementary/monitor/dbt_project/macros/get_test_results.sql +++ b/elementary/monitor/dbt_project/macros/get_test_results.sql @@ -7,7 +7,7 @@ Called by both default__ and fabric__ dispatches to avoid duplicating the Jinja processing loop. #} -{%- macro _process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status) -%} +{%- macro _process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples = false) -%} {% set test_results = [] %} {% set tests = elementary.agate_to_dicts(test_results_agate) %} @@ -26,7 +26,7 @@ {% set test_params = fromjson(test.test_params) %} {% set status = test.status | lower %} - {%- if (test_type == 'dbt_test' and status in ['fail', 'warn']) or (test_type != 'dbt_test' and status in elementary_tests_allowlist_status) -%} + {%- if not disable_samples and ((test_type == 'dbt_test' and status in ['fail', 'warn']) or (test_type != 'dbt_test' and status in elementary_tests_allowlist_status)) -%} {% set test_rows_sample = elementary_cli.get_test_rows_sample(test.result_rows, test_result_rows_agate.get(test.id)) %} {%- endif -%} {% else %} @@ -120,7 +120,7 @@ {% do elementary.fully_drop_relation(ordered_test_results_relation) %} {% endif %} - {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status)) %} + {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %} {%- endmacro -%} {%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} @@ -179,7 +179,7 @@ {% do elementary.fully_drop_relation(base_relation) %} {% do elementary.fully_drop_relation(ordered_relation) %} - {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status)) %} + {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %} {%- endmacro -%} {%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} @@ -319,5 +319,5 @@ {% do elementary.fully_drop_relation(ordered_test_results_relation) %} {% endif %} - {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status)) %} + {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %} {%- endmacro -%} From 3507c3afbf1e90d2b8ab2e0cbed371af263d3103 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Tue, 12 May 2026 21:24:59 +0000 Subject: [PATCH 3/6] Skip selecting result_rows column when disable_samples=true Thread disable_samples into current_tests_run_results_query and the clickhouse inline query so the legacy elementary_test_results.result_rows column is replaced with null/empty when samples are disabled. Avoids materializing the column into the temp table and serializing it through agate. Co-Authored-By: mika@elementary-data.com --- .../macros/base_queries/current_tests_run_results_query.sql | 4 ++-- elementary/monitor/dbt_project/macros/get_test_results.sql | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql b/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql index 1ad1ccb00..10bb22ca0 100644 --- a/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql +++ b/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql @@ -1,4 +1,4 @@ -{% macro current_tests_run_results_query(days_back = none, invocation_id = none) %} +{% macro current_tests_run_results_query(days_back = none, invocation_id = none, disable_samples = false) %} with elementary_test_results as ( select * from {{ ref('elementary', 'elementary_test_results') }} {% if days_back %} @@ -79,7 +79,7 @@ dbt_tests.short_name, elementary_test_results.test_alias, elementary_test_results.failures, - elementary_test_results.result_rows, + {% if disable_samples %}null{% else %}elementary_test_results.result_rows{% endif %} as result_rows, dbt_tests.original_path, dbt_tests.meta, dbt_tests.description as test_description, diff --git a/elementary/monitor/dbt_project/macros/get_test_results.sql b/elementary/monitor/dbt_project/macros/get_test_results.sql index 2a54d0b96..54064a6a8 100644 --- a/elementary/monitor/dbt_project/macros/get_test_results.sql +++ b/elementary/monitor/dbt_project/macros/get_test_results.sql @@ -44,7 +44,7 @@ {% set elementary_tests_allowlist_status = ['fail', 'warn'] if disable_passed_test_metrics else ['fail', 'warn', 'pass'] %} {% set select_test_results %} with test_results as ( - {{ elementary_cli.current_tests_run_results_query(days_back=days_back) }} + {{ elementary_cli.current_tests_run_results_query(days_back=days_back, disable_samples=disable_samples) }} ), ordered_test_results as ( @@ -136,7 +136,7 @@ {# Step 1 – materialise the base test-results query into a temp table #} {% set base_query %} - {{ elementary_cli.current_tests_run_results_query(days_back=days_back) }} + {{ elementary_cli.current_tests_run_results_query(days_back=days_back, disable_samples=disable_samples) }} {% endset %} {% set elementary_database, elementary_schema = elementary.get_package_database_and_schema() %} @@ -270,7 +270,7 @@ {{ elementary.edr_datediff(elementary.edr_cast_as_timestamp('etr.detected_at'), elementary.edr_current_timestamp(), 'day') }} AS days_diff, ROW_NUMBER() OVER (PARTITION BY elementary_unique_id ORDER BY etr.detected_at DESC) AS invocations_rank_index, etr.failures, - etr.result_rows + {% if disable_samples %}''{% else %}etr.result_rows{% endif %} AS result_rows FROM {{ ref('elementary', 'elementary_test_results') }} etr JOIN {{ ref('elementary', 'dbt_tests') }} dt ON etr.test_unique_id = dt.unique_id LEFT JOIN ( From a174c35f6314e9e5898da22e7f008c3a4283f103 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 13 May 2026 20:54:24 +0000 Subject: [PATCH 4/6] Rename disable_samples -> skip_test_result_rows for macro-level optimization Separates the macro-level DB optimization from the existing OSS Python-level disable_samples mask: - skip_test_result_rows (new, macro-level): pure DB optimization. Skips the test_result_rows table query, gates get_test_rows_sample, selects null/'' as result_rows. Affects ALL test types. Used by cloud only. - disable_samples (unchanged, Python-level): masks sample_data for dbt_test rows only. Used by OSS --disable-samples CLI flag for PII protection. Anomaly metrics are preserved. Co-Authored-By: mika@elementary-data.com --- elementary/monitor/api/report/report.py | 3 +- elementary/monitor/api/tests/tests.py | 8 ++--- .../current_tests_run_results_query.sql | 4 +-- .../dbt_project/macros/get_test_results.sql | 32 +++++++++---------- elementary/monitor/fetchers/tests/tests.py | 4 +-- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/elementary/monitor/api/report/report.py b/elementary/monitor/api/report/report.py index 7655fe011..2b7c4cd10 100644 --- a/elementary/monitor/api/report/report.py +++ b/elementary/monitor/api/report/report.py @@ -76,6 +76,7 @@ def get_report_data( exclude_elementary_models: bool = False, project_name: Optional[str] = None, disable_samples: bool = False, + skip_test_result_rows: bool = False, filter: SelectorFilterSchema = SelectorFilterSchema(), env: Optional[str] = None, warehouse_type: Optional[str] = None, @@ -86,7 +87,7 @@ def get_report_data( days_back=days_back, invocations_per_test=test_runs_amount, disable_passed_test_metrics=disable_passed_test_metrics, - disable_samples=disable_samples, + skip_test_result_rows=skip_test_result_rows, ) source_freshnesses_api = SourceFreshnessesAPI( dbt_runner=self.dbt_runner, diff --git a/elementary/monitor/api/tests/tests.py b/elementary/monitor/api/tests/tests.py index 59afcd608..41b8f407b 100644 --- a/elementary/monitor/api/tests/tests.py +++ b/elementary/monitor/api/tests/tests.py @@ -46,7 +46,7 @@ def __init__( days_back: int = 7, invocations_per_test: int = 720, disable_passed_test_metrics: bool = False, - disable_samples: bool = False, + skip_test_result_rows: bool = False, ): super().__init__(dbt_runner) self.tests_fetcher = TestsFetcher(dbt_runner=self.dbt_runner) @@ -54,7 +54,7 @@ def __init__( days_back=days_back, invocations_per_test=invocations_per_test, disable_passed_test_metrics=disable_passed_test_metrics, - disable_samples=disable_samples, + skip_test_result_rows=skip_test_result_rows, ) def _get_test_results_db_rows( @@ -62,13 +62,13 @@ def _get_test_results_db_rows( days_back: Optional[int] = 7, invocations_per_test: int = 720, disable_passed_test_metrics: bool = False, - disable_samples: bool = False, + skip_test_result_rows: bool = False, ) -> List[TestResultDBRowSchema]: return self.tests_fetcher.get_all_test_results_db_rows( days_back=days_back, invocations_per_test=invocations_per_test, disable_passed_test_metrics=disable_passed_test_metrics, - disable_samples=disable_samples, + skip_test_result_rows=skip_test_result_rows, ) def get_test_results_summary( diff --git a/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql b/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql index 10bb22ca0..3e18222bf 100644 --- a/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql +++ b/elementary/monitor/dbt_project/macros/base_queries/current_tests_run_results_query.sql @@ -1,4 +1,4 @@ -{% macro current_tests_run_results_query(days_back = none, invocation_id = none, disable_samples = false) %} +{% macro current_tests_run_results_query(days_back = none, invocation_id = none, skip_test_result_rows = false) %} with elementary_test_results as ( select * from {{ ref('elementary', 'elementary_test_results') }} {% if days_back %} @@ -79,7 +79,7 @@ dbt_tests.short_name, elementary_test_results.test_alias, elementary_test_results.failures, - {% if disable_samples %}null{% else %}elementary_test_results.result_rows{% endif %} as result_rows, + {% if skip_test_result_rows %}null{% else %}elementary_test_results.result_rows{% endif %} as result_rows, dbt_tests.original_path, dbt_tests.meta, dbt_tests.description as test_description, diff --git a/elementary/monitor/dbt_project/macros/get_test_results.sql b/elementary/monitor/dbt_project/macros/get_test_results.sql index 54064a6a8..f9e37f115 100644 --- a/elementary/monitor/dbt_project/macros/get_test_results.sql +++ b/elementary/monitor/dbt_project/macros/get_test_results.sql @@ -1,5 +1,5 @@ -{%- macro get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} - {{ return(adapter.dispatch('get_test_results', 'elementary_cli')(days_back, invocations_per_test, disable_passed_test_metrics, disable_samples)) }} +{%- macro get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%} + {{ return(adapter.dispatch('get_test_results', 'elementary_cli')(days_back, invocations_per_test, disable_passed_test_metrics, skip_test_result_rows)) }} {%- endmacro -%} {# @@ -7,7 +7,7 @@ Called by both default__ and fabric__ dispatches to avoid duplicating the Jinja processing loop. #} -{%- macro _process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples = false) -%} +{%- macro _process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows = false) -%} {% set test_results = [] %} {% set tests = elementary.agate_to_dicts(test_results_agate) %} @@ -26,7 +26,7 @@ {% set test_params = fromjson(test.test_params) %} {% set status = test.status | lower %} - {%- if not disable_samples and ((test_type == 'dbt_test' and status in ['fail', 'warn']) or (test_type != 'dbt_test' and status in elementary_tests_allowlist_status)) -%} + {%- if not skip_test_result_rows and ((test_type == 'dbt_test' and status in ['fail', 'warn']) or (test_type != 'dbt_test' and status in elementary_tests_allowlist_status)) -%} {% set test_rows_sample = elementary_cli.get_test_rows_sample(test.result_rows, test_result_rows_agate.get(test.id)) %} {%- endif -%} {% else %} @@ -40,11 +40,11 @@ {% do return(test_results) %} {%- endmacro -%} -{%- macro default__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} +{%- macro default__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%} {% set elementary_tests_allowlist_status = ['fail', 'warn'] if disable_passed_test_metrics else ['fail', 'warn', 'pass'] %} {% set select_test_results %} with test_results as ( - {{ elementary_cli.current_tests_run_results_query(days_back=days_back, disable_samples=disable_samples) }} + {{ elementary_cli.current_tests_run_results_query(days_back=days_back, skip_test_result_rows=skip_test_result_rows) }} ), ordered_test_results as ( @@ -111,7 +111,7 @@ {% endset %} {% set test_results_agate = elementary.run_query(test_results_agate_sql) %} - {% if not disable_samples %} + {% if not skip_test_result_rows %} {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} {% else %} {% set test_result_rows_agate = {} %} @@ -120,10 +120,10 @@ {% do elementary.fully_drop_relation(ordered_test_results_relation) %} {% endif %} - {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %} + {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows)) %} {%- endmacro -%} -{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} +{%- macro fabric__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%} {# T-SQL does not allow nested CTEs (WITH inside WITH). current_tests_run_results_query already starts with WITH, so we @@ -136,7 +136,7 @@ {# Step 1 – materialise the base test-results query into a temp table #} {% set base_query %} - {{ elementary_cli.current_tests_run_results_query(days_back=days_back, disable_samples=disable_samples) }} + {{ elementary_cli.current_tests_run_results_query(days_back=days_back, skip_test_result_rows=skip_test_result_rows) }} {% endset %} {% set elementary_database, elementary_schema = elementary.get_package_database_and_schema() %} @@ -169,7 +169,7 @@ {% endset %} {% set test_results_agate = elementary.run_query(test_results_agate_sql) %} - {% if not disable_samples %} + {% if not skip_test_result_rows %} {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} {% else %} {% set test_result_rows_agate = {} %} @@ -179,10 +179,10 @@ {% do elementary.fully_drop_relation(base_relation) %} {% do elementary.fully_drop_relation(ordered_relation) %} - {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %} + {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows)) %} {%- endmacro -%} -{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, disable_samples = false) -%} +{%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%} {% do elementary.run_query('drop table if exists ordered_test_results') %} {% set create_table_query %} CREATE TABLE ordered_test_results ( @@ -270,7 +270,7 @@ {{ elementary.edr_datediff(elementary.edr_cast_as_timestamp('etr.detected_at'), elementary.edr_current_timestamp(), 'day') }} AS days_diff, ROW_NUMBER() OVER (PARTITION BY elementary_unique_id ORDER BY etr.detected_at DESC) AS invocations_rank_index, etr.failures, - {% if disable_samples %}''{% else %}etr.result_rows{% endif %} AS result_rows + {% if skip_test_result_rows %}''{% else %}etr.result_rows{% endif %} AS result_rows FROM {{ ref('elementary', 'elementary_test_results') }} etr JOIN {{ ref('elementary', 'dbt_tests') }} dt ON etr.test_unique_id = dt.unique_id LEFT JOIN ( @@ -310,7 +310,7 @@ {% endset %} {% set test_results_agate = elementary.run_query(test_results_agate_sql) %} - {% if not disable_samples %} + {% if not skip_test_result_rows %} {% set test_result_rows_agate = elementary_cli.get_result_rows_agate(days_back, valid_ids_query) %} {% else %} {% set test_result_rows_agate = {} %} @@ -319,5 +319,5 @@ {% do elementary.fully_drop_relation(ordered_test_results_relation) %} {% endif %} - {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, disable_samples)) %} + {% do return(elementary_cli._process_raw_test_results(test_results_agate, test_result_rows_agate, elementary_tests_allowlist_status, skip_test_result_rows)) %} {%- endmacro -%} diff --git a/elementary/monitor/fetchers/tests/tests.py b/elementary/monitor/fetchers/tests/tests.py index 6aff79129..07e557228 100644 --- a/elementary/monitor/fetchers/tests/tests.py +++ b/elementary/monitor/fetchers/tests/tests.py @@ -22,7 +22,7 @@ def get_all_test_results_db_rows( days_back: Optional[int] = 7, invocations_per_test: int = 720, disable_passed_test_metrics: bool = False, - disable_samples: bool = False, + skip_test_result_rows: bool = False, ) -> List[TestResultDBRowSchema]: run_operation_response = self.dbt_runner.run_operation( macro_name="elementary_cli.get_test_results", @@ -30,7 +30,7 @@ def get_all_test_results_db_rows( days_back=days_back, invocations_per_test=invocations_per_test, disable_passed_test_metrics=disable_passed_test_metrics, - disable_samples=disable_samples, + skip_test_result_rows=skip_test_result_rows, ), ) test_results = ( From b79551be6e1872a6d6fef80b592bf01c2682db29 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 13 May 2026 20:57:50 +0000 Subject: [PATCH 5/6] Initialize elementary_tests_allowlist_status in clickhouse__get_test_results Pre-existing bug surfaced by CodeRabbit: the ClickHouse variant of get_test_results passes elementary_tests_allowlist_status into _process_raw_test_results without ever initializing it. The default__ and fabric__ variants both set it from disable_passed_test_metrics at the top of the macro. Without this, sample selection for non-dbt_test rows (anomaly/schema_change) would silently skip on ClickHouse because the 'status in elementary_tests_allowlist_status' check would fail on an undefined value. Co-Authored-By: mika@elementary-data.com --- elementary/monitor/dbt_project/macros/get_test_results.sql | 1 + 1 file changed, 1 insertion(+) diff --git a/elementary/monitor/dbt_project/macros/get_test_results.sql b/elementary/monitor/dbt_project/macros/get_test_results.sql index f9e37f115..bc6a34629 100644 --- a/elementary/monitor/dbt_project/macros/get_test_results.sql +++ b/elementary/monitor/dbt_project/macros/get_test_results.sql @@ -183,6 +183,7 @@ {%- endmacro -%} {%- macro clickhouse__get_test_results(days_back = 7, invocations_per_test = 720, disable_passed_test_metrics = false, skip_test_result_rows = false) -%} + {% set elementary_tests_allowlist_status = ['fail', 'warn'] if disable_passed_test_metrics else ['fail', 'warn', 'pass'] %} {% do elementary.run_query('drop table if exists ordered_test_results') %} {% set create_table_query %} CREATE TABLE ordered_test_results ( From 3a0d26834fd56900e3d3c9a048ecc79e9a1012b7 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 14 May 2026 08:01:15 +0000 Subject: [PATCH 6/6] ci: trigger re-run after dbt-adapters 1.24.0 yank Co-Authored-By: mika@elementary-data.com