Skip to content

Commit 57a9113

Browse files
rustyconoverclaude
andcommitted
catalog: count=0 in estimated_object_count is a hard guarantee for the C++ client
Documents that ``SchemaInfo.estimated_object_count[kind] = 0`` is the C++ client's signal to skip ``catalog_schema_contents_*`` and per-name lookup RPCs entirely — non-zero values remain approximate hints. Mark the load-bearing zero-handling in ``Schema.to_schema_info`` so a future maintainer doesn't "fix" empty-key population into omission. Three test fixtures had a latent contract bug: their declarative ``Schema(tables=[])`` auto-populated count=0 via ``to_schema_info``, but the actual tables were exposed dynamically via ``schema_contents`` overrides. The new bypass made the inconsistency observable as silent "table not found" — fix each by overriding ``schemas()`` to report the real population (or strip the field entirely on writable catalogs whose population is dynamic): - ``schema_reconcile`` worker: report ``len(TABLES)`` for the main schema. - ``projection_repro`` worker: report ``len(_TABLE_NAMES)`` for main. - ``writable`` worker: clear ``estimated_object_count`` on static schemas so the transactor's dynamic tables aren't masked. Also extend ``InMemoryCatalog.schemas`` to emit explicit 0 for kinds the fixture cannot model at all (functions, indexes), exercising the bypass paths through the standard ``vgi-fixture-worker`` for integration tests. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 4040d1b commit 57a9113

6 files changed

Lines changed: 91 additions & 4 deletions

File tree

