Skip to content

Commit b12518b

Browse files
rustyconoverclaude
andcommitted
feat: protocol 3.3 FunctionInfo.visibility; list every table function
The DuckDB extension takes a table scan or write function's capabilities (projection/filter pushdown, row ids, has_finalize, required secrets, ...) only from its entry in the schema function listing. Python did not list scans or write functions it was not told to, so those scans ran with every capability off, and listing them made them ordinary SQL functions. Protocol vgi.v3 3.3.0 (docs/protocol/function-visibility.md): - FunctionInfo.visibility: nullable utf8, "public" (also null) or "table_only". A table-only function backs its tables but is absent from duckdb_functions() and not callable. - ReadOnlyCatalogInterface lists every function a Table names, adding it to the table schema when the author did not register it. Write functions are always table_only; a scan is table_only unless Table(expose_scan=True) or the scan is also in a schema functions. - Schema.to_schema_info counts those functions, so a zero estimated_object_count never hides the listing. - Drops the Catalog check that an UPDATE/DELETE table scan be repeated in its schema functions (it is listed automatically now). - txfix fixture per the shared contract: items_scan and items_update table_only, labels_scan exposed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 771d23a commit b12518b

22 files changed

Lines changed: 610 additions & 62 deletions

‎CHANGELOG.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
### Protocol 3.3: table scans and write functions are table-only
6+
7+
- **Requires the matching DuckDB extension.** The protocol version is now `vgi.v3` / `3.3.0`; peers match on
8+
major and minor, so 3.3 workers and 3.2 clients reject each other.
9+
- `FunctionInfo` gains `visibility` (`"public"`, the default, or `"table_only"`), with the constants
10+
`FUNCTION_VISIBILITY_PUBLIC`, `FUNCTION_VISIBILITY_TABLE_ONLY` and `FUNCTION_VISIBILITIES` in `vgi.catalog`.
11+
See `docs/protocol/function-visibility.md`.
12+
- `ReadOnlyCatalogInterface` now lists every function a `Table` names (scan, insert, update, delete) even when it is
13+
not in the schema's `functions`, so DuckDB always has its capabilities (projection/filter pushdown, row ids,
14+
`has_finalize`, required secrets). Scans that were not listed used to run with every capability off.
15+
- **User-visible:** write functions are always table-only, and a table's scan is table-only unless the table sets
16+
the new `Table(expose_scan=True)` or the scan class is also registered in a schema's `functions`. Table-only
17+
functions disappear from `duckdb_functions()` and cannot be called from SQL.
18+
- The requirement to repeat an UPDATE/DELETE table's scan in the schema's `functions` is gone (it is listed for you;
19+
a scan repeated there stays public).
20+
- `Schema.to_schema_info` counts the tables' functions in `estimated_object_count`.

