Skip to content

Fixes 33353: Batch table custom-metric and column-extension reads - #33355

Merged
harshach merged 3 commits into
mainfrom
harshach/table-metadata-batch-reads
Sep 24, 2026
Merged

harshach merged 3 commits into
mainfrom
harshach/table-metadata-batch-reads

Conversation

@harshach

@harshach harshach commented Sep 15, 2026 •

Copy link
Copy Markdown
Collaborator

Describe your changes:

Fixes #33353

Part of #32946, shipped on its own as the reviewer suggested: this is the "505 → 5 statements on table metrics" win from #33248, ported onto the unchanged EntityRepository so it can merge and cherry-pick today.

Table detail reads fetched custom metrics once per column and column extensions once per column, so GET /v1/tables/{id}?fields=columns,customMetrics on a 100-column table ran 101 entity_extension queries. TableMetadataLoader now loads table and column metrics for a whole batch of tables with one prefix query, and column extensions with one keyed query (getExtensionsByKeys, chunked like the other IN lists), so the per-request count no longer depends on column width. The paginated column endpoints and the single-column read share the same loader, and TableRepository loses its four per-column readers.

Type of change:

  • Improvement

High-level design:

  • TableMetadataLoader (new, jdbi3): three read operations, one query each: loadMetrics(tables, includeColumns), loadColumnMetrics(tableId, columns), loadColumnExtensions(tableId, columns). It takes a Supplier<EntityExtensionDAO> so the reads join whatever transaction the caller already holds.

  • EntityExtensionDAO.getExtensionsByKeys: WHERE id = :id AND extension IN (<keys>), chunked through EntityDAO.queryInChunks. Column extensions are looked up by their exact persisted key, so legacy rows stored under another jsonSchema are still returned — by the entity read, the single-column read and the paginated /columns read alike.

    Correction: an earlier revision of this description said "the paginated path already read by key". It did not — getTableColumns still filtered on jsonschema = 'columnExtension', so a legacy row was returned by two reads and dropped by GET /v1/tables/{id}/columns?fields=extension. Caught in review; that branch now goes through the same loader, and TableMetadataReadIT.paginatedColumnExtensionsPreserveLegacyKeys covers it (fails on the previous code with expected: <{note=legacy}> but was: <null>).

  • TableRepository: setFields, fetchAndSetCustomMetrics, the two paginated column reads and the single-column read call the loader; getCustomMetrics, batchFetchCustomMetrics, batchFetchCustomMetricsByColumn and getColumnExtension are deleted. The public constants keep their values (they now alias the loader's).

  • No public/protected repository API changes; Collate compiles unchanged. Response JSON is unchanged: metric order per column is still the extension-name order, and absent metrics still serialize as [].

  • SqlQueryCounter (test util) is byte-identical to the one in Fixes 32946: Pin entity repository lifecycle and cache contracts (1/7) #33344 so the two PRs merge in either order.

Tests:

Use cases covered

  • GET /v1/tables/{id}?fields=columns,customMetrics at 3, 100 and 1,000 columns: one extension query, table metric and column metric both present, unrelated customMetrics.table.tableish.* rows ignored.
  • fields=columns,extension: one table-extension query plus one keyed query; a legacy column-extension row stored under another jsonSchema is returned.
  • fields=columns alone runs zero extension queries and leaves customMetrics null.
  • Bulk setFieldsInBulk across two tables with the same column names: one query, metrics not mixed across tables.
  • GET /v1/tables/{id}/columns?fields=customMetrics&limit=3: one extension query, counted only inside the HTTP request.
  • A metric inserted and read inside a rolled-back transaction is visible inside it and gone after it.

Unit tests

  • TableMetadataLoaderTest (8 tests, no database): absent inputs need no DAO, selected-column filtering, table-only reads do not decode column metrics, overlapping column names across tables stay distinct, malformed or unresolvable keys do not stop later columns, DAO failure clears stale values.

Backend integration tests

  • TableMetadataReadIT (8 tests, real SQL statement counter, @Isolated).
  • Failing-before evidence, same test class against main's TableRepository (PostgreSQL): 5 of 8 fail on the query budget alone: 3 columns → 4 queries, 100 → 101, 1,000 → 1,001; fields=columns,extension → 101; two-table bulk read → 202. The three that pass before (fields=columns runs zero queries, the paginated page already ran one, the transaction check) are regression guards.
  • After: 8 passed on PostgreSQL/OpenSearch and 8 passed on MySQL/Elasticsearch (Java 21, Testcontainers).
  • Existing coverage of the touched paths, PostgreSQL/OpenSearch: TableResourceIT (294 cases, including createUpdateDelete_tableCustomMetrics_200 and test_getTableColumnsWithCustomMetrics_200) and ColumnCustomPropertiesIT (65 cases): 364 run, 0 failures, 0 errors, 9 pre-existing skips.

Ingestion integration tests

Not applicable (no ingestion changes).

Playwright (UI) tests

Not applicable (no UI changes).

Manual testing performed

None beyond the automated runs above; all evidence is from the integration tests listed.

UI screen recording / screenshots:

Not applicable.

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: not applicable, no schema changes.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • I have added tests around the new logic.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable correctness, security, or repository-rule violations remain.

Summary

This PR replaces per-column custom-metric and extension reads with transaction-aware batched loading.

  • Adds keyed, chunked extension retrieval through EntityExtensionDAO.
  • Introduces TableMetadataLoader to hydrate table metrics, column metrics, and column extensions in bounded query batches.
  • Routes entity, bulk, paginated-column, and single-column reads through the shared loader.
  • Adds unit and integration coverage for query counts, table isolation, legacy extension keys, malformed records, and transactional visibility.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Table read request] --> B[TableRepository]
  B --> C{Requested fields}
  C -->|customMetrics| D[TableMetadataLoader.loadMetrics]
  C -->|column customMetrics| E[TableMetadataLoader.loadColumnMetrics]
  C -->|column extension| F[TableMetadataLoader.loadColumnExtensions]
  D --> G[Prefix-based batch query]
  E --> H[Column metric prefix query]
  F --> I[Chunked exact-key query]
  G --> J[(entity_extension)]
  H --> J
  I --> J
  D --> K[Hydrated tables and columns]
  E --> K
  F --> K
