Skip to content

Fixes #17323: Inherit query domains from associated tables - #32130

Merged
harshach merged 9 commits into
mainfrom
harshach/query-domain-inheritance
Aug 27, 2026
Merged

harshach merged 9 commits into
mainfrom
harshach/query-domain-inheritance

Conversation

@harshach

@harshach harshach commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #17323

Queries now inherit the effective domains of every associated table so a multi-table query appears under each applicable domain.

Type of change:

  • Bug fix

High-level design:

QueryRepository computes a deduplicated union of effective domains from non-deleted queryUsedIn tables, while explicit query domains preserve the existing override behavior. Domain propagation now resolves distinct affected query IDs directly from active table relationships with keyset pagination in batches of 100, avoiding descendant-table materialization and unbounded IN lists; exact-table lookup remains available during soft deletion so dependent query search documents can drop stale domains. Reindexing still runs after commit for usage, table/ancestor domain, and table deletion-state changes; no migration is required.

Tests:

Use cases covered

  • Queries associated with multiple tables inherit every table's effective domain
  • Domains inherited through database -> schema -> table propagate to queries
  • Database and table domain changes refresh query API and search results
  • Query usage changes replace stale inherited domains in API and search
  • Soft-deleted tables stop contributing inherited query domains in API and search
  • Large domain cascades page query IDs without materializing descendant table IDs

Unit tests

  • I added unit tests for the new/changed logic
  • Files added/updated: QueryDomainInheritanceTest, QueryRepositoryDomainReindexTest, SearchRepositoryBehaviorTest, SearchRepositoryTest
  • Coverage %: not measured; 131 focused unit tests passed

Backend integration tests

  • I added integration tests in openmetadata-integration-tests/ for the changed API/search behavior
  • Files updated: QueryResourceIT
  • Focused PostgreSQL/Elasticsearch integration tests passed, including ancestor-domain propagation and soft-deleted table exclusion against the optimized implementation

Ingestion integration tests

  • Not applicable (no ingestion changes)

Playwright (UI) tests

  • I added Playwright E2E coverage under openmetadata-ui/.../ui/playwright/
  • Files updated: DomainFilterQueryFilter.spec.ts
  • Spec discovery and changed-file UI checkstyle passed; browser execution not run locally

Manual testing performed

No manual testing was performed; the behavior was verified with isolated PostgreSQL/Elasticsearch integration tests.

UI screen recording / screenshots:

Not applicable -- there are no production UI changes.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: I updated the migration scripts or explained why it is not needed.
  • For UI changes: I attached a screen recording and/or screenshots above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added a test that covers the exact scenario we are fixing.

Greptile Summary

The PR makes queries inherit the deduplicated effective domains of their active associated tables while preserving explicit query-domain overrides.

  • Excludes soft-deleted tables from domain hydration and refreshes affected query search documents after table lifecycle changes.
  • Uses bounded keyset pagination to discover queries affected by table and ancestor-domain changes.
  • Updates persisted and default entity rules to permit legitimate multi-domain queries.
  • Adds unit, integration, search, migration, and Playwright coverage.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previous deleted-table finding is addressed by loading domain sources with non-deleted semantics and is covered by an integration test that verifies both API and search domains after table soft deletion.

Important Files Changed

Filename Overview
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java Hydrates query domains from non-deleted associated tables and batches affected-query discovery for domain propagation.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryDomainInheritance.java Implements explicit-domain override behavior and the deduplicated union of inherited table domains.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/CollectionDAO.java Adds bounded keyset queries for finding affected queries from table and ancestor sources.
openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java Reindexes affected queries after usage, domain, and table deletion-state changes using bounded batches.
openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/MigrationUtil.java Reconciles persisted entity rules so upgraded installations permit inherited multi-domain queries.
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/QueryResourceIT.java Covers multi-table and ancestor inheritance, propagation, usage replacement, soft deletion, and update validation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  T[Active associated tables] --> E[Resolve effective table domains]
  E --> U[Deduplicate domain union]
  Q[Query] --> X{Explicit domains present?}
  X -->|Yes| O[Keep explicit query domains]
  X -->|No| U
  U --> I[Inherited query domains]
  I --> A[Query API response]
  I --> S[Query search document]
  D[Table or ancestor domain/lifecycle change] --> P[Page affected query IDs]
  P --> S
