[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 11 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 |
|
@TemidayoA looks like lint is failing, can be addressed with |
|
@joshua-stauffer Thank you, I just rebased on the latest |
|
thanks, running CI now. I'll be out next week, so will review week of August 3rd, and likely can include it in that week's release. |
|
@joshua-stauffer one more small push (3d9fbdd), turned out marker-coverage-check needed a |
|
All checks passed @joshua-stauffer |
|
hey @TemidayoA, the test you added was clarifying - looks like it passes on develop without your fix. This is still a valuable PR, it just needs reframed. My read is that Clickhouse users -- and maybe BigQuery users? -- will hit the duplicate metric bug originally described in #10926. Clickhouse users fallback to individual metric resolution (thanks to #11708). If you're still interested in merging this PR, let's remove the postgres test, and remove the logic here since it should be now covered by the suffixes added in this PR. I'd like to include an integration test against Clickhouse and BigQuery, since they are the actual target data source to fix. I haven't implemented a test harness for Clickhouse yet, and am in the process of turning BigQuery CI tests back on. I'll implement that, and let you know when it's ready. thanks! |
|
Hi @joshua-stauffer, Thanks for the review and the detailed explanation. Really glad to hear that! I am definitely still interested in getting this merged. I'll go ahead and remove the Postgres regression test and revert the deduplication logic I added to clean up the branch. I'll keep an eye out for your update regarding the Clickhouse test harness and the BigQuery CI. Just ping me once those are ready, and I'll pick it back up and help write the integration tests targeting those specific data sources to properly cover the edge cases. Pushing the cleanup changes shortly. Thanks again for the guidance. |
|
@joshua-stauffer I've removed the Postgres regression test and reverted the deduplication logic, so this branch is now clean against |
|
thanks @TemidayoA - to clarify, your dedup implementation was good, and that's what i'd like to merge, along with tests proving that it's necessary. There is already deduplication logic in place in the codebase, but it's on a clickhouse-specific path: My suggestion was to remove that dedup logic in favor of the logic you had introduced in this PR, since its both broader and deterministic in its naming scheme. Sorry we missed each other there - let me know if you have questions! |
…ivetran#10926) Replaces the ClickHouse-specific random-suffix aliasing with a general, deterministic deduplication of metric aliases in _organize_metrics_by_domain, and adds a unit test proving bundled metrics get unique, deterministic aliases.
|
Hello @joshua-stauffer, thanks for clarifying, that makes much sense now. I've just re-landed my former dedup as the general path, removed the ClickHouse random-suffix logic (plus the now-unused Ready for review once again :) |
|
thanks @TemidayoA - as you noticed, I was unable to repro this on BigQuery. Looks like it's a Clickhouse-style specific issue, and a test harness for that won't be ready until sometime next week. This is still an improvement, and your tests capture the behavior, so i want to merge it as is. static-analysis is failing because test markers are missing; once CI is green i'll merge it. |
|
Done @joshua-stauffer - added the unit marker to the test file, so static-analysis should be green now. Thank you so much for the support 🙌 |
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)