Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Oct 15, 2025

Add missing query_text column to dbt_tests table

Summary

This PR adds the missing query_text column to the dbt_tests table schema and updates the flatten_test macro to populate it with the compiled test query.

Changes made:

  1. Added query_text (long_string) column to the dbt_tests table schema definition
  2. Updated flatten_test macro to use query_text instead of compiled_code as the dictionary key

Context:
The Elementary internal codebase expects a query_text column in the dbt_tests artifact data, but the dbt-data-reliability package was using compiled_code instead. This was discovered during investigation of the Elementary internal code which has logic to filter out query_text with comments indicating it should exist in the raw data but not in the ORM model.

Review & Testing Checklist for Human

  • Schema migration: Verify that existing Elementary installations can successfully upgrade to this version and that the new column is added automatically (the model is configured with on_schema_change='sync_all_columns')
  • Data population: Confirm that query_text is actually being populated with test queries after upgrade (run dbt run and check the dbt_tests table)
  • Elementary internal compatibility: Test that Elementary internal services (CLI/Cloud) can successfully consume the new query_text column without issues
  • Integration tests: Run relevant integration tests to ensure no breakage (note: I only ran dbt compile to verify syntax)
  • Linear issue alignment: Verify this change actually addresses what was requested in ELE-5137

Test Plan

  1. Run dbt run --select dbt_tests on a test project
  2. Query the dbt_tests table and verify query_text column exists and contains compiled SQL
  3. Test Elementary internal data processing to ensure it can consume the new column
  4. If possible, test upgrade path from previous version to ensure smooth migration

Notes

  • Session: Devin run
  • Requested by: Yosef Arbiv (yosef@elementary-data.com) / @arbiv
  • Pre-commit hooks passed
  • Only syntax validation performed via dbt compile - full integration tests not run due to time constraints

Summary by CodeRabbit

  • Refactor
    • Renamed the test artifact field from compiled_code to query_text across the test data schema and flattened metadata.
    • Test records now display the stored query text for each test.
    • Schema for empty test tables now includes query_text (long string).
    • No other fields or paths were changed.
    • Downstream consumers should read query_text where compiled_code was previously used.

- Added query_text column to dbt_tests table schema
- Updated flatten_test macro to use query_text instead of compiled_code
- This ensures compatibility with Elementary internal data processing
  which expects query_text column in the dbt_tests artifact

Fixes ELE-5137

Co-Authored-By: Yosef Arbiv <yosef.arbiv@gmail.com>
@linear
Copy link

linear bot commented Oct 15, 2025

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link
Contributor

👋 @devin-ai-integration[bot]
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 the elementary repository.

@coderabbitai
Copy link

coderabbitai bot commented Oct 15, 2025

Walkthrough

Replaces compiled_code with query_text in dbt test artifacts: adds query_text to the empty table schema and maps query_text to the output of get_compiled_code(node_dict) in the flattened test metadata.

Changes

Cohort / File(s) Summary
DBT test artifacts schema and flattening
macros/edr/dbt_artifacts/upload_dbt_tests.sql
Added query_text to empty table schema; replaced compiled_code with query_text in flattened test metadata, sourcing from elementary.get_compiled_code(node_dict).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • elazarlachkar
  • ofek1weiss

Poem

A nibble of SQL, a hop through the nest,
I swapped a field name to keep data at its best.
Query text now gleams where compiled once stood—
Thump-thump goes the build, all tidy and good.
Ears up, paws down—shipping as we should! 🐇✨

Pre-merge checks and finishing touches

✅ 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 accurately and concisely describes the primary change of adding a missing query_text column to the dbt_tests table, directly reflecting the core update. It is specific and avoids extraneous detail, matching the pull request summary and objectives. The phrasing is clear and informative for collaborators reviewing the change history.
Linked Issues Check ✅ Passed The pull request implements the addition of the query_text column in the table schema and updates the flatten_test macro to populate this field, directly satisfying the requirement from ELE-5137 to restore query_text in the final output. It replaces the compiled_code key with query_text as specified in the linked issue. No coding requirements from the issue remain unaddressed.
Out of Scope Changes Check ✅ Passed All changes are confined to the upload_dbt_tests.sql macro, focusing solely on adding and populating the query_text field and replacing compiled_code mapping to align with the linked issue objectives. No other files, modules, or features have been modified outside this scope. Therefore, there are no unrelated or out-of-scope changes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/ELE-5137-1760557703

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
macros/edr/dbt_artifacts/upload_dbt_tests.sql (1)

181-181: Preserve legacy compiled_code field and mitigate hash churn

  • In upload_dbt_tests.sql (line 181), add a compiled_code alias alongside the new query_text key or update all downstream consumers to use query_text to avoid breakage.
  • Renaming the key alters the input to get_artifact_metadata_hash, causing hash churn—either include both keys when hashing or provide a one-time migration path.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 20b7637 and b822139.

📒 Files selected for processing (1)
  • macros/edr/dbt_artifacts/upload_dbt_tests.sql (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: test (latest_official, dremio) / test
  • GitHub Check: test (latest_official, trino) / test
  • GitHub Check: test (fusion, redshift) / test
  • GitHub Check: test (latest_official, redshift) / test
  • GitHub Check: test (latest_official, snowflake) / test
  • GitHub Check: test (fusion, bigquery) / test
  • GitHub Check: test (latest_official, postgres) / test
  • GitHub Check: test (latest_official, databricks_catalog) / test
  • GitHub Check: test (latest_official, athena) / test
  • GitHub Check: test (fusion, snowflake) / test
  • GitHub Check: test (latest_official, bigquery) / test
  • GitHub Check: test (latest_pre, postgres) / test
  • GitHub Check: test (fusion, databricks_catalog) / test
  • GitHub Check: test (latest_official, clickhouse) / test
🔇 Additional comments (1)
macros/edr/dbt_artifacts/upload_dbt_tests.sql (1)

38-38: Schema: query_text added (long_string) — looks good.

Ordering matches the flattened dict; type aligns with other large text fields.

Please confirm:

  • Existing installs add this column automatically (on_schema_change or artifact table migration path).
  • Warehouses without automatic schema evolution are covered (manual/one‑time migration).

@arbiv arbiv closed this Oct 15, 2025
@arbiv arbiv deleted the devin/ELE-5137-1760557703 branch October 15, 2025 19:55
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.

2 participants