[BUGFIX] deduplicate sql metric aliases to prevent view schema collisions (#10926)#11905
[BUGFIX] deduplicate sql metric aliases to prevent view schema collisions (#10926)#11905TemidayoA wants to merge 5 commits into
Conversation
👷 Deploy request for niobium-lead-7998 pending review.Visit the deploys page to approve it
|
for more information, see https://pre-commit.ci
|
Hi team, just giving this bugfix a gentle jab. This resolves the strict SQL backend schema collisions documented in #10926. Could a maintainer be assigned to review this? Also, please let me know if you need me to write any specific unit tests for this dynamic alias deduplication logic, I left that checklist item blank for now but I am more than happy to add them if required. |
|
Is this PR still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions 🙇 |
|
hey @TemidayoA, thanks for the PR, and sorry for the delayed response. This looks like the right approach - we'll just need a regression test prior to review and merge, ideally an integration test within the If you haven't already, you'll also need to sign the CLA prior to getting this merged. Let me know if you have any questions, and thanks again! |
|
@cla-bot check |
|
All committers have signed the CLA. ✅ |
|
@cla-bot check on this pull request |
|
@cla-bot check |
👷 Deploy request for niobium-lead-7998 pending review.Visit the deploys page to approve it
|
|
Hii @joshua-stauffer, Thank you for getting back to me and for updating the CLA tags. I understand the need for a regression test. I will get to work on adding an integration test within tests/integration/data_sources_and_expectations that specifically reproduces the schema collision issue against Postgres. I'll push the updates to this branch shortly and ping you once it's ready for review. Thanks again... |
|
Hi @joshua-stauffer, Just pushed the regression test (ae26d9f), it reproduces the schema collision against Postgres by running three Locally it runs green: Looks like the two failing checks here ( Thanks. |
|
@joshua-stauffer I just pushed a small lint fix (5ceade4) for the ruff import-sort/newline issues from the last run, confirmed clean locally with |
Closes #10926
Description of Changes:
This PR addresses the schema collision error (
Duplicated field name in view schema) that occurs when the SQL execution engine bundles multiple expectations evaluating the same underlying metric. Previously, the query compiler assigned identical SQL aliases to these metrics, causing strict SQL backends (like Postgres) to reject the view/subquery construction.This fix introduces a dynamic alias deduplication step within
_organize_metrics_by_domain. It tracksexisting_aliasesin the current query batch and automatically appends an incrementing suffix (e.g.,_1,_2) to any colliding metric names before attaching the.label(), allowing the SQL view to compile successfully without breaking downstream positional index mapping.invoke lint(usesruff format+ruff check)