Loading

Reviews (9): Last reviewed commit: "fix(playwright): match dotted domain fil..." | Re-trigger Greptile

Copilot AI lite review requested due to automatic review settings August 26, 2026 23:11
@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Aug 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes the domain-filtered query visibility bug by ensuring Query entities inherit effective domains from every associated Table, and by reindexing affected query documents when either query usage or upstream domain sources (service/database/schema/table) change.

Changes:

  • Compute and return inherited query domains as the deduplicated union of effective domains across all queryUsedIn tables (while preserving the existing “explicit query domains override” behavior).
  • Reindex impacted queries in search when table usage or table/ancestor domain relationships change.
  • Add unit, integration, and Playwright coverage validating multi-table inheritance and search/domain filter behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
openmetadata-ui/src/main/resources/ui/playwright/e2e/Features/DomainFilterQueryFilter.spec.ts Adds E2E coverage ensuring queries are visible under each applicable domain when a query references multiple tables.
openmetadata-service/src/test/java/org/openmetadata/service/search/SearchRepositoryBehaviorTest.java Extends unit test expectations to ensure query domain fields are included in partial search update scripts/params when query usage changes.
openmetadata-service/src/test/java/org/openmetadata/service/jdbi3/QueryDomainInheritanceTest.java Adds unit tests covering unioned inheritance, explicit override behavior, and replacement of stale inherited domains on usage changes.
openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java Triggers query reindexing when domain sources change and ensures partial updates also refresh domains on query usage updates.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java Loads effective table domains in bulk and resolves inherited query domains whenever domains are requested or query usage changes.
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryDomainInheritance.java Implements domain inheritance resolution logic for queries based on associated tables’ effective domains.
openmetadata-integration-tests/src/test/java/org/openmetadata/it/tests/QueryResourceIT.java Adds integration tests validating domain inheritance, and search behavior on table domain changes and query usage changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.

A query inherits the union of the domains of the tables in its queryUsedIn,
so a query spanning tables in different domains legitimately carries multiple
domains. The "Multiple Domains are not allowed" and "Data Product Domain
Validation" rules only exempt user/team/persona/bot, and the rule engine
counts inherited domains (JsonUtils.getMap of the entity) unlike
getValidatedDomains, which skips all-inherited sets. As a result a full-body
update that echoed the inherited domains back was rejected with a 400.

- entityRulesSettings.json: add "query" to ignoredEntities of both domain
  rules (applies to fresh installs, which seed from this file).
- v210 migration: reconcile the persisted setting on existing instances,
  since SettingsCache seeds the JSON only when the setting is absent. The
  logic is idempotent and scoped to the two system domain rules; other rules
  and user customizations are preserved.
- Tests: unit test for the exemption logic (add, idempotency, scoping,
  null-safety) and an IT regression proving a read-modify-write of a
  multi-domain query is no longer blocked by the rule.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…tion

Harden the v210 migration: a customized or older persisted domain rule could
carry a null ignoredEntities list, in which case the exemption was silently
skipped and the query would still trip the single-domain rule after upgrade.
Initialize the list when null so the exemption always applies.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

…-inheritance

# Conflicts:
#	openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v210/Migration.java
#	openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v210/Migration.java
#	openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/MigrationUtil.java

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gitar-bot

gitar-bot Bot commented Aug 27, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 5 resolved / 5 findings

Adds query domain inheritance from associated active tables with batched keyset-paginated propagation and search reindexing. Issues including unbounded query fan-out on domain change, duplicate set declarations, null ignoredEntities handling, and missing migration storage archive logic were successfully addressed. No open findings remain.

