Skip to content

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

Open
TemidayoA wants to merge 5 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 5 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 5ceade4

@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?

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