From 51f421baee8d37d56488877ef8b46523f8588204 Mon Sep 17 00:00:00 2001 From: maanh96 <58045173+maanh96@users.noreply.github.com> Date: Thu, 14 May 2026 14:37:24 +0700 Subject: [PATCH] fix: add explicit AS aliases to all columns in get_tests & populate_test_alerts_query to support ClickHouse < 24.3 --- .../macros/alerts/population/test_alerts.sql | 38 +++++++++---------- .../monitor/dbt_project/macros/get_tests.sql | 18 ++++----- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/elementary/monitor/dbt_project/macros/alerts/population/test_alerts.sql b/elementary/monitor/dbt_project/macros/alerts/population/test_alerts.sql index bdc2a9253..ec876098b 100644 --- a/elementary/monitor/dbt_project/macros/alerts/population/test_alerts.sql +++ b/elementary/monitor/dbt_project/macros/alerts/population/test_alerts.sql @@ -126,7 +126,7 @@ ) select distinct - failed_tests.alert_id, + failed_tests.alert_id as alert_id, {# Generate elementary unique id which is used to identify between tests, and set it as alert_class_id #} {{ dbt.concat(["coalesce(failed_tests.test_unique_id, 'None')", "'.'", "coalesce(failed_tests.column_name, 'None')", "'.'", "coalesce(failed_tests.sub_type, 'None')"]) }} as alert_class_id, case @@ -135,26 +135,26 @@ when tests.short_name = 'dimension_anomalies' then failed_tests.test_unique_id else {{ dbt.concat(["coalesce(failed_tests.test_unique_id, 'None')", "'.'", "coalesce(failed_tests.column_name, 'None')", "'.'", "coalesce(failed_tests.sub_type, 'None')"]) }} end as elementary_unique_id, - failed_tests.data_issue_id, - failed_tests.test_execution_id, - failed_tests.test_unique_id, - failed_tests.model_unique_id, + failed_tests.data_issue_id as data_issue_id, + failed_tests.test_execution_id as test_execution_id, + failed_tests.test_unique_id as test_unique_id, + failed_tests.model_unique_id as model_unique_id, {# Explicit aliases for columns that exist in both failed_tests and tests tables to avoid ClickHouse column name ambiguity #} failed_tests.database_name as database_name, - failed_tests.detected_at, + failed_tests.detected_at as detected_at, {{ elementary.edr_current_timestamp() }} as created_at, failed_tests.schema_name as schema_name, - failed_tests.table_name, - failed_tests.column_name, + failed_tests.table_name as table_name, + failed_tests.column_name as column_name, failed_tests.test_type as alert_type, - failed_tests.sub_type, + failed_tests.sub_type as sub_type, failed_tests.test_results_description as alert_description, - failed_tests.owners, + failed_tests.owners as owners, failed_tests.tags as tags, failed_tests.test_results_query as alert_results_query, - failed_tests.other, - failed_tests.test_name, - failed_tests.test_short_name, + failed_tests.other as other, + failed_tests.test_name as test_name, + failed_tests.test_short_name as test_short_name, failed_tests.test_params as test_params, failed_tests.severity as severity, failed_tests.status as status, @@ -162,12 +162,12 @@ tests.meta as test_meta, tests.description as test_description, artifacts_meta.meta as model_meta, - invocations.job_id, - invocations.job_name, - invocations.job_run_id, - invocations.job_url, - invocations.job_run_url, - invocations.orchestrator + invocations.job_id as job_id, + invocations.job_name as job_name, + invocations.job_run_id as job_run_id, + invocations.job_url as job_url, + invocations.job_run_url as job_run_url, + invocations.orchestrator as orchestrator from failed_tests left join tests on failed_tests.test_unique_id = tests.unique_id left join artifacts_meta on failed_tests.model_unique_id = artifacts_meta.unique_id diff --git a/elementary/monitor/dbt_project/macros/get_tests.sql b/elementary/monitor/dbt_project/macros/get_tests.sql index 1b04f3d3e..00e6a6d8b 100644 --- a/elementary/monitor/dbt_project/macros/get_tests.sql +++ b/elementary/monitor/dbt_project/macros/get_tests.sql @@ -65,22 +65,22 @@ select tests.unique_id as unique_id, tests.parent_model_unique_id as model_unique_id, - tests.database_name, - tests.schema_name, + tests.database_name as database_name, + tests.schema_name as schema_name, nodes.name as model_name, tests.test_column_name as column_name, tests.name as name, - tests.description, - tests.package_name, - tests.original_path, - tests.test_params, + tests.description as description, + tests.package_name as package_name, + tests.original_path as original_path, + tests.test_params as test_params, tests.meta as meta, nodes.meta as model_meta, - tests.tags, + tests.tags as tags, nodes.tags as model_tags, tests.type as type, - last_test_results.test_type, - last_test_results.test_sub_type, + last_test_results.test_type as test_type, + last_test_results.test_sub_type as test_sub_type, test_results_times.first_detected_at as created_at, last_test_results.detected_at as latest_run_time, last_test_results.status as latest_run_status