✅ 5 resolved
✅ Performance: Unbounded query fan-out on service/db/schema domain change

📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java:3114-3126 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java:242-256
When a DATABASE_SERVICE, DATABASE, or DATABASE_SCHEMA has its domain changed, reindexQueriesForDomainSource resolves every descendant table (listDescendantIdFqnByPrefixNonDeleted) and then every associated query in one pass (getQueriesForTables -> getEntityReferencesByIds with the full id list), then reindexes them all. For large services (thousands of tables/queries) this materializes very large id lists and blocks on a single deferred round trip, unlike the batched terms-query approach used elsewhere (see MAX_PARENT_IDS_PER_TERMS_QUERY). Consider chunking the table/query id lists to bound memory and query size. Domain reassignment at the service level is infrequent, so impact is limited but can be significant at scale.

✅ Quality: Two divergent QUERY_DOMAIN_SOURCE_TYPES sets with same name

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java:51-52 📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java:321-334 📄 openmetadata-service/src/main/java/org/openmetadata/service/search/SearchRepository.java:3119-3132
QueryRepository defines QUERY_DOMAIN_SOURCE_TYPES as {DATABASE_SERVICE, DATABASE, DATABASE_SCHEMA} while SearchRepository defines an identically named constant that also includes TABLE. The membership difference is intentional (SearchRepository gates the reindex on table soft-delete, QueryRepository's getTableIdsForDomainSource special-cases TABLE separately) but the shared name with different contents is easy to misread and could cause a future edit to one to be wrongly assumed to apply to the other. Consider renaming one (e.g. QUERY_DOMAIN_REINDEX_SOURCE_TYPES in SearchRepository) or adding a comment documenting why TABLE is present in one and absent in the other.

✅ Edge Case: Rule with null ignoredEntities is silently skipped

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/MigrationUtil.java:100-114
addQueryDomainRuleExemption() only adds "query" when rule.getIgnoredEntities() != null. If a matching system rule was ever persisted with a null ignoredEntities list, the exemption is silently skipped and the query would still trip the single-domain rule after upgrade. The packaged JSON always supplies a non-null list so this is unlikely, but initializing an absent list would make the migration robust against customized/older persisted settings.

✅ Quality: v210 runDataMigration omits archiveLegacyThreadStorage

📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/mysql/v210/Migration.java:30-37 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/postgres/v210/Migration.java:30-37 📄 openmetadata-service/src/main/java/org/openmetadata/service/migration/utils/v210/MigrationUtil.java:29-43
The v210 MigrationUtil is documented as "Migration utility for 2.1.0 archival of legacy thread storage" and exposes archiveLegacyThreadStorage(), but the new mysql/postgres v210 Migration.runDataMigration() overrides the base method to call only exemptQueryFromMultiDomainRules() — archiveLegacyThreadStorage() has no callers anywhere in the codebase. If the legacy-thread archival was intended to run during the 2.1.0 upgrade, it is now silently skipped; otherwise the method is dead code. Verify intent and either invoke it here or remove it.

✅ Edge Case: Inherited domains include soft-deleted tables

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/QueryRepository.java:184-190
loadTablesWithDomains fetches used tables with Include.ALL, so a query still inherits the domains of a soft-deleted table it references via queryUsedIn. If the intent is for query domains to reflect only active associations, this will surface stale domains for queries whose tables have been soft-deleted (but whose usage relationship still exists). Consider Include.NON_DELETED if soft-deleted tables should not contribute domains.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

Comment on lines +39 to +42
// Reconcile the persisted entityRulesSettings so upgraded instances allow queries to carry the
// multiple domains they inherit from their associated tables. Fresh installs get this from the
// packaged JSON default; existing installs only through this migration.
exemptQueryFromMultiDomainRules();

This branch was previously deployed

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

Labels

backend safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't see Queries Tab infomation, when select domain

4 participants