‎docs/catalog-interface.md‎

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Information about a function in a schema:
154154
| `argument_monotonicity` | `list[ArgumentMonotonicity] \| None` | Scalar-only claims aligned exactly with `arguments`; a vararg declaration occupies one slot |
155155
| `comment` | `str \| None` | Optional description |
156156
| `tags` | `dict[str, str]` | Key-value metadata |
157+
| `visibility` | `str \| None` | Protocol 3.3: `"public"` (or `None`) for an ordinary function, `"table_only"` for one listed only so a table can resolve it (see [Table functions and visibility](#table-functions-and-visibility)) |
157158

158159
### SchemaObjectType
159160

@@ -686,6 +687,40 @@ if __name__ == "__main__":
686687
| **Automatic scan handling** | Function-backed tables don't need `table_scan_function_get()` |
687688
| **Type safety** | Frozen dataclasses with runtime validation |
688689

690+
### Table functions and visibility
691+
692+
DuckDB takes a table's scan and write capabilities (projection, filter and sampling pushdown, row
693+
ids, `has_finalize`, required secrets, partitioning, ordering) only from the named function's entry
694+
in the schema's function listing. `ReadOnlyCatalogInterface` therefore lists every function a
695+
`Table` names (`function`, `insert_function`, `update_function`, `delete_function`) whether or not
696+
you repeat it in the schema's `functions`, and marks each with the protocol 3.3
697+
`FunctionInfo.visibility`:
698+
699+
| Function | Visibility |
700+
|---|---|
701+
| insert, update, delete function | always `"table_only"` |
702+
| scan `function` | `"table_only"`, unless `Table(expose_scan=True)` or the class is also in a schema's `functions` |
703+
| anything else in a schema's `functions` | public |
704+
705+
A `"table_only"` function backs its tables but is not a SQL function: it is absent from
706+
`duckdb_functions()` and `SELECT * FROM cat.main.items_scan()` fails. To let users call a scan
707+
directly as well, set `expose_scan`:
708+
709+
```python test="skip"
710+
Schema(
711+
path=["main"],
712+
tables=[
713+
Table(name="items", function=ItemsScan, update_function=ItemsUpdate), # items_scan hidden
714+
Table(name="labels", function=LabelsScan, expose_scan=True), # labels_scan() callable
715+
],
716+
)
717+
```
718+
719+
The Python `Client` can still call any function by name (`Client.table_function`), table-only or not.
720+
A hand-written `CatalogInterface` that builds its own `FunctionInfo` listing sets `visibility`
721+
itself (`FUNCTION_VISIBILITY_TABLE_ONLY` from `vgi.catalog`) and must list every function its tables
722+
return from `table_scan_function_get` / `table_*_function_get`.
723+
689724
### Writable tables
690725

691726
A `Table` can declare `insert_function`, `update_function` and `delete_function` (table in-out
@@ -714,12 +749,12 @@ UPDATE and DELETE identify rows by the row-id column, which DuckDB reads as a *v
714749
table's scan `function` must therefore:
715750

716751
1. emit a row-id column, built with `row_id_field()` (`rowid BIGINT`, metadata key `is_row_id`);
717-
2. declare `projection_pushdown = True` in its `Meta` and honour `params.output_schema`;
718-
3. be listed in the `functions` of the table's `Schema`, which is how DuckDB learns (2).
752+
2. declare `projection_pushdown = True` in its `Meta` and honour `params.output_schema`.
719753

720-
`Table` checks (1) and (2), `Catalog` checks (3); otherwise UPDATE/DELETE would fail with DuckDB's
721-
"Virtual columns require projection pushdown". Write results never include the row id:
722-
`write_result_schema` and the batch helpers drop it (`user_columns()` does the same for a schema).
754+
`Table` checks both; otherwise UPDATE/DELETE would fail with DuckDB's "Virtual columns require
755+
projection pushdown". DuckDB learns (2) from the scan's function listing, which the catalog sends for
756+
you (see [Table functions and visibility](#table-functions-and-visibility)). Write results never
757+
include the row id: `write_result_schema` and the batch helpers drop it (`user_columns()` does the same for a schema).
723758
`write_count_batch`, `write_rows_batch` and `write_changes_batch` build one mode each.
724759

725760
### Tables with Explicit Columns

‎docs/catalog_publication.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Batched catalog contents and reusable publications
22

3-
VGI wire revision **3.2.0** uses the `vgi.v3` route and retains
3+
VGI wire revision **3.3.0** uses the `vgi.v3` route and retains
44
`catalog_contents` with six catalog-wide Arrow IPC streams: schemas, tables,
55
views, functions, macros and indexes. Each stream can contain multiple batches.
66
Null means an empty category. Function and macro subtype fields remain intact.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Function visibility and table functions (protocol 3.3)
2+
3+
Status: **normative**. Introduced in `vgi.v3` / `3.3.0`.
4+
5+
## Problem
6+
7+
A table's descriptor names its scan function and its write functions (insert, update, delete). The
8+
client binds them by name over RPC, but it takes their capabilities only from the function's entry in
9+
the schema's function listing (`catalog_schema_contents_functions`, or the batched
10+
`catalog_contents`): projection, filter and sampling pushdown, late materialization, required
11+
secrets, partitioning, ordering, filter profiles, `has_finalize`, and the write schema. A worker that
12+
did not list a table's scan therefore had every capability silently off (a row-id table failed with
13+
"Virtual columns require projection pushdown"), and a worker that did list them made them ordinary
14+
SQL functions, cluttering `duckdb_functions()` and letting users call write functions directly.
15+
16+
## `FunctionInfo.visibility`
17+
18+
`FunctionInfo` gains one optional field:
19+
20+
| Field | Arrow type | Values |
21+
|---|---|---|
22+
| `visibility` | nullable `utf8` (a plain string, not a dictionary or enum type) | `"public"`, `"table_only"`; null or absent means `"public"` |
23+
24+
- **`public`**: an ordinary catalog function. The client exposes it to SQL: it appears in
25+
`duckdb_functions()` and autocomplete and can be called, qualified or not.
26+
- **`table_only`**: the client keeps the function's full description but does not expose it to SQL.
27+
It is absent from `duckdb_functions()` and autocomplete and cannot be called, not even fully
28+
qualified. The client uses it only to resolve the functions tables name.
29+
30+
A client MUST reject any other value at ATTACH with an error that names the function. A worker MUST
31+
NOT send another value.
32+
33+
## Listing rule
34+
35+
A worker MUST list, in the function listing, every function a table descriptor names (its scan
36+
function and each of its insert, update and delete functions), so the client always has their
37+
capabilities. Then:
38+
39+
1. Write functions (insert, update, delete) are always `table_only`.
40+
2. A table's scan function is `table_only` by default. The author opts in to a SQL-callable scan
41+
with one flag on the table descriptor (`expose_scan` in Python and Rust, `exposeScan` in
42+
TypeScript and Java, `ExposeScan` in Go and C#; default false). A scan the author also registers
43+
as an ordinary function is `public`.
44+
3. Functions not named by any table are unchanged: `public`.
45+
46+
The SDKs enforce this rule automatically; authors do not set `visibility` by hand unless they build
47+
their own listing.
48+
49+
## Client resolution
50+
51+
To resolve a function a table names, the client looks it up among the visible functions (the
52+
table's schema, the schema the worker's redirect claims, then the default schema), then among the
53+
`table_only` functions, then in the engine's own catalog (so delegation to built-in scans such as
54+
`read_parquet` keeps working). If nothing resolves, binding fails with an error naming the worker,
55+
the table and the function, saying the worker must list it. There is no silent fallback to a scan
56+
with every capability off.
57+
58+
## Compatibility
59+
60+
Protocol 3.3.0 is a minor bump of `vgi.v3`. Clients and workers match on exact major and minor, so 3.3
61+
peers reject 3.2 peers. User-visible change: table scans and write functions disappear from
62+
`duckdb_functions()` unless the table sets `expose_scan`, or the scan is also registered as an ordinary
63+
function.
64+
65+
## Python surface
66+
67+
- `FunctionInfo.visibility`, with the constants `FUNCTION_VISIBILITY_PUBLIC`,
68+
`FUNCTION_VISIBILITY_TABLE_ONLY` and `FUNCTION_VISIBILITIES` in `vgi.catalog`.
69+
- `Table(expose_scan=...)`.
70+
- `ReadOnlyCatalogInterface` (declarative `Catalog`) lists every table-named function in the
71+
table's schema when the author did not register it anywhere, and sets `visibility` per the rule.
72+
`Schema.to_schema_info` counts those functions, so the client never skips the listing on a zero
73+
`estimated_object_count`.
74+
- The former requirement to repeat an UPDATE/DELETE table's scan in the schema's `functions` is
75+
gone; a scan repeated there is public, as before.

‎docs/protocol/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Each document declares its own status; “proposed” means the contract is stil
88
| [VGI Filter Encoding v2](vgi-filter-encoding-v2-spec.md) | **Normative, proposed** | Engine-neutral wire format, semantics, validation, and conformance requirements for `vgi.filters.v2`. |
99
| [VGI Runtime-Filter Artifacts](vgi-runtime-filter-artifacts.md) | **Normative optional extension, proposed** | Additional requirements for capability-gated advisory runtime-pruning artifacts. Base filter-v2 conformance does not require this extension. |
1010
| [VGI DuckDB Filter Adapter](vgi-duckdb-filter-adapter.md) | **Informative implementation guide, proposed** | DuckDB 1.5 and 2.0 mappings into the normative filter-v2 wire contract. |
11+
| [Function visibility](function-visibility.md) | **Normative** | Protocol 3.3 `FunctionInfo.visibility` (`public` / `table_only`) and the rule that every function a table names is listed. |
1112
| [VGI Secrets](vgi-secrets.md) | **Normative** | How a worker asks for client-side secrets, the two-phase bind, and the layout of the secrets batch. |
1213
| [VGI catalog query pushdown](vgi-catalog-query-pushdown-design.md) | **Informative implementation design, proposed** | Updated 2026-10-06: proposed VGI 2.2 query preparation, DuckDB 1.5 explicit execution, and DuckDB 2.0 bound-plan SQL export for automatic pushdown. |
1314
| [Proposed VGI protocol changes for DuckDB 2.0](vgi-protocol-proposed-changes.md) | **Informative design/audit report** | Rationale, migration inventory, implementation status, and deferred protocol decisions. It is not an implementation specification. |

‎docs/protocol/macro-contract.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Status: development contract for the combined successor protocol. The wire
44
records use one canonical overload-family representation while builds remain
55
on DuckDB 1.5. Native SQL CREATE MACRO remains unsupported; creation through
66
the catalog API and native discovery/execution are distinct paths.
7-
The breaking successor uses `vgi.v3` / `3.2.0`; it is incompatible with
7+
The breaking successor uses `vgi.v3` / `3.3.0`; it is incompatible with
88
released `vgi.v2` implementations.
99

1010
The [October 23 combined review](shared-catalog-values.md#combined-protocol-review--october-23-2026)

‎docs/protocol/projection-expressions.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Optional scalar projection expressions
22

33
This contract is part of the combined, unpublished DuckDB 2.0 protocol
4-
transition, identified as `vgi.v3` / `3.2.0`. It can be implemented and tested
4+
transition, identified as `vgi.v3` / `3.3.0`. It can be implemented and tested
55
while the native adapter still builds against DuckDB 1.5. The successor is
66
unpublished and still requires coordinated release qualification.
77

‎docs/protocol/shared-catalog-values.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ records and bounded reference behavior on the DuckDB 2.0 preparation branch.
55
The combined-design section distinguishes implemented SQL/constraint records
66
and reference proofs from the remaining public API and execution work. Both are
77
part of one combined successor contract. Published main now uses `vgi.v2` / `2.2.0`. The
8-
unpublished successor now uses `vgi.v3` / `3.2.0` for its incompatible changes.
8+
unpublished successor now uses `vgi.v3` / `3.3.0` for its incompatible changes.
99
This selects the protocol identity; final coordinated release qualification remains open. The development snapshot
1010
carries typed schema/table options,
1111
layouts, raw column mutation paths, and capability negotiation. See the

‎docs/protocol/vgi-catalog-query-pushdown-design.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and automatic pushdown remain read-only.
1313
The implementation belongs to the **combined successor protocol release**, alongside the
1414
catalog/type changes in the [manifest](duckdb-2.0-manifest.json). It does not reserve a separate
1515
minor release. Published main now uses `vgi.v2` / `2.2.0`; the prepared successor
16-
now uses `vgi.v3` / `3.2.0`. Separate versioned endpoints/processes, draining old
16+
now uses `vgi.v3` / `3.3.0`. Separate versioned endpoints/processes, draining old
1717
sessions, and reattaching/repreparing remain the migration policy. Coordinated
1818
release qualification is still required. See the
1919
[latest-main integration checkpoint](duckdb-2.0-main-integration-2026-10-24.md).
@@ -1361,7 +1361,7 @@ universal speedup percentage; establish budgets from these measurements before d
13611361
## 13. Compatibility, alternatives, and launch gates
13621362

13631363
Published main now uses **2.2.0** under **`vgi.v2`**. The prepared Python SDK, other SDKs and extension
1364-
use **3.2.0** under **`vgi.v3`**.
1364+
use **3.3.0** under **`vgi.v3`**.
13651365
The query capability, preparation/release RPCs and parameter metadata join the combined breaking
13661366
successor contract. The selected major version and routing/migration policy apply to that package;
13671367
do not publish this development surface as a compatible 2.2.0 update.

‎mkdocs.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ nav:
145145
- protocol/index.md
146146
- "Partition distribution (normative)": protocol/partition-distribution.md
147147
- "Filtered scan planning (normative)": protocol/scan-planning.md
148+
- "Function visibility (normative)": protocol/function-visibility.md
148149
- "Filter Encoding v2 (normative, proposed)": protocol/vgi-filter-encoding-v2-spec.md
149150
- "Runtime-filter artifacts (optional extension)": protocol/vgi-runtime-filter-artifacts.md
150151
- "Opaque values: sealing (normative)": protocol/vgi-opaque-data-sealing.md

0 commit comments

Comments
 (0)