Skip to content

Commit 4040d1b

Browse files
rustyconoverclaude
andcommitted
catalog: add estimated_object_count to SchemaInfo for client-side eager-load gate
Adds a nullable ``dict[str, int]`` map keyed by the same names the C++ extension uses for set-cache instrumentation (table, view, scalar_function, aggregate_function, table_function, macro, index). Workers populate it to let the client decide between bulk LoadEntries and per-name RPCs without an extra round trip. Both the declarative ``Schema.to_schema_info`` helper and the InMemoryCatalog test fixture populate it from their declared / actual population. Missing field / missing keys are interpreted client-side as 1 (eager-load), so existing workers don't change behavior unless they opt in. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3a5e8dd commit 4040d1b

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎vgi/_test_fixtures/catalog.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,23 @@ def schemas(self, *, attach_id: AttachId, transaction_id: TransactionId | None)
312312
catalog = self._get_catalog(attach_id)
313313
result = []
314314
for schema_data in catalog.schemas.values():
315-
# Update the attach_id in the returned info
315+
# Populate estimated_object_count from the in-memory population so
316+
# the C++ side's eager-load gate has a real signal to act on. We
317+
# only know about tables/views/macros in the fixture; other kinds
318+
# are omitted (the client treats absent keys as 1, biasing toward
319+
# eager bulk-load).
320+
estimated = {
321+
"table": len(schema_data.tables),
322+
"view": len(schema_data.views),
323+
"macro": len(schema_data.macros),
324+
}
316325
result.append(
317326
SchemaInfo(
318327
attach_id=attach_id,
319328
name=schema_data.info.name,
320329
comment=schema_data.info.comment,
321330
tags=schema_data.info.tags,
331+
estimated_object_count=estimated,
322332
)
323333
)
324334
return result

‎vgi/catalog/catalog_interface.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,14 @@ class SchemaInfo(CatalogObject, ArrowSerializableDataclass):
187187

188188
attach_id: AttachId
189189
name: str
190+
# Approximate population per object kind, keyed by the same names the C++
191+
# extension uses for its set-cache instrumentation: ``"table"``, ``"view"``,
192+
# ``"scalar_function"``, ``"aggregate_function"``, ``"table_function"``,
193+
# ``"macro"``, ``"index"``. Used by the client to pick between bulk
194+
# ``LoadEntries`` and per-name single-entry RPCs. Workers may omit the
195+
# field entirely or any individual key — the client treats absent counts
196+
# as 1, so unspecified populations bias toward eager bulk-load.
197+
estimated_object_count: dict[str, int] | None = None
190198

191199

192200
@dataclass(frozen=True)

‎vgi/catalog/descriptors.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,29 @@ class Schema:
655655
indexes: Sequence[Index] = ()
656656

657657
def to_schema_info(self, attach_id: AttachId) -> SchemaInfo:
658-
"""Convert to SchemaInfo for catalog response."""
658+
"""Convert to SchemaInfo for catalog response.
659+
660+
Populates ``estimated_object_count`` from the declared population so
661+
the C++ extension's eager-load gate can choose between bulk
662+
``LoadEntries`` and per-name single-entry RPCs without an extra round
663+
trip. Splitting functions into scalar / aggregate / table requires a
664+
type discriminator we don't have here, so we report the total under
665+
the ``scalar_function`` key and leave the others at the client-side
666+
default of 1 (i.e. eager-load) — workers wanting finer control can
667+
return their own SchemaInfo rather than calling this helper.
668+
"""
659669
return SchemaInfo(
660670
attach_id=attach_id,
661671
name=self.name,
662672
comment=self.comment,
663673
tags=dict(self.tags),
674+
estimated_object_count={
675+
"table": len(self.tables),
676+
"view": len(self.views),
677+
"scalar_function": len(self.functions),
678+
"macro": len(self.macros),
679+
"index": len(self.indexes),
680+
},
664681
)
665682

666683

0 commit comments

Comments
 (0)