Loading

Reviews (2) · Last reviewed commit: "Route the paginated /columns extension r..."

Table detail reads fetched custom metrics once per column and column
extensions once per column, so a 100-column table with customMetrics
cost 101 entity_extension queries per request. TableMetadataLoader now
loads table and column metrics for a whole batch of tables with one
prefix query, and column extensions with one keyed query, keeping the
per-request count independent of column width. The paginated column
endpoints share the same loader.

Part of #32946

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added backend safe to test Add this label to run secure Github workflows on PRs labels Sep 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

harshach and others added 2 commits September 22, 2026 14:03
#33539 landed SqlQueryCounter on main, and this PR carried its own, so the two
collided add/add. This PR's copy is dropped in favour of main's.

That is a pure dedup rather than a compromise: TableMetadataReadIT only calls
the two-argument forRequests and the public constructor, both of which main's
copy has with the same semantics - calling-thread scope for the constructor,
"a request is in flight" for forRequests. Nothing here used the three-argument
forRequests, deadlockOnce or afterFirst that the dropped copy also carried, so
this does not depend on #33642.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Review feedback, and it caught a false claim of mine. This PR's description
said "the paginated path already read by key". It did not: getTableColumns
still read column extensions with getExtensionsByJsonSchema, filtering on
jsonschema = 'columnExtension', while the entity read (setFields) and the
single-column read resolve by the exact persisted key through
TableMetadataLoader. A column-extension row written under an older schema name
was therefore returned by two reads and silently dropped by
GET /v1/tables/{id}/columns?fields=extension.