‎vgi/_test_fixtures/catalog.py‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,20 @@ def schemas(self, *, attach_id: AttachId, transaction_id: TransactionId | None)
313313
result = []
314314
for schema_data in catalog.schemas.values():
315315
# 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).
316+
# the C++ side's eager-load gate has a real signal to act on. The
317+
# InMemoryCatalog only models tables/views/macros — for kinds it
318+
# cannot model at all (functions, indexes), emit explicit ``0``
319+
# so the client triggers the zero-count RPC bypass instead of
320+
# paying empty round-trips for kinds that genuinely cannot exist
321+
# here. This is load-bearing for the bypass integration test.
320322
estimated = {
321323
"table": len(schema_data.tables),
322324
"view": len(schema_data.views),
323325
"macro": len(schema_data.macros),
326+
"index": 0,
327+
"scalar_function": 0,
328+
"aggregate_function": 0,
329+
"table_function": 0,
324330
}
325331
result.append(
326332
SchemaInfo(

‎vgi/_test_fixtures/projection_repro/worker.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
AttachId,
4646
ReadOnlyCatalogInterface,
4747
ScanFunctionResult,
48+
SchemaInfo,
4849
SchemaObjectType,
4950
SerializedSchema,
5051
TableInfo,
@@ -355,6 +356,27 @@ def _info(self, table_name: str) -> TableInfo:
355356
check_constraints=[],
356357
)
357358

359+
def schemas(self, *, attach_id: AttachId, transaction_id: TransactionId | None) -> list[SchemaInfo]:
360+
# Override the declarative ``Schema(tables=[])``-derived
361+
# ``estimated_object_count[table] = 0`` with the real population.
362+
# Without this, the C++ client treats the static zero as a hard
363+
# guarantee and skips ``catalog_schema_contents_tables``, hiding
364+
# every table this catalog publishes via the override below.
365+
infos = super().schemas(attach_id=attach_id, transaction_id=transaction_id)
366+
for i, info in enumerate(infos):
367+
if info.name == "main":
368+
infos[i] = SchemaInfo(
369+
attach_id=info.attach_id,
370+
name=info.name,
371+
comment=info.comment,
372+
tags=info.tags,
373+
estimated_object_count={
374+
**(info.estimated_object_count or {}),
375+
"table": len(_TABLE_NAMES),
376+
},
377+
)
378+
return infos
379+
358380
def schema_contents(
359381
self,
360382
*,

‎vgi/_test_fixtures/schema_reconcile/worker.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
AttachId,
4040
ReadOnlyCatalogInterface,
4141
ScanFunctionResult,
42+
SchemaInfo,
4243
SchemaObjectType,
4344
SerializedSchema,
4445
TableInfo,
@@ -524,6 +525,28 @@ def _table_info(self, spec: TableSpec) -> TableInfo:
524525
supports_delete=True,
525526
)
526527

528+
def schemas(self, *, attach_id: AttachId, transaction_id: TransactionId | None) -> list[SchemaInfo]:
529+
# The declarative ``Schema(tables=[])`` would auto-populate
530+
# ``estimated_object_count[table] = 0``, which the C++ client treats
531+
# as a hard guarantee and uses to skip the bulk RPC. But this catalog
532+
# publishes tables via the ``schema_contents`` override below, not
533+
# via the declarative ``tables=`` field — so the count is wrong.
534+
# Override at the catalog level to report the real population.
535+
infos = super().schemas(attach_id=attach_id, transaction_id=transaction_id)
536+
for i, info in enumerate(infos):
537+
if info.name == _SCHEMA_NAME:
538+
infos[i] = SchemaInfo(
539+
attach_id=info.attach_id,
540+
name=info.name,
541+
comment=info.comment,
542+
tags=info.tags,
543+
estimated_object_count={
544+
**(info.estimated_object_count or {}),
545+
"table": len(TABLES),
546+
},
547+
)
548+
return infos
549+
527550
def schema_contents(
528551
self,
529552
*,

‎vgi/_test_fixtures/writable/worker.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,22 @@ def schemas(
539539
) -> list[SchemaInfo]:
540540
"""List schemas — merge static catalog schemas with transactor schemas."""
541541
static_schemas = super().schemas(attach_id=attach_id, transaction_id=transaction_id)
542+
# Static ``Schema(tables=[])`` declaration would auto-populate
543+
# ``estimated_object_count[table] = 0``, which the C++ client treats
544+
# as a hard guarantee and skips the bulk RPC. But this catalog adds
545+
# tables dynamically via the transactor, so the static zero is wrong.
546+
# Strip estimated_object_count entirely — the client falls back to its
547+
# default of 1 (unknown / eager-load), which restores correct lookups.
548+
static_schemas = [
549+
SchemaInfo(
550+
attach_id=s.attach_id,
551+
name=s.name,
552+
comment=s.comment,
553+
tags=s.tags,
554+
estimated_object_count=None,
555+
)
556+
for s in static_schemas
557+
]
542558
static_names = {s.name.lower() for s in static_schemas}
543559

544560
if not transaction_id:

‎vgi/catalog/catalog_interface.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,20 @@ class SchemaInfo(CatalogObject, ArrowSerializableDataclass):
194194
# ``LoadEntries`` and per-name single-entry RPCs. Workers may omit the
195195
# field entirely or any individual key — the client treats absent counts
196196
# as 1, so unspecified populations bias toward eager bulk-load.
197+
#
198+
# **The value 0 is a hard guarantee, not an estimate.** When a count is
199+
# exactly 0 the client skips the corresponding ``catalog_schema_contents_*``
200+
# bulk RPC entirely and short-circuits per-name lookups
201+
# (``catalog_table_get`` / ``catalog_view_get`` / ``catalog_index_get``).
202+
# If a worker reports 0 for a kind that actually has entries,
203+
# ``SELECT … FROM s.x`` silently returns "not found" — only declare 0 for
204+
# kinds the worker knows are empty in its current view of the schema.
205+
# Cross-session DDL on the same catalog (another connection creating a
206+
# view in a schema this connection has cached as zero-views) is handled
207+
# the same way as any other stale catalog cache: ``vgi_clear_cache()`` or
208+
# re-attach. Time-travel AT-clause queries do not honor the bypass — they
209+
# always issue the per-name RPC because a historical version may have had
210+
# entries the current view does not.
197211
estimated_object_count: dict[str, int] | None = None
198212

199213

‎vgi/catalog/descriptors.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,12 @@ def to_schema_info(self, attach_id: AttachId) -> SchemaInfo:
665665
the ``scalar_function`` key and leave the others at the client-side
666666
default of 1 (i.e. eager-load) — workers wanting finer control can
667667
return their own SchemaInfo rather than calling this helper.
668+
669+
**Zero counts are load-bearing.** Empty declarative collections
670+
(e.g. ``views=()``) emit ``0`` here, which the C++ client treats as
671+
a hard guarantee and uses to skip the corresponding bulk + per-name
672+
RPCs entirely. Do not "optimize" this into omitting empty keys —
673+
absence reads as count=1 (unknown), suppressing the RPC bypass.
668674
"""
669675
return SchemaInfo(
670676
attach_id=attach_id,

0 commit comments

Comments
 (0)