|
| 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. |
0 commit comments