The branch now calls metadataLoader.loadColumnExtensions, so all three reads
agree. It is cheaper as well: the old read fetched every column-extension row
on the table and filtered in memory, where the loader fetches only the page's
keys. Per-record deserialisation failures are still caught individually, so one
bad row does not blank the rest of the page.

Nothing tested this path, which is how the inconsistency and the claim both
survived - the legacy-key test went through the entity read only, and the
paginated test checked customMetrics only.
paginatedColumnExtensionsPreserveLegacyKeys covers it. Run locally against
MySQL/Elasticsearch: 9/9 with this change; against the previous code the new
test is the only failure, with "expected: <{note=legacy}> but was: <null>".

Out of scope and unchanged: searchTableColumnsInternal has no extension branch
at all. That is true on main as well, so it is a pre-existing gap in the search
endpoint rather than something this PR introduced.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gitar-bot

gitar-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 1 closed / 1 findings

🟡 Medium risk · Batches table metadata extension reads and changes repository hydration behavior.

Batches table custom-metric and column-extension reads through a new TableMetadataLoader, reducing per-request queries from O(columns) to O(1) by replacing 101 separate reads on a 100-column table with three prefix- and key-based batch queries. Paginated /columns endpoint now routes through the shared loader to preserve legacy extension keys. No issues found.

✅ 1 closed
✅ Bug: Paginated /columns extension read not routed through loader

📄 openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/TableRepository.java:2879-2893
In getTableColumns, the customMetrics branch was converted to metadataLoader.loadColumnMetrics, but the adjacent extension branch (lines 2883-2906) still reads via getExtensionsByJsonSchema(id, COLUMN_EXTENSION_JSON_SCHEMA), filtering on jsonschema = 'columnExtension'. The new loadColumnExtensions used by setFields and the single-column read (enrichSingleColumnFields) resolves by the exact persisted key regardless of jsonSchema, so a legacy column-extension row stored under a different jsonSchema will be returned by GET /v1/tables/{id}?fields=columns,extension and the single-column read but NOT by the paginated GET /v1/tables/{id}/columns?fields=extension. This contradicts the PR's stated claim that "the paginated path already read by key." Consider routing this branch through metadataLoader.loadColumnExtensions(table.getId(), paginatedColumns) for consistency.

Review coverage

📋 Rules No rules evaluated

🧪 Functional validation Not enabled · Set up

🤖 Auto-approval Not enabled · Set up

Options

Display: compact → Counting what did not apply, without listing it.

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Playwright Results — workflow succeeded

Validated commit 3a915e94b970b16e7df15a0b71895a5d31c4d588 in Playwright run 35785858603, attempt 1.

✅ 4553 passed · ❌ 0 failed · 🟡 5 flaky · ⏭️ 1 skipped · 🧰 0 lifecycle flaky

Performance

Blocking targets: ✅ met · Optimization targets: 🟡 in progress

Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting.

🕒 Full workflow signal wall (to summary) 55m 23s

⏱️ Max setup 4m 59s · max shard execution 23m 24s · max shard-job elapsed before upload 27m 9s · reporting 19s

🌐 224.33 requests/attempt · 2.23 app boots/UI scenario · 43.66% common-shard skew

Optimization targets still in progress:

  • Common shard skew was 43.66% (convergence target: at most 15%).
  • Browser traffic was 224.33 requests per attempt (convergence target: fewer than 200).
  • Application boot ratio was 2.23 per UI scenario (10799 boots / 4851 scenarios; convergence target: at most 1).
