Worker & serving
On this page
Registering functions and running a worker over each transport.
struct AttachDecision
Section titled âstruct AttachDecisionâtype AttachDecision struct {ResolvedDataVersion stringResolvedImplementationVersion stringAttachOpaqueData []byte}Description
AttachDecision is the custom response returned by an AttachValidator. Any non-empty ResolvedDataVersion / ResolvedImplementationVersion value is forwarded to the client so it appears as a duckdb_databases().tag. If AttachOpaqueData is nil, the worker falls back to the catalog name.
func type AttachScanBranchesGetHandler
Section titled âfunc type AttachScanBranchesGetHandlerâtype AttachScanBranchesGetHandler func(attachOpaqueData []byte, schemaName, name string, atUnit, atValue *string) (result *ScanBranchesResult, handled bool, err error)Description
AttachScanBranchesGetHandler is the attach-opaque-data-aware handler for catalog_table_scan_branches_get. Return (result, true) to serve a multi-branch table; (nil, false) to fall through (the C++ extension then falls back to catalog_table_scan_function_get).
func type AttachScanFunctionGetHandler
Section titled âfunc type AttachScanFunctionGetHandlerâtype AttachScanFunctionGetHandler func(attachOpaqueData []byte, schemaName, name string, atUnit, atValue *string) (result *ScanFunctionResult, handled bool, err error)Description
AttachScanFunctionGetHandler is the attach-opaque-data-aware version of ScanFunctionGetHandler. Return (result, true) to override; (nil, false) to fall through.
func type AttachTableGetHandler
Section titled âfunc type AttachTableGetHandlerâtype AttachTableGetHandler func(attachOpaqueData []byte, schemaName, name string, atUnit, atValue *string) (data []byte, handled bool, err error)Description
AttachTableGetHandler is the attach-opaque-data-aware version of TableGetHandler. Return (data, true) to override the default; return (nil, false) to fall through. Used by version-aware workers where the attach_opaque_data encodes the resolved version.
func type AttachValidator
Section titled âfunc type AttachValidatorâtype AttachValidator func(req *CatalogAttachRequestWire, callCtx *vgirpc.CallContext) (*AttachDecision, error)Description
AttachValidator is invoked by the default catalog_attach handler. It may inspect the requested data_version_spec / implementation_version, perform validation, and return resolved values. Returning an error causes the ATTACH to fail with that message â the test suite treats a âValueErrorâ RPC type as a user error the extension should surface verbatim.
func type AttachWriteFunctionGetHandler
Section titled âfunc type AttachWriteFunctionGetHandlerâtype AttachWriteFunctionGetHandler func(op WriteOp, attachOpaqueData []byte, schemaName, name string) (result *ScanFunctionResult, handled bool, err error)Description
AttachWriteFunctionGetHandler is the attach-opaque-data-aware version of catalog_table_{insert,update,delete}_function_get. Op is WriteOpInsert, WriteOpUpdate, or WriteOpDelete. Return (result, true) to route; (nil, false) to fall through to the built-in writable-catalog path or the read-only rejection.
func type CatalogVersionHook
Section titled âfunc type CatalogVersionHookâtype CatalogVersionHook func(attachOpaqueData []byte, callCtx *vgirpc.CallContext) errorDescription
CatalogVersionHook runs on every catalog_version RPC before the response is returned. Returning a non-nil error causes the RPC to fail with that message (wrapped as a ValueError). The hook can inspect call-context cookies to assert the HTTP cookie jar is round-tripping correctly â a useful regression check for versioned workers that set a sticky cookie at ATTACH time.
struct GlobalInitResponse
Section titled âstruct GlobalInitResponseâtype GlobalInitResponse struct {// ExecutionID uniquely identifies this execution.ExecutionID []byte// MaxWorkers is the maximum number of parallel workers (0 = default/4).MaxWorkers int64// OpaqueData is optional data passed to secondary inits.OpaqueData []byte}Description
GlobalInitResponse is returned by a functionâs OnInit method.
Methods
function DefaultInit
Section titled âfunction DefaultInitâfunc DefaultInit() (*GlobalInitResponse, error)DefaultInit returns a standard single-worker GlobalInitResponse (MaxWorkers: 1). Use this in OnInit for table functions that donât need parallel execution.
struct InitParams
Section titled âstruct InitParamsâtype InitParams struct {// FunctionName is the name of the function.FunctionName string// FunctionType is the type of the function.FunctionType FunctionType// Args are the parsed function arguments.Args *Arguments// OutputSchema is the output schema resolved during bind.OutputSchema *arrow.Schema// InputSchema is the input table schema (nil for table functions).InputSchema *arrow.Schema// ProjectionIDs are the projected column indices (nil = all columns).ProjectionIDs []int32// Phase is the table-in-out init phase.Phase Phase// ExecutionID is the execution ID for secondary inits.ExecutionID []byte// BindOpaqueData is opaque data from the bind phase.BindOpaqueData []byte// InitOpaqueData is opaque data from a previous global init (secondary inits).InitOpaqueData []byte// Settings is a map of DuckDB setting names to their scalar values.Settings map[string]interface{}// Secrets is a map of secret names to their value maps.Secrets Secrets// IsSecondary is true if this is a secondary init (worker init).IsSecondary bool// PushdownFilters is the pushdown filter batch (nil if none).PushdownFilters arrow.RecordBatch// JoinKeys maps keys_column name -> Arrow array carrying the join keys// referenced by FilterJoinKeys entries in PushdownFilters.JoinKeys map[string]arrow.Array// OrderByHint, when non-nil, carries an ORDER BY + LIMIT pushdown// hint set by DuckDB's RowGroupPruner optimizer.OrderByHint *OrderByHint// TableSampleHint, when non-nil, carries a TABLESAMPLE pushdown hint.TableSampleHint *TableSampleHint// Storage provides shared execution storage for cross-phase data.Storage *ExecutionStorage}Description
InitParams holds the parameters available during the init phase.
struct InitRecipe
Section titled âstruct InitRecipeâtype InitRecipe struct {BindCall BindRequestWireOutputSchemaIPC []byteFunctionName stringFunctionType FunctionTypeProjectionIDs []int32ExecutionID []byteBindOpaqueData []byteInitOpaqueData []bytePushdownFilterIPC []bytePhase PhaseIsSecondary bool// SubstreamID is the client-minted per-substream id folded into the recipe// (and so into the HTTP state token) so every rehydrated tick of one// substream sees the same id. Nil when the client did not supply one.SubstreamID []byte// ShardKey is the per-attach Durable Object routing key (att-<hex uuid>),// derived once at init from the unwrapped attach UUID and carried through// serialization so a rehydrated process/finalize turn routes storage to the// same DO without re-opening the auth-scoped seal. "" for non-attach paths.ShardKey string}Description
InitRecipe carries all serializable data needed to reconstruct ProcessParams after a state token round-trip through HTTP transport. It captures the raw IPC bytes from the init request so that the rehydration path can replay the same bind/init logic without the original wire message.
Methods
function decodeInitRecipe
Section titled âfunction decodeInitRecipeâfunc decodeInitRecipe(data []byte) (*InitRecipe, error)struct OrderByHint
Section titled âstruct OrderByHintâtype OrderByHint struct {ColumnName stringDirection OrderByDirection // "" if unspecifiedNullOrder OrderByNullOrder // "" if unspecifiedRowLimit int64 // -1 if unbounded}Description
OrderByHint is an ORDER BY + LIMIT hint pushed by the optimizer.
struct ProcessParams
Section titled âstruct ProcessParamsâtype ProcessParams struct {// FunctionName is the name of the function.FunctionName string// FunctionType is the type of the function.FunctionType FunctionType// Args are the parsed function arguments.Args *Arguments// OutputSchema is the output schema (may be projected).OutputSchema *arrow.Schema// InputSchema is the source/input table schema (nil for table functions// with no input). For a COPY ... TO sink it carries the source columns, so a// CopyToFunction can write a header even when zero rows are buffered.InputSchema *arrow.Schema// ProjectionIDs are the projected column indices (nil = all columns).ProjectionIDs []int32// Settings is a map of DuckDB setting names to their scalar values.Settings map[string]interface{}// Secrets is a map of secret names to their value maps.Secrets Secrets// ExecutionID is the execution identifier.ExecutionID []byte// SubstreamID is the stable client-minted id for this streaming// table-in-out substream. Present (identical across init / every Process /// finalize) when the client fanned this function out across per-substream// workers; use it to key per-substream accumulated state in shared storage// so a finalize that lands on a different HTTP backend than the Process// calls still finds it. Nil for the serial path, non-table-in-out// functions, or an old client that did not supply one. Mirrors vgi-python's// ProcessParams.substream_id.SubstreamID []byte// AttachScope is the per-ATTACH plaintext (the catalog's attach_opaque_data// with the framework UUID stripped). Stable across the queries of one ATTACH// session; used to scope persistent state via Storage.AttachStore(scope).// Nil when the call has no attach context.AttachScope []byte// InitOpaqueData is the opaque data from the init response.InitOpaqueData []byte// PushdownFilters is the pushdown filter batch (nil if none).PushdownFilters arrow.RecordBatch// JoinKeys maps keys_column name -> Arrow array carrying the join keys// referenced by FilterJoinKeys entries in PushdownFilters.JoinKeys map[string]arrow.Array// AtUnit/AtValue carry the AT (TIMESTAMP|VERSION ...) time-travel clause for// this scan, threaded onto the bind request embedded in init. Both nil when// the scan has no AT clause. Function-backed time-travel tables resolve the// version from these at NewState.AtUnit *stringAtValue *string// CopyFrom carries the COPY ... FROM context when this scan was opened by a// COPY-FROM statement (nil otherwise). A CopyFromFunction reads FilePath /// ExpectedSchema here in Process. Mirrors Python's// ProcessParams.init_call.bind_call.copy_from.CopyFrom *CopyFromContext// CopyTo carries the COPY ... TO context when this sink was opened by a// COPY-TO statement (nil otherwise). A CopyToFunction reads Format /// FilePath here in Process (per-shard write) and Combine (terminal write).// Mirrors Python's ProcessParams.init_call.bind_call.copy_to.CopyTo *CopyToContext// CurrentPushdownFilters is the filter state for the *current* Produce// tick. It starts at the init-time pushdown filters and is replaced// whenever DuckDB's dynamic filter tightens (DynamicFilter pushdown).// Functions that want to react to filter updates per batch should read// this field; functions that only care about static filters should use// PushdownFilters.CurrentPushdownFilters *PushdownFilters// OrderByHint, when non-nil, carries an ORDER BY + LIMIT pushdown hint.OrderByHint *OrderByHint// TableSampleHint, when non-nil, carries a TABLESAMPLE pushdown hint.TableSampleHint *TableSampleHint// Storage provides shared execution storage for cross-phase data.Storage *ExecutionStorage// Auth is the authentication context for the current request.// Always non-nil; unauthenticated requests receive vgirpc.Anonymous().Auth *vgirpc.AuthContext// BatchIndex is the DuckDB per-chunk batch index threaded into a// table_buffering_process call when the function declares// RequiresInputBatchIndex. Nil otherwise.BatchIndex *int64// IfNoneMatch is the conditional-revalidation validator carrying the// client's stored ETag. It is set when the client holds a// stale-but-revalidatable cached result and asks the worker to confirm// freshness cheaply. A function that advertised CacheControl.Revalidatable// compares it against its current validator and, when unchanged, emits a// 0-row batch tagged CacheControl{NotModified: true} instead of// re-streaming. Nil on a normal call.IfNoneMatch *string// IfModifiedSince is the conditional-revalidation validator carrying the// client's stored Last-Modified. Companion to IfNoneMatch. Nil otherwise.IfModifiedSince *string// clientLog forwards an in-band log message to the client (surfaced in// duckdb_logs() with type='VGI'). Set by the framework on the unary// table-buffering RPCs, which have no streaming OutputCollector. Nil when// in-band logging is unavailable.clientLog func(level vgirpc.LogLevel, msg string)}Description
ProcessParams holds the parameters available during the process phase.
Methods
method ClientLog
Section titled âmethod ClientLogâfunc (p *ProcessParams) ClientLog(level vgirpc.LogLevel, msg string)ClientLog emits an in-band log message to the client, if the framework wired a logging sink for this call (e.g. from table_buffering_process/combine).
func type SchemaContentsHandler
Section titled âfunc type SchemaContentsHandlerâtype SchemaContentsHandler func(attachOpaqueData []byte, schemaName string) ([]SerializedSchemaItem, bool)Description
SchemaContentsHandler lets callers override catalog_schema_contents_tables on a per-attach-opaque-data basis (e.g. return different tables per resolved data version). Return nil to fall through to the default registered-tables behaviour.
struct SecretTypeSpec
Section titled âstruct SecretTypeSpecâtype SecretTypeSpec struct {Name stringDescription stringSchema *arrow.Schema // parameter schema; use field metadata {"redact":"true"} for sensitive fields}Description
SecretTypeSpec describes a DuckDB secret type registered by the worker.
type SerializedSchemaItem
Section titled âtype SerializedSchemaItemâtype SerializedSchemaItem []byteDescription
SerializedSchemaItem is a single pre-serialized schema item (TableInfo or ViewInfo IPC bytes).
struct SettingSpec
Section titled âstruct SettingSpecâtype SettingSpec struct {Name stringDescription stringType arrow.DataTypeDefaultValue interface{} // Go value matching the Type (nil = no default)}Description
SettingSpec describes a DuckDB custom setting registered by the worker.
struct TableSampleHint
Section titled âstruct TableSampleHintâtype TableSampleHint struct {Percentage float64Seed int64}Description
TableSampleHint is a TABLESAMPLE pushdown hint.
struct Worker
Section titled âstruct Workerâtype Worker struct {scalars map[string][]ScalarFunctiontables map[string][]TableFunctiontableInOuts map[string][]TableInOutFunctiontableBufferings map[string][]TableBufferingFunctionaggregates map[string][]AggregateFunctionaggStorage *aggregateStorage// streamingSessions tracks per-execution_id state for streaming-partitioned// aggregates (aggregate_streaming_open/_chunk/_close).streamingSessions streamingSessionStorecatalogName stringcatalogComment stringcatalogTags map[string]string// globalFunctionNames / globalFunctionPrefix back the protocol-1.3.0// global_functions + global_function_prefix fields of catalog_attach: the// subset of this catalog's functions a client may republish into its own// global (system.main) namespace, and the prefix it publishes them under.// The Go analogue of vgi-python's Catalog(global_functions=...,// global_function_prefix=...).globalFunctionNames []stringglobalFunctionPrefix stringsupportsTransactions boolschemaComments map[string]stringschemaTags map[string]map[string]stringcatalog *DefaultReadOnlyCatalog// extraCatalogs are additional catalog names this worker accepts via// catalog_attach. They share the worker's registered functions but// have their own (writable) table/schema state. Indexed by name.extraCatalogs map[string]*WritableCatalog// catalogAliases are extra catalog names that ATTACH against the// worker's primary read-only catalog (no separate writable state, no// distinct catalog implementation). Useful for fixture workers that// publish multiple cross-language reproducer catalogs (e.g.// projection_repro) sharing one binary.catalogAliases map[string]struct{}// funcOrigins records, for every registered implementation, the catalog// schema that declares it and the catalog it is restricted to (if any).// Keyed by (kind, function name) with the slice index-aligned to the// same-named slice in scalars/tables/tableInOuts/tableBufferings/// aggregates, so two implementations sharing a name keep separate// origins â which is exactly what makes a name registered in two schemas// (or two catalogs) resolvable.funcOrigins map[funcKey][]funcOrigin// catalogAliasInfos carries per-alias discovery metadata (data version,// etc.) for aliases that should advertise themselves distinctly in// catalog_catalogs and mint a random per-ATTACH scope at attach (so two// ATTACHes of the same alias are isolated). Keyed by catalog name.catalogAliasInfos map[string]CatalogInfostorages sync.Map // map[hex execution ID string]*ExecutionStoragebufferingParams sync.Map // map[hex execution ID string]*bufferingParamsEntryfsOnce sync.Oncefs FunctionStoragefsErr errorsettings []SettingSpeccatalogTables map[string][]CatalogTable // schema_name â tablescatalogViews map[string][]CatalogView // schema_name â viewscatalogMacros map[string][]CatalogMacro // schema_name â macrosdynamicSchemas map[string]string // schema_name â comment (for SchemaContentsHandler-only schemas)scanFunctionGetHandler ScanFunctionGetHandlertableGetHandler TableGetHandlercatalogInfoOverride *CatalogInfoattachValidator AttachValidatorschemaContentsHandler SchemaContentsHandlerattachTableGetHandler AttachTableGetHandlerattachScanFunctionGetHandler AttachScanFunctionGetHandlerattachScanBranchesGetHandler AttachScanBranchesGetHandlerattachWriteFunctionGetHandler AttachWriteFunctionGetHandlercatalogVersionHook CatalogVersionHookauthenticateFunc vgirpc.AuthenticateFuncoauthMetadata *vgirpc.OAuthResourceMetadataoauthPkce *vgirpc.OAuthPkceConfigsecretTypes []SecretTypeSpecattachCatalogs []AttachCatalogInfoattachOptions []AttachOptionSpec// catalogAttachOptions holds per-alias-catalog option specs// (WithAttachOptionsForCatalog); a catalog absent here falls back to// attachOptions.catalogAttachOptions map[string][]AttachOptionSpeclogLevel slog.Level // slog.LevelInfo (0) by default â Info level is intentional.logHandler slog.Handler // nil means default TextHandler to stderrlogFormat LogFormat // empty means textlogLoggers []string // empty means all known loggerslogConfigured bool // true once any logging WorkerOption fireshttpSigningKey []byte // HMAC key for HTTP state tokens (explicit via WithHttpSigningKey, else ephemeral per-process)// sealOpaqueData gates AEAD sealing of catalog opaque-data envelopes. It is// enabled only when an explicit signing key is configured (WithHttpSigningKey),// matching vgi-python: an anonymous worker with an ephemeral, per-process key// (generated only so the HTTP state-token machinery has one) does not seal â// sealing binds opaque-data to a principal, and there is none without auth, so// it would only add a cross-implementation incompatibility (the published// extension round-trips plaintext opaque-data, not the longer sealed envelope).sealOpaqueData bool
// copyFromFormats holds the custom COPY ... FROM formats advertised by this// worker (one per RegisterCopyFrom). Surfaced via catalog_copy_from_formats// so the VGI extension can register a DuckDB CopyFunction per entry.copyFromFormats []copyFromFormatRecord}Description
Worker is the main VGI worker that hosts functions and serves RPC.
Methods
function NewWorker
Section titled âfunction NewWorkerâfunc NewWorker(opts âŠWorkerOption) *WorkerNewWorker creates a new VGI worker.
method RegisterAggregate
Section titled âmethod RegisterAggregateâfunc (w *Worker) RegisterAggregate(f AggregateFunction)RegisterAggregate registers an aggregate function in the catalogâs default schema. Multiple registrations with the same Name() are kept as overloads â distinguished by their ArgumentSpecs at catalog-discovery time.
method RegisterAggregateInSchema
Section titled âmethod RegisterAggregateInSchemaâfunc (w *Worker) RegisterAggregateInSchema(schemaName string, f AggregateFunction)RegisterAggregateInSchema registers an aggregate function in a named catalog schema. See RegisterScalarInSchema for why the schema is part of the identity.
method RegisterCatalogMacro
Section titled âmethod RegisterCatalogMacroâfunc (w *Worker) RegisterCatalogMacro(schemaName string, macro CatalogMacro)RegisterCatalogMacro registers a macro in the given schema of the catalog.
method RegisterCatalogSchema
Section titled âmethod RegisterCatalogSchemaâfunc (w *Worker) RegisterCatalogSchema(name, comment string)RegisterCatalogSchema declares a schema that exists in the catalog but whose tables are produced dynamically by a SchemaContentsHandler. Use when there are no registered CatalogTable/View/Macro entries to âanchorâ the schema (otherwise it wouldnât appear in catalog_schemas).
method RegisterCatalogTable
Section titled âmethod RegisterCatalogTableâfunc (w *Worker) RegisterCatalogTable(schemaName string, table CatalogTable)RegisterCatalogTable registers a table in the given schema of the catalog.
If table.Function is set, the function is also auto-registered into the dispatch table (deduped by name) so the scan resolves without a separate RegisterTable call â mirroring vgi-pythonâs _build_registry, which auto-scans each Table.function.
method RegisterCatalogView
Section titled âmethod RegisterCatalogViewâfunc (w *Worker) RegisterCatalogView(schemaName string, view CatalogView)RegisterCatalogView registers a view in the given schema of the catalog.
method RegisterCopyFrom
Section titled âmethod RegisterCopyFromâfunc (w *Worker) RegisterCopyFrom(f CopyFromFunction)RegisterCopyFrom registers a custom COPY ⊠FROM format. The function is registered as an ordinary producer-mode table function (so it appears in duckdb_functions and reuses the table scan path) AND advertised via catalog_copy_from_formats so the VGI extension registers a DuckDB CopyFunction for it. Mirrors vgi-python registering a CopyFromFunction subclass in the catalogâs function list.
method RegisterCopyTo
Section titled âmethod RegisterCopyToâfunc (w *Worker) RegisterCopyTo(f CopyToFunction)RegisterCopyTo registers a custom COPY ⊠TO format. The function is registered as a table-buffering function (so init/process/combine reuse the buffered Sink+Combine path) AND advertised via catalog_copy_from_formats with direction=âtoâ so the VGI extension registers a DuckDB CopyFunction for it. Mirrors vgi-python registering a CopyToFunction subclass in the catalogâs function list.
method RegisterScalar
Section titled âmethod RegisterScalarâfunc (w *Worker) RegisterScalar(f ScalarFunction)RegisterScalar registers a scalar function in the catalogâs default schema.
method RegisterScalarForCatalog
Section titled âmethod RegisterScalarForCatalogâfunc (w *Worker) RegisterScalarForCatalog(catalogName string, f ScalarFunction)RegisterScalarForCatalog registers a scalar function scoped to a single catalog name, in that catalogâs default schema. The function only surfaces in â and is only dispatchable from â ATTACHes of the named catalog, so two catalogs served by one worker may each declare their own implementation of the same function name.
method RegisterScalarInSchema
Section titled âmethod RegisterScalarInSchemaâfunc (w *Worker) RegisterScalarInSchema(schemaName string, f ScalarFunction)RegisterScalarInSchema registers a scalar function in a named catalog schema.
The same name may be registered in more than one schema; a schema-qualified
call (db.schema.fn(...)) then dispatches to the implementation declared in
the schema it names, rather than colliding with the other as an overload.
method RegisterTable
Section titled âmethod RegisterTableâfunc (w *Worker) RegisterTable(f TableFunction)RegisterTable registers a table function in the catalogâs default schema.
method RegisterTableBuffering
Section titled âmethod RegisterTableBufferingâfunc (w *Worker) RegisterTableBuffering(f TableBufferingFunction)RegisterTableBuffering registers a table-buffering function in the catalogâs default schema.
method RegisterTableBufferingForCatalog
Section titled âmethod RegisterTableBufferingForCatalogâfunc (w *Worker) RegisterTableBufferingForCatalog(catalogName string, f TableBufferingFunction)RegisterTableBufferingForCatalog registers a table-buffering function scoped to a single catalog (visible only under that ATTACH). See RegisterTableForCatalog for the rationale.
method RegisterTableBufferingInSchema
Section titled âmethod RegisterTableBufferingInSchemaâfunc (w *Worker) RegisterTableBufferingInSchema(schemaName string, f TableBufferingFunction)RegisterTableBufferingInSchema registers a table-buffering function in a named catalog schema. See RegisterScalarInSchema for why the schema is part of the identity.
method RegisterTableForCatalog
Section titled âmethod RegisterTableForCatalogâfunc (w *Worker) RegisterTableForCatalog(catalogName string, f TableFunction)RegisterTableForCatalog registers a table function scoped to a single catalog name. The function is invokable as normal but only surfaces in catalog_schema_contents_functions / duckdb_functions for ATTACH calls against the named catalog. Use for fixture functions that should only be visible to their own reproducer catalog (e.g. proj_repro_* under âprojection_reproâ).
method RegisterTableInOut
Section titled âmethod RegisterTableInOutâfunc (w *Worker) RegisterTableInOut(f TableInOutFunction)RegisterTableInOut registers a table-in-out function in the catalogâs default schema.
method RegisterTableInOutForCatalog
Section titled âmethod RegisterTableInOutForCatalogâfunc (w *Worker) RegisterTableInOutForCatalog(catalogName string, f TableInOutFunction)RegisterTableInOutForCatalog is the catalog-scoped sibling of RegisterTableInOut; the function is invokable as normal but only surfaces under the named catalogâs function listing. See RegisterTableForCatalog for the rationale (per-catalog function inventories that fixture tests assert on).
method RegisterTableInOutInSchema
Section titled âmethod RegisterTableInOutInSchemaâfunc (w *Worker) RegisterTableInOutInSchema(schemaName string, f TableInOutFunction)RegisterTableInOutInSchema registers a table-in-out function in a named catalog schema. See RegisterScalarInSchema for why the schema is part of the identity.
method RegisterTableInSchema
Section titled âmethod RegisterTableInSchemaâfunc (w *Worker) RegisterTableInSchema(schemaName string, f TableFunction)RegisterTableInSchema registers a table function in a named catalog schema. See RegisterScalarInSchema for why the schema is part of the identity.
method RegisterTableUnlisted
Section titled âmethod RegisterTableUnlistedâfunc (w *Worker) RegisterTableUnlisted(f TableFunction)RegisterTableUnlisted registers a table function that is invokable but never appears in any catalogâs function listing (duckdb_functions, describe.json). Use it for a function that exists only to back a catalog table: the tableâs scan resolves it by name, but exposing it as a callable table function too would be redundant surface area.
method RegisterWritableCatalog
Section titled âmethod RegisterWritableCatalogâfunc (w *Worker) RegisterWritableCatalog(c *WritableCatalog)RegisterWritableCatalog adds a writable catalog this worker handles alongside its primary read-only catalog. The catalog accepts ATTACH requests by its name and supports DDL/DML operations on user-created tables.
method RunHttp
Section titled âmethod RunHttpâfunc (w *Worker) RunHttp(addr string) errorRunHttp runs the worker serving RPC over HTTP. It listens on the given address (e.g. â127.0.0.1:0â for a random port) and prints âPORT:<n>â to stdout so callers can discover the assigned port.
method RunStdio
Section titled âmethod RunStdioâfunc (w *Worker) RunStdio()RunStdio runs the worker serving RPC over stdin/stdout.
method RunTcp
Section titled âmethod RunTcpâfunc (w *Worker) RunTcp(host string, port int, idleTimeout time.Duration) errorRunTcp runs the worker serving RPC over a raw TCP socket â the launcher transportâs AF_INET sibling. It binds host:port (host ââ defaults to 127.0.0.1; port 0 picks a free port), prints the readiness marker âTCP:<host>:<port>â with the actual bound port to stdout once listening (then writes nothing further to stdout), and self-shuts-down after idleTimeout with no active connections (<=0 disables the timeout).
Raw TCP framing carries no auth/encryption â bind loopback / a trusted network only; use RunHttp for untrusted networks.
method RunUnix
Section titled âmethod RunUnixâfunc (w *Worker) RunUnix(path string, idleTimeout time.Duration) errorRunUnix runs the worker serving RPC over an AF_UNIX socket at path â the âlauncherâ transport. It prints the readiness marker âUNIX:<path>â to stdout once the socket is listening (then writes nothing further to stdout), and self-shuts-down after idleTimeout with no active connections (<=0 disables the timeout). Mutually exclusive with HTTP.
method SetAuthenticate
Section titled âmethod SetAuthenticateâfunc (w *Worker) SetAuthenticate(fn vgirpc.AuthenticateFunc)SetAuthenticate sets an authentication callback for HTTP mode. When set, every HTTP request is validated and the resulting AuthContext is available via ProcessParams.Auth and BindParams.Auth.
method SetOAuthPkce
Section titled âmethod SetOAuthPkceâfunc (w *Worker) SetOAuthPkce(cfg vgirpc.OAuthPkceConfig)SetOAuthPkce enables the browser-based OAuth PKCE login flow for HTTP mode. It requires SetAuthenticate and SetOAuthResourceMetadata (with a ClientID) to also be configured; RunHttp applies it after both. When enabled, the server serves /_oauth/callback, /_oauth/logout, and the /_oauth/token exchange proxy, and redirects unauthenticated browser GETs to the authorization server.
method SetOAuthResourceMetadata
Section titled âmethod SetOAuthResourceMetadataâfunc (w *Worker) SetOAuthResourceMetadata(m *vgirpc.OAuthResourceMetadata)SetOAuthResourceMetadata configures OAuth Protected Resource Metadata (RFC 9728) for HTTP mode. When set, the server exposes a well-known endpoint and includes a WWW-Authenticate header on 401 responses.
method SetScanFunctionGetHandler
Section titled âmethod SetScanFunctionGetHandlerâfunc (w *Worker) SetScanFunctionGetHandler(h ScanFunctionGetHandler)SetScanFunctionGetHandler sets a handler for resolving scan functions for tables that are not directly backed by a registered Function.
method SetTableGetHandler
Section titled âmethod SetTableGetHandlerâfunc (w *Worker) SetTableGetHandler(h TableGetHandler)SetTableGetHandler sets a handler for customizing catalog_table_get responses. Return non-nil bytes to override the default lookup; return nil to fall through.
method attachOptionsFor
Section titled âmethod attachOptionsForâfunc (w *Worker) attachOptionsFor(catalogName string) []AttachOptionSpecattachOptionsFor returns the option specs governing an ATTACH of catalogName: the per-catalog set when one is registered, otherwise the worker-wide set.
method attachScopeForPtr
Section titled âmethod attachScopeForPtrâfunc (w *Worker) attachScopeForPtr(sealed *[]byte, cc *vgirpc.CallContext, fallback []byte) []byteattachScopeForPtr resolves the per-ATTACH plaintext scope (catalog bytes with the framework UUID stripped) from a sealed wire attach value, using the live call context so it is correct on both subprocess (pass-through) and HTTP (AEAD) transports. Returns fallback when the value is absent or canât be opened (e.g. cold-load best-effort scope on the rehydrate path).
method buildBindArgs
Section titled âmethod buildBindArgsâfunc (w *Worker) buildBindArgs(ct *CatalogTable) *ArgumentsbuildBindArgs creates an Arguments struct from CatalogTable.FuncArgs for use in OnBind calls to derive output schemas.
method buildScanResultFromTable
Section titled âmethod buildScanResultFromTableâfunc (w *Worker) buildScanResultFromTable(ct *CatalogTable) *ScanFunctionResultbuildScanResultFromTable creates a ScanFunctionResult from a function-backed CatalogTable.
method buildServer
Section titled âmethod buildServerâfunc (w *Worker) buildServer(transport serverTransport) *vgirpc.Servermethod candidatesFor
Section titled âmethod candidatesForâfunc (w *Worker) candidatesFor(name string, ft FunctionType) []candidatecandidatesFor gathers every registration of name, preferring the registry matching the requested function type and falling back to the others (DuckDB reports table-in-out and table-buffering functions as TABLE, and old clients may send an unrecognized type).
method catalogOfAttach
Section titled âmethod catalogOfAttachâfunc (w *Worker) catalogOfAttach(attachOpaqueData []byte) stringcatalogOfAttach names the catalog an unwrapped attach plaintext belongs to. Every function is homed in exactly one catalog, so both the function listing and bind dispatch need one catalog name per request â this is where it comes from.
Writable catalogs mint their own âwritable:<name>â plaintext, so their name is recovered through that mapping; every other catalog carries its name up front. A plaintext naming no catalog this worker serves â an attach validator that replaced it with its own encoding (a resolved data version, encoded ATTACH options), or no attachment at all â resolves to the workerâs own catalog, which is the only catalog such a worker can mean.
method catalogOfAttachPtr
Section titled âmethod catalogOfAttachPtrâfunc (w *Worker) catalogOfAttachPtr(attachOpaqueData *[]byte, cc *vgirpc.CallContext) stringcatalogOfAttachPtr names the catalog for a request that carries the attach value as an optional wire field (the unary aggregate / table-buffering RPCs). It opens the envelope down to the catalogâs own plaintext first, then applies catalogOfAttach. Returns the workerâs own catalog when there is no attachment or it cannot be opened â the same single-home rule the bind path uses.
method clearTransactionState
Section titled âmethod clearTransactionStateâfunc (w *Worker) clearTransactionState(txID []byte)clearTransactionState best-effort clears per-transaction K/V storage when a transaction commits or rolls back.
method findCatalogTable
Section titled âmethod findCatalogTableâfunc (w *Worker) findCatalogTable(schemaName, name string) *CatalogTablefindCatalogTable returns the registered CatalogTable for (schema, name) or nil.
method findWritableTable
Section titled âmethod findWritableTableâfunc (w *Worker) findWritableTable(schemaName, tableName string) (*WritableCatalog, *writableTable, error)findWritableTable looks up a (schema, table) across all writable catalogs. Reads from the SQLite store so DuckDB-spawned worker subprocesses see the same state as the process that ran CREATE TABLE.
method functionStorage
Section titled âmethod functionStorageâfunc (w *Worker) functionStorage() (FunctionStorage, error)functionStorage returns the workerâs shared FunctionStorage backend, constructed on first call. Today this is always a SQLite backend at the per-user default path; an env-driven selector (âVGI_WORKER_SHARED_STORAGEâ) can be added later to pick alternative backends (Cloudflare DO, etc.).
method getArgSpecs
Section titled âmethod getArgSpecsâfunc (w *Worker) getArgSpecs(fn interface{}) []ArgSpecgetArgSpecs returns the ArgSpecs for a resolved function.
method getFunctionMetadata
Section titled âmethod getFunctionMetadataâfunc (w *Worker) getFunctionMetadata(fn interface{}) FunctionMetadatagetFunctionMetadata returns the FunctionMetadata for a resolved function.
method getOrCreateStorage
Section titled âmethod getOrCreateStorageâfunc (w *Worker) getOrCreateStorage(ctx context.Context, executionID []byte, shardKey string) (*ExecutionStorage, error)getOrCreateStorage returns or creates an ExecutionStorage for the given execution ID. The wrapper binds against the workerâs shared FunctionStorage backend (initialized lazily on first call) so every execution in the worker uses one backend â one SQLite DB shared across all executions and across worker subprocesses spawned for parallel scans.
method handleAggregateBind
Section titled âmethod handleAggregateBindâfunc (w *Worker) handleAggregateBind(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateBindRequestWire) (AggregateBindResponseWire, error)method handleAggregateCombine
Section titled âmethod handleAggregateCombineâfunc (w *Worker) handleAggregateCombine(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateCombineRequestWire) (AggregateCombineResponseWire, error)method handleAggregateDestructor
Section titled âmethod handleAggregateDestructorâfunc (w *Worker) handleAggregateDestructor(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateDestructorRequestWire) (AggregateDestructorResponseWire, error)method handleAggregateFinalize
Section titled âmethod handleAggregateFinalizeâfunc (w *Worker) handleAggregateFinalize(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateFinalizeRequestWire) (AggregateFinalizeResponseWire, error)method handleAggregateStreamingChunk
Section titled âmethod handleAggregateStreamingChunkâfunc (w *Worker) handleAggregateStreamingChunk(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateStreamingChunkRequestWire) (AggregateStreamingChunkResponseWire, error)method handleAggregateStreamingClose
Section titled âmethod handleAggregateStreamingCloseâfunc (w *Worker) handleAggregateStreamingClose(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateStreamingCloseRequestWire) (AggregateStreamingCloseResponseWire, error)method handleAggregateStreamingOpen
Section titled âmethod handleAggregateStreamingOpenâfunc (w *Worker) handleAggregateStreamingOpen(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateStreamingOpenRequestWire) (AggregateStreamingOpenResponseWire, error)method handleAggregateUpdate
Section titled âmethod handleAggregateUpdateâfunc (w *Worker) handleAggregateUpdate(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateUpdateRequestWire) (AggregateUpdateResponseWire, error)method handleAggregateWindow
Section titled âmethod handleAggregateWindowâfunc (w *Worker) handleAggregateWindow(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateWindowRequestWire) (AggregateWindowResponseWire, error)method handleAggregateWindowBatch
Section titled âmethod handleAggregateWindowBatchâfunc (w *Worker) handleAggregateWindowBatch(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateWindowBatchRequestWire) (AggregateWindowBatchResponseWire, error)handleAggregateWindowBatch serves the batched window RPC (one call per Evaluate() instead of one per output row). UNREACHABLE under the current build: the C++ extension wires SetWindowBatchCallback only under #ifdef DUCKDB_HAS_AGGREGATE_WINDOW_BATCH, which is never defined because the pinned DuckDB lacks aggregate_window_batch_t. Until DuckDB ships that API and the extension enables it, only the per-row handleAggregateWindow runs. Kept symmetric with the per-row path so it works the moment it lands.
method handleAggregateWindowDestructor
Section titled âmethod handleAggregateWindowDestructorâfunc (w *Worker) handleAggregateWindowDestructor(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateWindowDestructorRequestWire) (AggregateWindowDestructorResponseWire, error)method handleAggregateWindowInit
Section titled âmethod handleAggregateWindowInitâfunc (w *Worker) handleAggregateWindowInit(ctx context.Context, callCtx *vgirpc.CallContext, req AggregateWindowInitRequestWire) (AggregateWindowInitResponseWire, error)method handleBind
Section titled âmethod handleBindâfunc (w *Worker) handleBind(ctx context.Context, callCtx *vgirpc.CallContext, req BindRequestWire) (resp BindResponseWire, err error)handleBind processes a bind RPC request.
method handleCardinality
Section titled âmethod handleCardinalityâfunc (w *Worker) handleCardinality(ctx context.Context, callCtx *vgirpc.CallContext, req CardinalityRequestWire) (card TableCardinality, err error)handleCardinality processes a table_function_cardinality RPC request.
method handleInit
Section titled âmethod handleInitâfunc (w *Worker) handleInit(ctx context.Context, callCtx *vgirpc.CallContext, req InitRequestWire) (result *vgirpc.StreamResult, err error)handleInit processes an init RPC request and returns a StreamResult.
method handleTableBufferingCombine
Section titled âmethod handleTableBufferingCombineâfunc (w *Worker) handleTableBufferingCombine(ctx context.Context, cc *vgirpc.CallContext, req TableBufferingCombineRequestWire) (TableBufferingCombineResponseWire, error)method handleTableBufferingDestructor
Section titled âmethod handleTableBufferingDestructorâfunc (w *Worker) handleTableBufferingDestructor(ctx context.Context, cc *vgirpc.CallContext, req TableBufferingDestructorRequestWire) (TableBufferingDestructorResponseWire, error)method handleTableBufferingProcess
Section titled âmethod handleTableBufferingProcessâfunc (w *Worker) handleTableBufferingProcess(ctx context.Context, cc *vgirpc.CallContext, req TableBufferingProcessRequestWire) (TableBufferingProcessResponseWire, error)method handleTableFunctionDynamicToString
Section titled âmethod handleTableFunctionDynamicToStringâfunc (w *Worker) handleTableFunctionDynamicToString(ctx context.Context, callCtx *vgirpc.CallContext, req TableFunctionDynamicToStringRequestWire) (TableFunctionDynamicToStringResponseWire, error)method handleTableFunctionStatistics
Section titled âmethod handleTableFunctionStatisticsâfunc (w *Worker) handleTableFunctionStatistics(ctx context.Context, callCtx *vgirpc.CallContext, req CardinalityRequestWire) (out []byte, err error)handleTableFunctionStatistics processes a table_function_statistics RPC request, returning serialized per-column statistics IPC bytes (or nil when unknown).
method handleWritableAttach
Section titled âmethod handleWritableAttachâfunc (w *Worker) handleWritableAttach(req CatalogAttachRequestWire, c *WritableCatalog) (CatalogAttachResultWire, error)handleWritableAttach serves catalog_attach for a writable catalog.
method initScalar
Section titled âmethod initScalarâfunc (w *Worker) initScalar(ctx context.Context, fn ScalarFunction, initParams *InitParams, processParams *ProcessParams, outputSchema *arrow.Schema, recipe *InitRecipe) (*vgirpc.StreamResult, error)method initTable
Section titled âmethod initTableâfunc (w *Worker) initTable(ctx context.Context, fn TableFunction, initParams *InitParams, processParams *ProcessParams, outputSchema *arrow.Schema, autoProjectIDs []int32, recipe *InitRecipe) (*vgirpc.StreamResult, error)method initTableBuffering
Section titled âmethod initTableBufferingâfunc (w *Worker) initTableBuffering(ctx context.Context, fn TableBufferingFunction, initParams *InitParams, processParams *ProcessParams, outputSchema *arrow.Schema, phase Phase, recipe *InitRecipe, finalizeStateID *[]byte) (*vgirpc.StreamResult, error)initTableBuffering handles the two buffering init phases. TABLE_BUFFERING is the sink init: it persists the InitRecipe so process/combine can cold-load it, and returns an empty stream (the sink ingests via the unary process RPC). TABLE_BUFFERING_FINALIZE opens a producer that emits all batches the function returns for one finalize_state_id.
method initTableInOut
Section titled âmethod initTableInOutâfunc (w *Worker) initTableInOut(ctx context.Context, fn TableInOutFunction, initParams *InitParams, processParams *ProcessParams, outputSchema *arrow.Schema, phase Phase, recipe *InitRecipe) (*vgirpc.StreamResult, error)method loadAggArgs
Section titled âmethod loadAggArgsâfunc (w *Worker) loadAggArgs(funcName string, execID []byte, shardKey string) *ArgumentsloadAggArgs returns the bind-time arguments stashed by handleAggregateBind.
method loadBufferingParams
Section titled âmethod loadBufferingParamsâfunc (w *Worker) loadBufferingParams(executionID []byte, shardKey string) (TableBufferingFunction, *ProcessParams, error)loadBufferingParams returns the (function, ProcessParams) pair for a process/combine RPC. It caches the decoded template per execution_id so only the first call pays the storage scan + gob decode + schema/arg re-parse; every later batch of the same execution gets a cheap shallow copy. The cache is evicted by the destructor RPC (end-of-query cleanup).
method loadCachedPartition
Section titled âmethod loadCachedPartitionâfunc (w *Worker) loadCachedPartition(funcName string, execID []byte, partitionID int64, shardKey string) (*WindowPartition, interface{}, error)loadCachedPartition rebuilds a WindowPartition from the gob-encoded payload stored at WindowInit time, plus the optional gob-encoded WindowInit state.
method lookupAggregate
Section titled âmethod lookupAggregateâfunc (w *Worker) lookupAggregate(name string, schemaName *string, attach *[]byte, cc *vgirpc.CallContext) (AggregateFunction, error)lookupAggregate resolves the aggregate one unary RPC names.
Every aggregate RPC re-resolves by name â they are stateless requests with no bound connection, so the request itself carries the whole identity. Since protocol 1.2.0 that includes schema_name, without which an aggregate declared in two schemas would run whichever implementation the by-name lookup found first: bind could resolve correctly and update/finalize then silently return the other schemaâs answer.
method lookupFor
Section titled âmethod lookupForâfunc (w *Worker) lookupFor(req *BindRequestWire, params *BindParams) functionLookuplookupFor builds the (catalog, schema, name) resolution key for a bind_call whose params were parsed on the live path â where parseBindRequest has already opened the attachment down to the catalogâs own plaintext, so the catalog name reads straight off it.
method lookupTable
Section titled âmethod lookupTableâfunc (w *Worker) lookupTable(name string) (TableFunction, error)lookupTable resolves a registered table function by name (single-overload lookup; the dynamic_to_string call always knows the resolved name).
method openAttach
Section titled âmethod openAttachâfunc (w *Worker) openAttach(envelope []byte, cc *vgirpc.CallContext) ([]byte, error)openAttach opens an attach_opaque_data envelope, returning the catalogâs own bytes â the framework UUID prefix is stripped. This is what catalog handlers and function bodies see (the catalog never knows about the shard UUID); storage routing uses openAttachFull to reach the UUID instead.
method openAttachFull
Section titled âmethod openAttachFullâfunc (w *Worker) openAttachFull(envelope []byte, cc *vgirpc.CallContext) ([]byte, error)openAttachFull opens an attach_opaque_data envelope, returning the full framework plaintext uuid(16) || catalog_bytes (not stripped). Storage shards on the leading UUID, so the function-execution paths use this to derive the shard key. Pass-through when there is no signing key.
method openTransaction
Section titled âmethod openTransactionâfunc (w *Worker) openTransaction(envelope, attachEnvelope []byte, cc *vgirpc.CallContext) ([]byte, error)openTransaction opens a transaction_opaque_data envelope. attachEnvelope is the (sealed) attach_opaque_data the same call carried â it must match the attach the transaction was minted under, or the open fails.
method originOf
Section titled âmethod originOfâfunc (w *Worker) originOf(kind funcKind, name string, idx int) funcOriginoriginOf returns the home recorded for the idxâth registration of (kind, name). A registration made by a test poking the registry maps directly falls back to the workerâs own catalog and default schema.
method parseBindRequest
Section titled âmethod parseBindRequestâfunc (w *Worker) parseBindRequest(req BindRequestWire, callCtx *vgirpc.CallContext) (*BindParams, error)parseBindRequest converts a wire bind request into BindParams.
method rebuildProcessParams
Section titled âmethod rebuildProcessParamsâfunc (w *Worker) rebuildProcessParams(recipe *InitRecipe) (interface{}, *ProcessParams, error)rebuildProcessParams reconstructs ProcessParams from an InitRecipe. It also returns the resolved function (via overload resolution) to avoid a redundant second resolution by the caller.
method recordOrigin
Section titled âmethod recordOriginâfunc (w *Worker) recordOrigin(kind funcKind, name string, o funcOrigin)recordOrigin appends the home for a registration, keeping the funcOrigins slice index-aligned with the registry slice it mirrors. An empty catalog resolves to the workerâs own catalog, so every entry names one.
method registerAggregateRPCs
Section titled âmethod registerAggregateRPCsâfunc (w *Worker) registerAggregateRPCs(s *vgirpc.Server)method registerAggregateStreamingRPCs
Section titled âmethod registerAggregateStreamingRPCsâfunc (w *Worker) registerAggregateStreamingRPCs(s *vgirpc.Server)method registerCatalogMethods
Section titled âmethod registerCatalogMethodsâfunc (w *Worker) registerCatalogMethods(s *vgirpc.Server)method registerDynamicToStringRPCs
Section titled âmethod registerDynamicToStringRPCsâfunc (w *Worker) registerDynamicToStringRPCs(s *vgirpc.Server)method registerTableBufferingRPCs
Section titled âmethod registerTableBufferingRPCsâfunc (w *Worker) registerTableBufferingRPCs(s *vgirpc.Server)method registerWritableFunctions
Section titled âmethod registerWritableFunctionsâfunc (w *Worker) registerWritableFunctions(catalogName string)registerWritableFunctions registers the four generic writable table functions for one writable catalog. Called automatically per RegisterWritableCatalog.
One set is registered per catalog rather than one shared set, because every function is homed in exactly one catalog: a bind arriving through catalog X resolves only functions homed in X, so a single shared registration would be reachable from just one of the workerâs writable catalogs.
method rehydrateFinalize
Section titled âmethod rehydrateFinalizeâfunc (w *Worker) rehydrateFinalize(s *FinalizeProducerState) errormethod rehydrateScalar
Section titled âmethod rehydrateScalarâfunc (w *Worker) rehydrateScalar(s *ScalarExchangeState) errormethod rehydrateState
Section titled âmethod rehydrateStateâfunc (w *Worker) rehydrateState(state interface{}, method string) errorrehydrateState reconstructs non-serializable fields on a deserialized stream state. This is the RehydrateFunc callback for the HTTP server.
method rehydrateTableInOut
Section titled âmethod rehydrateTableInOutâfunc (w *Worker) rehydrateTableInOut(s *TableInOutExchangeState) errormethod rehydrateTableProducer
Section titled âmethod rehydrateTableProducerâfunc (w *Worker) rehydrateTableProducer(s *TableProducerState) errormethod resolveAggregate
Section titled âmethod resolveAggregateâfunc (w *Worker) resolveAggregate(name, schema, catalog string) (AggregateFunction, error)resolveAggregate resolves an aggregate RPC to a single registered implementation.
Every aggregate RPC (bind / update / combine / finalize / destructor, the four window calls, the three streaming calls) re-resolves the function by name: they are stateless unary requests with no bound connection, so the request is the only carrier of identity. Before protocol 1.2.0 none of them carried a schema, so an aggregate name declared in two schemas ran whichever the by-name lookup found first â bind could resolve correctly and update/finalize then return the other schemaâs answer.
Aggregates do not disambiguate by argument signature (overloads of one aggregate share state semantics, so any of them drives dispatch); the home is the whole of the resolution.
method resolveFunction
Section titled âmethod resolveFunctionâfunc (w *Worker) resolveFunction(lk functionLookup) (interface{}, error)resolveFunction resolves a call to a single registered implementation.
Scoping by home (see scopeToHome) runs first, narrowing âevery registration of this nameâ to âthe registrations the caller could possibly meanâ. Only then do argument signatures pick between same-schema overloads.
method resolveScanFunction
Section titled âmethod resolveScanFunctionâfunc (w *Worker) resolveScanFunction(req TableScanFunctionGetRequestWire) (*ScanFunctionResult, error)resolveScanFunction resolves the scan function backing a catalog table, following the same precedence as catalog_table_scan_function_get: writable catalog, registered function-backed table, attach-aware handler, then plain handler. Returns an RpcError when no scan function is available.
method scopeToHome
Section titled âmethod scopeToHomeâfunc (w *Worker) scopeToHome(cands []candidate, name, schema, catalog string) ([]candidate, error)scopeToHome narrows candidates to the registrations the caller could possibly mean, by their recorded home:
- Catalog: a call arriving through catalog X can only reach functions homed
in X. This is what lets one worker process serve two catalogs that eachdeclare the same function name.- Schema: a schema-qualified call is exact â only functions declared in that
schema survive, so a name registered in two schemas resolves to the onethe caller named instead of colliding. Naming a schema that does not holdthe function reports where it does live rather than the genericunknown-function list.A caller that names no schema keeps every candidate; the caller decides whether a surviving cross-schema tie is an error (see crossSchemaAmbiguity).
method sealAttach
Section titled âmethod sealAttachâfunc (w *Worker) sealAttach(plaintext []byte, cc *vgirpc.CallContext) ([]byte, error)sealAttach seals a plaintext attach value into an envelope bound to the callerâs identity.
method serializeCatalogTable
Section titled âmethod serializeCatalogTableâfunc (w *Worker) serializeCatalogTable(schemaName string, ct *CatalogTable) ([]byte, error)serializeCatalogTable converts a CatalogTable into serialized TableInfo bytes.
method serializedGlobalFunctions
Section titled âmethod serializedGlobalFunctionsâfunc (w *Worker) serializedGlobalFunctions() (SerializedItems, error)registerCatalogMethods registers all catalog RPC methods on the server. serializedGlobalFunctions returns the IPC-serialized FunctionInfo of every function named by WithGlobalFunctions, in declaration order, resolved against the catalogâs default schema. Names are carried unprefixed â the client applies global_function_prefix itself. Unknown or unlisted names contribute nothing, so declaring a function that was never registered is inert rather than fatal.
method shardKeyForAttach
Section titled âmethod shardKeyForAttachâfunc (w *Worker) shardKeyForAttach(sealed []byte, cc *vgirpc.CallContext) (string, error)shardKeyForAttach unwraps the sealed attach and derives its shard key. An empty/absent attach yields ââ (non-sharding backends ignore the key; the CfDo backend rejects an empty key server-side, the âmust not happenâ case).
method shardKeyForAttachPtr
Section titled âmethod shardKeyForAttachPtrâfunc (w *Worker) shardKeyForAttachPtr(sealed *[]byte, cc *vgirpc.CallContext) (string, error)shardKeyForAttachPtr is shardKeyForAttach for a nilable wire field.
method unwrapReqOpaque
Section titled âmethod unwrapReqOpaqueâfunc (w *Worker) unwrapReqOpaque(reqPtr any, cc *vgirpc.CallContext) errorunwrapReqOpaque unwraps the AttachOpaqueData ([]byte) and, if present, TransactionOpaqueData (*[]byte) fields of a catalog request struct in place, so handler bodies always see plaintext. The transaction envelope is opened with the sealed attach value as part of its AAD, so it stays bound to its parent attach. A no-op when the worker has no signing key.
method writableByAttachOpaqueData
Section titled âmethod writableByAttachOpaqueDataâfunc (w *Worker) writableByAttachOpaqueData(attachOpaqueData []byte) *WritableCatalogwritableByAttachOpaqueData returns the writable catalog whose attach_opaque_data matches. Attach IDs are deterministic (âwritable:<name>â) so DuckDB-spawned worker processes resolve to the same catalog without sharing in-memory state.
method writableSchemaContentsTables
Section titled âmethod writableSchemaContentsTablesâfunc (w *Worker) writableSchemaContentsTables(c *WritableCatalog, schemaName string) ([][]byte, error)method writableSchemaCreate
Section titled âmethod writableSchemaCreateâfunc (w *Worker) writableSchemaCreate(c *WritableCatalog, name string, onConflict onConflictAction, comment *string) errormethod writableSchemaDrop
Section titled âmethod writableSchemaDropâfunc (w *Worker) writableSchemaDrop(c *WritableCatalog, name string, ignoreNotFound, cascade bool) errormethod writableSchemaGet
Section titled âmethod writableSchemaGetâfunc (w *Worker) writableSchemaGet(c *WritableCatalog, name string) ([][]byte, error)method writableSchemas
Section titled âmethod writableSchemasâfunc (w *Worker) writableSchemas(c *WritableCatalog) ([][]byte, error)method writableTableCreate
Section titled âmethod writableTableCreateâfunc (w *Worker) writableTableCreate(c *WritableCatalog, req TableCreateRequestWire) errormethod writableTableDrop
Section titled âmethod writableTableDropâfunc (w *Worker) writableTableDrop(c *WritableCatalog, schemaName, name string, ignoreNotFound, cascade bool) errormethod writableTableGet
Section titled âmethod writableTableGetâfunc (w *Worker) writableTableGet(c *WritableCatalog, schemaName, tableName string) ([][]byte, error)func type WorkerOption
Section titled âfunc type WorkerOptionâtype WorkerOption func(*Worker)Description
WorkerOption configures a Worker.
Methods
function WithAttachCatalogs
Section titled âfunction WithAttachCatalogsâfunc WithAttachCatalogs(catalogs âŠAttachCatalogInfo) WorkerOptionWithAttachCatalogs advertises companion catalogs (lakehouse federation) that the client should ATTACH when this VGI catalog attaches. Surfaced via catalog_attach.attach_catalogs; the C++ extension attaches each at VGI-attach time.
function WithAttachOptions
Section titled âfunction WithAttachOptionsâfunc WithAttachOptions(opts âŠAttachOptionSpec) WorkerOptionWithAttachOptions declares ATTACH-time options accepted by the worker. These are advertised via catalog_catalogs so DuckDB can validate option names/types at ATTACH time. Values passed at ATTACH arrive as the CatalogAttachRequestWire.Options RecordBatch.
function WithAttachOptionsForCatalog
Section titled âfunction WithAttachOptionsForCatalogâfunc WithAttachOptionsForCatalog(catalogName string, opts âŠAttachOptionSpec) WorkerOptionWithAttachOptionsForCatalog declares ATTACH-time options for one alias catalog (see WithCatalogAliasInfo) rather than for the worker as a whole.
A worker that serves several catalogs rarely wants one option set spanning all of them: an option that is Required on a gated catalog must not gate the others too. Options registered here are advertised on that catalogâs vgi_catalogs() row only, and enforced only when that catalog is the ATTACH target. The primary catalog keeps using WithAttachOptions.
function WithAttachScanBranchesGetHandler
Section titled âfunction WithAttachScanBranchesGetHandlerâfunc WithAttachScanBranchesGetHandler(h AttachScanBranchesGetHandler) WorkerOptionWithAttachScanBranchesGetHandler installs an attach-opaque-data-aware scan_branches_get handler for multi-branch (UNION-of-sources) tables.
function WithAttachScanFunctionGetHandler
Section titled âfunction WithAttachScanFunctionGetHandlerâfunc WithAttachScanFunctionGetHandler(h AttachScanFunctionGetHandler) WorkerOptionWithAttachScanFunctionGetHandler installs an attach-opaque-data-aware scan_function_get handler.
function WithAttachTableGetHandler
Section titled âfunction WithAttachTableGetHandlerâfunc WithAttachTableGetHandler(h AttachTableGetHandler) WorkerOptionWithAttachTableGetHandler installs an attach-opaque-data-aware table_get handler.
function WithAttachValidator
Section titled âfunction WithAttachValidatorâfunc WithAttachValidator(v AttachValidator) WorkerOptionWithAttachValidator installs a custom attach validator. Required by the versioned/versioned-tables example workers.
function WithAttachWriteFunctionGetHandler
Section titled âfunction WithAttachWriteFunctionGetHandlerâfunc WithAttachWriteFunctionGetHandler(h AttachWriteFunctionGetHandler) WorkerOptionWithAttachWriteFunctionGetHandler installs an attach-opaque-data-aware handler that resolves the worker function backing INSERT/UPDATE/DELETE on a given (attach_opaque_data, schema, table). Use this for fixture catalogs that publish writable tables outside of the built-in WritableCatalog path (e.g. schema_reconcile, which has its own per-table SQLite store and strict-schema validators).
function WithCatalogAliasInfo
Section titled âfunction WithCatalogAliasInfoâfunc WithCatalogAliasInfo(name string, info CatalogInfo) WorkerOptionWithCatalogAliasInfo registers a catalog alias that advertises itself distinctly in catalog discovery and is isolated per ATTACH. Unlike a plain WithCatalogAliases entry (which shares the primary catalogâs identity and a stable name-based attach scope), an alias registered here:
- appears as its own row in vgi_catalogs() carrying info.DataVersionSpec; and
- mints a random per-ATTACH scope at attach time (info.Name + NUL + random),
so two ATTACHes of the same alias never share attach-scoped state.info.Name should equal name. Functions meant to surface only under this alias must be registered with Register*ForCatalog(name, âŠ). Used by the accumulate fixture, whose per-ATTACH row collections must be isolated.
function WithCatalogAliases
Section titled âfunction WithCatalogAliasesâfunc WithCatalogAliases(names âŠstring) WorkerOptionWithCatalogAliases adds extra catalog names this worker accepts via catalog_attach. Each alias resolves to the same primary read-only catalog (same registered functions, no separate state). Useful for fixture workers that publish multiple cross-language reproducer catalogs out of one binary (projection_repro, schema_reconcile, âŠ).
function WithCatalogComment
Section titled âfunction WithCatalogCommentâfunc WithCatalogComment(comment string) WorkerOptionWithCatalogComment sets the comment reported by catalog_attach (surfaces in duckdb_databases().comment).
function WithCatalogInfo
Section titled âfunction WithCatalogInfoâfunc WithCatalogInfo(info CatalogInfo) WorkerOptionWithCatalogInfo overrides the CatalogInfo record returned by catalog_catalogs
(used by vgi_catalogs(location) for discovery). Set it to advertise
implementation_version / data_version_spec for versioned workers.
function WithCatalogName
Section titled âfunction WithCatalogNameâfunc WithCatalogName(name string) WorkerOptionWithCatalogName sets the catalog name.
function WithCatalogTags
Section titled âfunction WithCatalogTagsâfunc WithCatalogTags(tags map[string]string) WorkerOptionWithCatalogTags sets tags reported by catalog_attach (duckdb_databases().tags).
function WithCatalogVersionHook
Section titled âfunction WithCatalogVersionHookâfunc WithCatalogVersionHook(h CatalogVersionHook) WorkerOptionWithCatalogVersionHook installs a hook that runs on every catalog_version RPC. Use it to assert invariants like cookie presence on HTTP transport.
function WithFunctionStorage
Section titled âfunction WithFunctionStorageâfunc WithFunctionStorage(s FunctionStorage) WorkerOptionWithFunctionStorage injects an explicit FunctionStorage backend. When unset, the worker defaults to a local SQLite backend at the per-user state path. Use this to wire a Cloudflare Durable Object client or any other backend implementing the FunctionStorage interface; combine with vgi/storage/resolve.FromEnv to get vgi-python-style env-driven selection (VGI_WORKER_SHARED_STORAGE=sqlite|cloudflare-do).
function WithGlobalFunctionPrefix
Section titled âfunction WithGlobalFunctionPrefixâfunc WithGlobalFunctionPrefix(prefix string) WorkerOptionWithGlobalFunctionPrefix sets the prefix a client prepends when publishing this catalogâs global functions (see WithGlobalFunctions) â e.g. prefix âvgi_exampleâ publishes global_scalar as vgi_example_global_scalar. Reported by catalog_attach as global_function_prefix (protocol 1.3.0). Mirrors vgi-pythonâs Catalog(global_function_prefix=âŠ).
function WithGlobalFunctions
Section titled âfunction WithGlobalFunctionsâfunc WithGlobalFunctions(names âŠstring) WorkerOptionWithGlobalFunctions names the registered functions this catalog advertises for publication into the clientâs global function namespace (DuckDBâs system.main), in the order they should be published. Each name is resolved against the catalogâs default schema; the serialized FunctionInfo of every match is carried in catalog_attachâs global_functions field (protocol 1.3.0), under the unprefixed registered name â the prefix set by WithGlobalFunctionPrefix is the clientâs to apply.
Advertising a function does not change where the worker registers it: it stays an ordinary member of its schema and is still callable as catalog.schema.name. Mirrors vgi-pythonâs Catalog(global_functions=[âŠ]).
function WithHttpSigningKey
Section titled âfunction WithHttpSigningKeyâfunc WithHttpSigningKey(key []byte) WorkerOptionWithHttpSigningKey configures the HMAC key used by the HTTP transport to sign opaque state tokens. When unset, the HTTP server generates a random key at startup â fine for ephemeral workers, but in-flight state tokens become invalid on restart. Pass a stable key (â„16 bytes, typically from VGI_SIGNING_KEY) for production deployments.
Has no effect when running in stdio mode.
function WithLogFormat
Section titled âfunction WithLogFormatâfunc WithLogFormat(format LogFormat) WorkerOptionWithLogFormat selects the stderr log format. Default is text. Ignored when WithLogHandler is also set (the custom handler wins).
function WithLogHandler
Section titled âfunction WithLogHandlerâfunc WithLogHandler(h slog.Handler) WorkerOptionWithLogHandler sets a custom slog.Handler for all logging. When set, WithLogLevel/WithLogFormat/WithLoggers are ignored â the handler controls its own level and formatting. The packageâs named loggers are re-bound to the supplied handler at worker startup.
function WithLogLevel
Section titled âfunction WithLogLevelâfunc WithLogLevel(level slog.Level) WorkerOptionWithLogLevel sets the minimum log level for the default handler. The zero value (slog.LevelInfo) logs Info and above.
function WithLoggers
Section titled âfunction WithLoggersâfunc WithLoggers(names âŠstring) WorkerOptionWithLoggers restricts which named loggers emit records. Use to silence noisy subsystems or focus on one (e.g. WithLoggers(âvgi.catalogâ)). Empty means all known loggers. Unknown names log a warning but are honored.
function WithSchemaComments
Section titled âfunction WithSchemaCommentsâfunc WithSchemaComments(comments map[string]string) WorkerOptionWithSchemaComments overrides the default comment for built-in schemas (âmainâ and âdataâ). Other schemas retain their auto-generated comments.
function WithSchemaContentsHandler
Section titled âfunction WithSchemaContentsHandlerâfunc WithSchemaContentsHandler(h SchemaContentsHandler) WorkerOptionWithSchemaContentsHandler installs a handler that can replace the tables returned for a given (attach_opaque_data, schema) pair.
function WithSchemaTags
Section titled âfunction WithSchemaTagsâfunc WithSchemaTags(tags map[string]map[string]string) WorkerOptionWithSchemaTags sets schema-level tags surfaced via duckdb_schemas().tags (SchemaInfo.tags). Keyed by schema name. The metadata-quality linter expects vgi.description_llm / vgi.description_md tags on each schema. Tags merge with any previously configured tags for the same schema; later keys win.
function WithSecretTypes
Section titled âfunction WithSecretTypesâfunc WithSecretTypes(types âŠSecretTypeSpec) WorkerOptionWithSecretTypes registers secret types that will be sent to DuckDB during catalog_attach.
function WithSettings
Section titled âfunction WithSettingsâfunc WithSettings(settings âŠSettingSpec) WorkerOptionWithSettings adds custom DuckDB settings to the worker.
function WithSupportsTransactions
Section titled âfunction WithSupportsTransactionsâfunc WithSupportsTransactions(v bool) WorkerOptionWithSupportsTransactions makes the catalog report supports_transactions=true on attach, so DuckDB threads a transaction_opaque_data through bind/scan inside BEGIN/COMMIT (needed by transaction-scoped storage like tx_cached_value).
struct funcKey
Section titled âstruct funcKeyâtype funcKey struct {kind funcKindname string}Description
funcKey identifies one registry slice: (kind, function name).
type funcKind
Section titled âtype funcKindâtype funcKind uint8Description
funcKind distinguishes the five registries a function can land in. It is part of the funcOrigins key so an index in one registry never aliases an index in another.
struct funcOrigin
Section titled âstruct funcOriginâtype funcOrigin struct {// catalog is the catalog that owns the function. Never empty: a// registration that names none is homed in the worker's own catalog.catalog string// schema is the catalog schema declaring the function, lowercased.schema string// unlisted hides the function from every function listing without// changing its home â it exists to back a catalog table, whose scan// resolves it by name, so publishing it as a callable function too would// be redundant surface area. Dispatch is unaffected.unlisted bool}Description
funcOrigin is the single home of one registered implementation: exactly one (catalog, schema) pair. There is no âunscopedâ home â a function is never visible in every schema, nor reachable from every catalog.
A function name is not a unique key: the same name may be registered in two
schemas of one catalog, or in two catalogs served by one worker process.
Registration is the only place that knows which, so the home is recorded here
and is what both the catalog listing and bind dispatch resolve against â a
bind naming schema data can only reach an implementation homed in data.
type serverTransport
Section titled âtype serverTransportâtype serverTransport intDescription
buildServer creates and configures the vgirpc.Server with all handlers registered. Shared between RunStdio and RunHttp. serverTransport selects how the worker serves and how execution-storage cleanup is handled.
struct storageCleanupHook
Section titled âstruct storageCleanupHookâtype storageCleanupHook struct {worker *WorkerpendingKeys []string // keys from previous dispatch, candidates for cleanupstaleKeys []string // snapshot of pendingKeys at current dispatch startisHTTP bool // when true, skip storage cleanup (no reliable stream-end signal)}Description
storageCleanupHook implements vgirpc.DispatchHook to clean up storage entries when execution streams complete.
Cleanup is deferred by one dispatch cycle: keys tracked during a dispatch become âpendingâ at its end, and are only cleaned up in the next dispatchâs OnDispatchEnd â but only if the new dispatch did NOT reuse them. This handles multi-worker (primary + secondary inits share an execution ID) and table-in-out (INPUT + FINALIZE share an execution ID).
Methods
method OnDispatchEnd
Section titled âmethod OnDispatchEndâfunc (h *storageCleanupHook) OnDispatchEnd(ctx context.Context, token vgirpc.HookToken, info vgirpc.DispatchInfo, stats *vgirpc.CallStatistics, err error)OnDispatchEnd cleans up stale storage entries that were not reused in this dispatch and defers this dispatchâs keys to the next cycle. In HTTP mode it does nothing, since there is no reliable stream-end signal.
method OnDispatchStart
Section titled âmethod OnDispatchStartâfunc (h *storageCleanupHook) OnDispatchStart(ctx context.Context, info vgirpc.DispatchInfo) (context.Context, vgirpc.HookToken)OnDispatchStart begins tracking storage for an âinitâ dispatch: it snapshots the previous cycleâs pending keys as stale candidates and installs a storageTracker in the context so keys touched during this dispatch can be recorded.
struct storageTracker
Section titled âstruct storageTrackerâtype storageTracker struct {keys []string}Description
storageTracker records execution ID hex keys used during a single dispatch.
Methods
method track
Section titled âmethod trackâfunc (t *storageTracker) track(key string)track records a hex key, deduplicating against previously tracked keys.
struct storageTrackerKeyType
Section titled âstruct storageTrackerKeyTypeâtype storageTrackerKeyType struct{}Description
storageTrackerKeyType is the context key type for the storage tracker.
function buildDefaultValueBatch
Section titled âfunction buildDefaultValueBatchâfunc buildDefaultValueBatch(mem memory.Allocator, schema *arrow.Schema, dt arrow.DataType, val interface{}) (arrow.RecordBatch, error)buildDefaultValueBatch creates a 1-row batch with the default value.
function coldAttachScope
Section titled âfunction coldAttachScopeâfunc coldAttachScope(raw []byte) []bytecoldAttachScope derives the per-ATTACH plaintext scope on the cold-load path, where parseBindRequest ran with no call context and so left the attach value raw (the framework uuid(16) || plaintext, pass-through on subprocess). Strip the UUID prefix to match what OnBind saw. On HTTP, where the raw value is a sealed envelope this canât unwrap, the buffering RPC handlers re-derive the scope from the live request instead; this is the subprocess best-effort.
function gobDecode
Section titled âfunction gobDecodeâfunc gobDecode(data []byte) (interface{}, error)gobDecode gob-decodes bytes back into an interface{}.
function gobEncode
Section titled âfunction gobEncodeâfunc gobEncode(v interface{}) ([]byte, error)gobEncode gob-encodes a value to bytes.
function makeClientBundleHandler
Section titled âfunction makeClientBundleHandlerâfunc makeClientBundleHandler() http.HandlerFuncmakeClientBundleHandler returns the GET {prefix}/vgi-client.js handler.
function makeLandingHandler
Section titled âfunction makeLandingHandlerâfunc makeLandingHandler(name, serverID string, oauth bool) http.HandlerFuncmakeLandingHandler returns the GET {prefix}/ handler: HTML for browsers, a JSON status document for health checks and for the pageâs own identity read.
function newExecutionID
Section titled âfunction newExecutionIDâfunc newExecutionID() []bytenewExecutionID generates a UUID-based execution ID.
function serializeSecretTypeSpec
Section titled âfunction serializeSecretTypeSpecâfunc serializeSecretTypeSpec(spec SecretTypeSpec) ([]byte, error)serializeSecretTypeSpec serializes a SecretTypeSpec to Arrow IPC bytes. Format: RecordBatch with schema {name: string, description: string, parameters_schema: binary}.
function serializeSettingSpec
Section titled âfunction serializeSettingSpecâfunc serializeSettingSpec(spec SettingSpec) ([]byte, error)serializeSettingSpec serializes a SettingSpec to Arrow IPC bytes. Format: RecordBatch with schema {name: string, description: string, type: binary, default_value: binary?}.
function vgiGoVersion
Section titled âfunction vgiGoVersionâfunc vgiGoVersion() stringvgiGoVersion returns the build version of the module that embeds this package, falling back to âdevâ. Surfaced as the status documentâs version.
function writeJSON
Section titled âfunction writeJSONâfunc writeJSON(rw http.ResponseWriter, v any)