Skip to content

[BUGFIX] deduplicate sql metric aliases to prevent view schema collisions (#10926) - #11905

Open
TemidayoA wants to merge 11 commits into
fivetran:developfrom
TemidayoA:fix/10926-sql-alias-deduplication
Open

[BUGFIX] deduplicate sql metric aliases to prevent view schema collisions (#10926)#11905
TemidayoA wants to merge 11 commits into
fivetran:developfrom
TemidayoA:fix/10926-sql-alias-deduplication

Conversation

@TemidayoA

Copy link
Copy Markdown

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 tracks existing_aliases in 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.

  • Description of PR changes above includes a link to an existing GitHub issue
  • PR title is prefixed with one of: [BUGFIX], [FEATURE], [DOCS], [MAINTENANCE], [CONTRIB], [MINORBUMP]
  • Code is linted - run invoke lint (uses ruff format + ruff check)
  • Appropriate tests and docs have been updated

@netlify

netlify Bot commented Jun 4, 2026

Copy link
Copy Markdown

👷 Deploy request for niobium-lead-7998 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6c8957f

@TemidayoA

Copy link
Copy Markdown
Author

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.

@github-actions

Copy link
Copy Markdown
Contributor

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 🙇

@github-actions github-actions Bot added the stale Stale issues and PRs label Jul 14, 2026
@joshua-stauffer joshua-stauffer added bug Bugs bugs bugs! and removed stale Stale issues and PRs labels Jul 21, 2026
@joshua-stauffer

Copy link
Copy Markdown
Collaborator

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 tests/integration/data_sources_and_expectations package that reproduces #11905 against Postgres.

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!

@joshua-stauffer

Copy link
Copy Markdown
Collaborator

@cla-bot check

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

All committers have signed the CLA. ✅

@joshua-stauffer joshua-stauffer added the cla-not-signed https://github.com/fivetran/great_expectations/blob/develop/CLA.md label Jul 21, 2026
@TemidayoA

Copy link
Copy Markdown
Author

@cla-bot check on this pull request

@TemidayoA

Copy link
Copy Markdown
Author

@cla-bot check

@joshua-stauffer joshua-stauffer added cla-signed and removed cla-not-signed https://github.com/fivetran/great_expectations/blob/develop/CLA.md labels Jul 21, 2026
@netlify

netlify Bot commented Jul 21, 2026

Copy link
Copy Markdown

👷 Deploy request for niobium-lead-7998 pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 6a71bb3

@TemidayoA

Copy link
Copy Markdown
Author

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...

@TemidayoA

Copy link
Copy Markdown
Author

Hi @joshua-stauffer,

Just pushed the regression test (ae26d9f), it reproduces the schema collision against Postgres by running three ExpectColumnValuesToNotBeNull expectations on different columns (all resolving to column_values.nonnull.unexpected_count), which fails without the fix and passes with it.

Locally it runs green:

tests/integration/data_sources_and_expectations/test_postgres_metric_alias_deduplication.py::test_postgres_multiple_null_expectations_alias_deduplication PASSED

Looks like the two failing checks here (check-actor-permissions, ci-required) are just waiting on workflow approval rather than an actual failure, could you approve the workflow run when you get a chance? Ready for review otherwise.

Thanks.

@TemidayoA

TemidayoA commented Jul 22, 2026

Copy link
Copy Markdown
Author

@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 invoke lint --no-fmt. Can you please approve the workflow run again?

@joshua-stauffer

Copy link
Copy Markdown
Collaborator

@TemidayoA looks like lint is failing, can be addressed with invoke lint --fix

@TemidayoA

Copy link
Copy Markdown
Author

@joshua-stauffer Thank you, I just rebased on the latest upstream/develop and reformatted with ruff, all green locally (lint + the regression test against Postgres). Now waiting on workflow approval to get CI running again. Whenever you get a chance!

@joshua-stauffer

Copy link
Copy Markdown
Collaborator

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.

@TemidayoA

Copy link
Copy Markdown
Author

@joshua-stauffer one more small push (3d9fbdd), turned out marker-coverage-check needed a postgresql marker on the new test, now fixed alongside the formatting. All green locally. Just flagging so it's ready whenever you're back the week of the 3rd. Thanks for your patience

@TemidayoA

Copy link
Copy Markdown
Author

All checks passed @joshua-stauffer

@joshua-stauffer

Copy link
Copy Markdown
Collaborator

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!

@TemidayoA

Copy link
Copy Markdown
Author

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.

@TemidayoA

TemidayoA commented Aug 4, 2026

Copy link
Copy Markdown
Author

@joshua-stauffer I've removed the Postgres regression test and reverted the deduplication logic, so this branch is now clean against develop (lint green). Now standing by for the Clickhouse/BigQuery test harness; once you give me the green light I'll add the integration tests against those backends here.

@joshua-stauffer

Copy link
Copy Markdown
Collaborator

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.
@TemidayoA

TemidayoA commented Aug 5, 2026

Copy link
Copy Markdown
Author

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 random/string imports), and added a unit test asserting that bundled metrics sharing the same underlying metric name get unique, deterministic aliases (_1, _2).

Ready for review once again :)

@joshua-stauffer

Copy link
Copy Markdown
Collaborator

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.

@TemidayoA

Copy link
Copy Markdown
Author

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 🙌

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

Labels

bug Bugs bugs bugs! cla-signed

Projects

None yet

2 participants