Shard Passed Failed Flaky Skipped Lifecycle failed Lifecycle flaky
✅ Shard advanced-search-01 130 0 0 0 0 0
✅ Shard chromium-01 148 0 0 0 0 0
✅ Shard chromium-02 163 0 0 0 0 0
✅ Shard chromium-03 194 0 0 0 0 0
✅ Shard chromium-04 185 0 0 0 0 0
✅ Shard chromium-05 173 0 0 0 0 0
✅ Shard chromium-06 184 0 0 0 0 0
✅ Shard chromium-07 158 0 0 0 0 0
✅ Shard chromium-08 170 0 0 1 0 0
✅ Shard chromium-09 177 0 0 0 0 0
✅ Shard chromium-10 186 0 0 0 0 0
✅ Shard chromium-11 156 0 0 0 0 0
✅ Shard chromium-12 177 0 0 0 0 0
✅ Shard chromium-13 182 0 0 0 0 0
✅ Shard chromium-14 171 0 0 0 0 0
✅ Shard chromium-15 172 0 0 0 0 0
🟡 Shard chromium-16 195 0 2 0 0 0
✅ Shard chromium-17 179 0 0 0 0 0
✅ Shard chromium-18 166 0 0 0 0 0
🟡 Shard chromium-19 142 0 1 0 0 0
🟡 Shard chromium-20 187 0 1 0 0 0
✅ Shard chromium-21 128 0 0 0 0 0
🟡 Shard chromium-22 168 0 1 0 0 0
✅ Shard chromium-23 216 0 0 0 0 0
✅ Shard data-asset-rules-01 65 0 0 0 0 0
✅ Shard domain-isolation-01 16 0 0 0 0 0
✅ Shard global-state-01 34 0 0 0 0 0
✅ Shard import-export-01 51 0 0 0 0 0
✅ Shard import-export-02 99 0 0 0 0 0
✅ Shard ingestion-01 45 0 0 0 0 0
✅ Shard ingestion-02 55 0 0 0 0 0
✅ Shard reindex-01 40 0 0 0 0 0
✅ Shard search-01 12 0 0 0 0 0
✅ Shard search-rbac-01 29 0 0 0 0 0
🟡 5 flaky test(s) (passed on retry)
  • Features/DomainFilterQueryFilter.spec.ts › 3-level domain hierarchy: SubSubDomain assets visible when SubDomain selected (shard chromium-16, 1 retry)
  • Pages/DataProductAndSubdomains.spec.ts › Add assets to data product and verify count (shard chromium-16, 1 retry)
  • Pages/ExplorePageRightPanel_KnowledgeCenter.spec.ts › Should remove user owner for knowledgeCenter (shard chromium-19, 1 retry)
  • Features/EntityRenameConsolidation.spec.ts › Domain - multiple rename + update cycles should work (shard chromium-20, 1 retry)
  • Features/ColumnBulkOperations.spec.ts › should select and edit nested STRUCT field (shard chromium-22, 1 retry)

📦 Download artifacts

How to debug locally
# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip    # view trace

