Skip to content
Query-farmPublic

About

VGI worker SDK for C++ — build DuckDB-facing workers on Apache Arrow IPC

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

vgi-c++

The C++ worker SDK for VGI (Vector Gateway Interface) — write DuckDB functions and catalogs in C++, ship them as one binary, no DuckDB extension to compile and no version coupling.

A worker is an ordinary binary that DuckDB launches and talks to over Apache Arrow IPC. It can expose scalar / table / aggregate functions and whole catalogs that behave like native DuckDB objects. This repo is the C++ sibling of the Rust and Python SDKs, and is built on the C++ vgi-rpc port.

Version 0.17.0 uses vgi.v3 / 3.4.0 and requires a matching VGI extension: peers must agree on major and minor, so keep 0.16.x for a 3.3.0 extension, 0.15.x for a 3.2.0 extension and 0.12.x for existing vgi.v2 installations; upgrade the extension and worker SDKs together. The shared contract prepares for DuckDB 2.0 while remaining usable by the 1.5 adapter. Optional catalog and query capabilities still depend on the provider. This release uses vgi-rpc-cpp 0.12.0.

The example worker passes the VGI integration suite in vgi over the subprocess transport. What is and is not implemented is written down in docs/roadmap.md, and the suite — not that file — is the specification.

Build

git clone https://github.com/Query-farm/vgi-rpc-cpp.git ../vgi-rpc-c++
export VCPKG_ROOT=/path/to/vcpkg

cmake --preset default   # Debug + tests
cmake --build build
ctest --test-dir build

vgi-rpc-c++ is built from a sibling checkout by default, since the two move together and an installed copy goes stale silently. Override with -DVGI_RPC_SOURCE_DIR=<path>, or use an installed copy with -DVGI_USE_INSTALLED_RPC=ON.

Note for Linux and macOS: vcpkg builds libsodium through its autotools script, so autoconf and automake need to be installed. Windows uses MSBuild and needs neither.

A worker

#include <vgi/worker.h>

class UpperCase : public vgi::ScalarFunction {
    std::string name() const override { return "upper_case"; }
    vgi::FunctionMetadata metadata() const override {
        vgi::FunctionMetadata md;
        md.return_type = arrow::utf8();
        return md;
    }
    std::vector<vgi::ArgSpec> argument_specs() const override {
        return {vgi::ArgSpec::column("value", 0, "varchar")};
    }
    std::shared_ptr<arrow::RecordBatch> process(
        const vgi::ProcessParams& params,
        const std::shared_ptr<arrow::RecordBatch>& batch) const override;
};

int main(int argc, char** argv) {
    vgi::Worker worker;
    worker.register_scalar(std::make_shared<UpperCase>());
    worker.run(argc, argv);  // stdio, --unix <path> [--idle-timeout SEC], or --http
}

example-worker/ is the full fixture set the integration suite runs against — several hundred functions across every shape the protocol has, and the best place to look for how any one of them is meant to behave.

Running the suite

scripts/run_tests.sh                 # the whole in-scope suite
scripts/run_tests.sh scalar          # one category
scripts/run_tests.sh test/sql/integration/scalar/upper_case.test

It drives ~/Development/vgi's unittest binary against the release worker. VGI_EXT points at the extension checkout, VGI_CPP_BUILD at the build directory, and VGI_CPP_TEST_CACHE at a scratch directory — the last matters when two runs go at once, since they would otherwise share one log.

See Hosted protocols and Identity for serving other vgi-rpc protocols beside vgi.v3 and for hosting vgi_rpc.Identity.v2.

See Attach tickets for letting a runner reattach a user's catalog later, as that user, with a grant and a sealed vgia1. ticket (vgi.attach_tickets.v1, enabled by VGI_SIGNING_KEY plus grant keys).

See Filtered scan planning for letting a multi-branch table choose its branches with the query's predicates and attach branch statistics (protocol 3.2).

Function visibility (protocol 3.3)

The engine takes a table's scan capabilities (projection and filter pushdown, required secrets, late materialization, ...) only from the function listing, so every registered function is listed. Worker::hide_function(name) marks one FunctionInfo.visibility = "table_only": the tables that name it still resolve it with all its capabilities, but it is absent from duckdb_functions() and cannot be called from SQL, not even fully qualified, nor published as a global function. Every other function is public (the field is sent null). Functions in this SDK are always registered explicitly, and an explicitly registered function is public under the rule every SDK shares, so a table's scan function stays callable unless it is hidden.

This SDK serves read-only catalogs, so 3.3's write-path changes reach it only as wire shape: catalog_table_scan_function_get is gone (catalog_table_scan_branches_get is the only scan-discovery RPC, served for every table), and catalog_table_create answers {created: bool} — the in-memory DDL catalog reports false for IF NOT EXISTS over an existing table.

Orchard hosted mode

With VGI_ORCHARD_HOSTED=1 the worker runs as an Orchard Field Worker: only --http serves, every request except HEAD /health and CORS preflights needs a valid Pass (an RFC 9068 ES256 access token checked against VGI_JWT_ISSUER, VGI_JWT_AUDIENCE and the VGI_JWT_JWKS_URI keys), and any other way in refuses to start. Functions read the Pass claims from ProcessParams::auth. See Orchard hosted mode.

Large values in your own bucket

With VGI_STORAGE_BACKEND=s3 (or just VGI_STORAGE_S3_BUCKET), a self-hosted worker keeps externalized results, upload grants and stored objects in your own S3 or S3-compatible bucket instead of the blob vendor. GCS works the same way with VGI_STORAGE_GCS_BUCKET. Build with the s3 or gcs vcpkg feature. See Direct object storage.

See Iroh operations for the in-process C ABI client and identity-preserving raw or HTTP worker bridge setup.

Licence

Query Farm Source-Available License, Version 1.0 — see LICENSE. The same licence as vgi-python and the DuckDB extension.

Browser catalog

HTTP workers serve the shared browser catalog and bundled client at / and the configured HTTP prefix. The page discovers schemas, tables, views, and functions through VGI RPC. ?format=json returns worker identity. Asset routes use the same authentication and proxy-proof policy as RPC and support HEAD and ETag revalidation. The assets are embedded in the library; no runtime files are needed. This requires vgi-rpc-cpp 0.5.0 or newer.

About

VGI worker SDK for C++ — build DuckDB-facing workers on Apache Arrow IPC

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages