Skip to content

fix: add explicit AS aliases to all columns in get_tests & populate_test_alerts_query to support ClickHouse < 24.3#2231

Open
maanh96 wants to merge 1 commit into
elementary-data:masterfrom
maanh96:master
Open

fix: add explicit AS aliases to all columns in get_tests & populate_test_alerts_query to support ClickHouse < 24.3#2231
maanh96 wants to merge 1 commit into
elementary-data:masterfrom
maanh96:master

Conversation

@maanh96
Copy link
Copy Markdown

@maanh96 maanh96 commented May 14, 2026

Fixes #2228

Description

On ClickHouse versions < 24.3, the old query analyzer prefixes all joined/CTE columns with their source table name (e.g., failed_tests.alert_id, invocations.job_id) instead of plain column names. This causes two separate failures:

  1. edr monitor crashes with Object of type Undefined is not JSON serializable in populate_test_alerts macro
  2. edr report crashes with ValidationError: field required schema_name / test_params from get_tests macro

Both have the same root cause — ClickHouse < 24.3 prefixing all joined/CTE column names with their source table name.

Changes

  • elementary/monitor/dbt_project/macros/alerts/population/test_alerts.sql — added explicit AS aliases to all table.column references in the final SELECT of populate_test_alerts_query
  • elementary/monitor/dbt_project/macros/get_tests.sql — added explicit AS aliases to all table.column references for the same reason

Root Cause

ClickHouse's old analyzer (default in versions < 24.3) prefixes all joined/CTE columns with their source table name. The new analyzer (default from 24.3+) handles this correctly. This change is fully backwards compatible — redundant AS aliases are valid SQL on all warehouses and all ClickHouse versions.

Testing

Verified on ClickHouse 23.4:

  • edr monitor now runs successfully and sends alerts without error
  • edr report now generates the report without validation errors

Summary by CodeRabbit

  • Refactor
    • Enhanced database query logic with improved column naming and explicit aliasing to increase consistency and reduce potential ambiguity in internal queries.

Review Change Stack

…est_alerts_query to support ClickHouse < 24.3
@github-actions
Copy link
Copy Markdown
Contributor

👋 @maanh96
Thank you for raising your pull request.
Please make sure to add tests and document all user-facing changes.
You can do this by editing the docs files in this pull request.

@maanh96 maanh96 requested a deployment to elementary_test_env May 14, 2026 07:50 — with GitHub Actions Waiting
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 22c1b78c-5eff-4446-8a31-94707dbf1d0b

📥 Commits

Reviewing files that changed from the base of the PR and between fc1599e and 51f421b.

📒 Files selected for processing (2)
  • elementary/monitor/dbt_project/macros/alerts/population/test_alerts.sql
  • elementary/monitor/dbt_project/macros/get_tests.sql

📝 Walkthrough

Walkthrough

This PR adds explicit column aliases to SQL macros in Elementary's dbt project to resolve a ClickHouse 23.4 compatibility issue. Two macros (populate_test_alerts_query and get_tests) are updated to consistently alias all selected columns, ensuring plain column names are returned instead of table-qualified names across ClickHouse versions.

Changes

SQL Column Aliasing for ClickHouse Compatibility

Layer / File(s) Summary
Test alerts query column aliasing
elementary/monitor/dbt_project/macros/alerts/population/test_alerts.sql
The populate_test_alerts_query macro adds explicit AS aliases to all columns in the SELECT DISTINCT projection, including alert_id, data_issue_id, test_execution_id, test_unique_id, model_unique_id, and test metadata fields (detected_at, schema_name, table_name, alert_type, alert_description, test_results_query, owners, tags, status, result_rows).
Test retrieval query column aliasing
elementary/monitor/dbt_project/macros/get_tests.sql
The get_tests() macro adds explicit AS aliases to columns in the SELECT clause for test metadata fields (database_name, schema_name, description, package_name, original_path, test_params, tags) and last test results fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through ClickHouse rows,
Where column names in aliases flow,
No more prefixed, no more unclear,
Just plain and simple, crystal clear!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding explicit AS aliases to columns in two SQL macros to support older ClickHouse versions.
Linked Issues check ✅ Passed The PR fully addresses issue #2228 by adding explicit AS aliases to all unaliased columns in both populate_test_alerts_query and get_tests macros, resolving the ClickHouse < 24.3 compatibility issue.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing ClickHouse < 24.3 column aliasing issues; no unrelated modifications are present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

populate_test_alerts_query returns prefixed column names on old ClickHouse versions, causing "Object of type Undefined is not JSON serializable" error

1 participant