@harshach
harshach added this pull request to the merge queue Sep 24, 2026
Merged via the queue into main with commit 60ca022 Sep 24, 2026
156 of 159 checks passed
@harshach
harshach deleted the harshach/table-metadata-batch-reads branch September 24, 2026 19:47
timothybrush pushed a commit to timothybrush/OpenMetadata that referenced this pull request Sep 27, 2026
…text> (open-metadata#33642)

* Scope the JDBI test decorators on Predicate<StatementContext>

Three PRs in the open-metadata#32946 stack each carry their own copy of these decorators and
now collide with the versions open-metadata#33539 landed on main:

  CONFLICT (add/add) SqlQueryCounter.java   open-metadata#33344, open-metadata#33355
  CONFLICT (add/add) SqlFailureProbe.java   open-metadata#33362

Their copies are not gratuitous - they scope on Predicate<StatementContext>
rather than the BooleanSupplier that merged, and open-metadata#33344 and open-metadata#33355 already call
the three-argument forRequests and deadlockOnce. This makes main's copy the one
they call, so the dedup on rebase is a deletion rather than a rewrite.

Predicate<StatementContext> is also the better answer to the review on open-metadata#33539
that forRequests was too broad. A fragment alone cannot tell the request under
test apart from a concurrent one running the same SQL; the caller needs a look
at each candidate statement. SqlFailureProbe.forRequests therefore returns, but
requiring the caller's predicate rather than matching any in-flight request.

SqlFailureProbe.deadlockOnce covers open-metadata#33344's SqlQueryCounter.deadlockOnce so
EntityRepositoryGoldenIT becomes a one-line swap. Injection stays in the probe
rather than moving into the counter: a counter that also throws is two jobs in
one class, and the probe's one-shot claim is already a compareAndSet.

16 unit tests, both guards verified to fail without the code that satisfies
them - dropping the predicate gate gives "a matching statement the predicate
rejects must not be counted", and replacing the CAS with a check-then-act gives
"both threads were past the guard at once ... expected: <1> but was: <2>".

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Cover the request-scoped overloads, which nothing exercised

Review feedback, and correct: forRequests was called by nothing but itself. The
unit tests injected predicates through the package-private constructor and
SqlTestDecoratorsIT only used the calling-thread ones, so the composed scope -
"a request is in flight AND the caller's predicate accepts" - was the one line
in these classes with no coverage. It is also the line where a regression is
silent: get it wrong and every REST-driven statement is rejected, or every one
is accepted, and a test supplying its own predicate would never notice.

RequestLatencyContext.startRequest and clearContext are public statics, so the
composition is testable without a server. Four tests, two per class: a matching
statement outside any request is not counted or claimed, the same statement
inside one is, and a caller predicate that rejects still wins while a request
is in flight.

Each half is independently guarded. Dropping the request check fails with "no
request in flight, so there is nothing to attribute the statement to"; dropping
the caller predicate fails with "a request is in flight but the caller's
predicate rejects this statement". Verified both ways.

20 unit tests total.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Replace deadlockOnce with a scope-free deadlock() supplier

Review follow-up from @manerow, and the trap is real. deadlockOnce built its
probe through the calling-thread constructor, while the open-metadata#33344 factory it was
meant to replace is request-scoped. Its only call site, EntityRepositoryGoldenIT,
drives a PATCH over REST, so the statement runs on a Jetty worker: a
calling-thread probe never fires, and the replay test goes green without ever
exercising the replay. Silent false pass, in the one place whose job is to prove
a deadlock is retried.

A convenience that has to guess a scope will keep guessing wrong, so there is no
longer one. deadlock() returns the failure shape DeadlockRetry replays and
composes with either scope, which makes the mistake impossible to make by
accident:

  new SqlFailureProbe(jdbi, fragment, deadlock())                      // this thread
  SqlFailureProbe.forRequests(jdbi, fragment, deadlock(), mine::match) // a request

Two claims in this PR were also wrong and are corrected in the description. The
open-metadata#33344 call site counts as well as injects - assertEquals(2, writes.count()) -
and no factory here does both, so the swap is not one line; it nests a counter
around a probe. And SqlQueryCounter.afterFirst is still not provided, so open-metadata#33344
cannot delete its copy outright either. A new test pins the nesting: the probe
sits outermost while both are open, closing it hands the logger back to the
counter rather than the application, and the chain unwinds to the original.

21 unit tests.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Move the composition test to the IT, where it can assert behaviour

Review feedback, and correct: assertSame on the SqlLogger chain is wiring, not
behaviour, and passes even if delegation stops invoking the inner decorator -
the one failure it needed to catch.

I had justified it by saying a real StatementContext could not be built here.
That was wrong twice over. StatementContext is not final; it has a private
constructor that reflection can reach. But the signature is not stable: this
module resolves jdbi3-core 3.37.1, whose constructor takes (ConfigRegistry,
ExtensionMethod), while 3.47.0 takes a third Type argument. A unit test built on
that would break on a minor dependency bump.

So the test moves to SqlTestDecoratorsIT, where real statements produce real
contexts and no reflection is needed. It now asserts what one statement does to
both decorators: the outer probe fires, the inner counter still sees the same
statement, and once the probe is spent the counter keeps counting through it.
The unit-level wiring assertion is deleted rather than kept alongside.

20 unit tests; the composition case runs in the IT lane.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>

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.

Table custom-metric and column-extension reads scale with column count

2 participants