@query-farm/vgi 0.49.2 → 0.50.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/catalog/composite.d.ts +1 -1
- package/dist/catalog/descriptors.d.ts +34 -2
- package/dist/catalog/interface.d.ts +47 -8
- package/dist/catalog/read-only.d.ts +48 -1
- package/dist/client/client.d.ts +13 -7
- package/dist/client-entry.d.ts +1 -1
- package/dist/client-entry.js +40 -16
- package/dist/client-entry.js.map +6 -6
- package/dist/functions/storage.d.ts +7 -0
- package/dist/generated/vgi-client.d.ts +4 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +2 -2
- package/dist/generated/vgi-service.d.ts +7 -26
- package/dist/index.core.d.ts +4 -3
- package/dist/index.js +265 -170
- package/dist/index.js.map +16 -16
- package/dist/protocol/dispatch.d.ts +5 -3
- package/dist/serve-entry.js +43 -45
- package/dist/serve-entry.js.map +9 -9
- package/dist/worker-cf-entry.js +221 -154
- package/dist/worker-cf-entry.js.map +15 -15
- package/dist/write-results.d.ts +8 -1
- package/package.json +1 -1
- package/src/catalog/composite.ts +2 -2
- package/src/catalog/descriptors.ts +35 -2
- package/src/catalog/interface.ts +78 -10
- package/src/catalog/read-only.ts +297 -175
- package/src/client/client.ts +22 -13
- package/src/client-entry.ts +4 -0
- package/src/functions/storage.ts +44 -3
- package/src/generated/vgi-client.ts +6 -1
- package/src/generated/vgi-protocol-schemas.ts +8 -12
- package/src/generated/vgi-service.ts +9 -48
- package/src/index.core.ts +4 -3
- package/src/protocol/dispatch.ts +5 -3
- package/src/protocol/handlers/catalog/table.ts +14 -21
- package/src/write-results.ts +8 -3
package/dist/write-results.d.ts
CHANGED
|
@@ -46,12 +46,19 @@ export declare function writeResultBatch(mode: WriteResultMode, tableSchema: Vgi
|
|
|
46
46
|
/** What DuckDB asked a write function for, decoded from `write_options`. */
|
|
47
47
|
export interface WriteOptions {
|
|
48
48
|
resultMode: WriteResultMode;
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated Always `"throw"`. Protocol 3.3 removed `on_conflict` from the
|
|
51
|
+
* `write_options` batch: DuckDB rewrites every `INSERT ... ON CONFLICT` and
|
|
52
|
+
* `INSERT OR REPLACE` into a MERGE before any catalog hook runs, so a write
|
|
53
|
+
* function never received anything else.
|
|
54
|
+
*/
|
|
50
55
|
onConflict: string;
|
|
56
|
+
/** @deprecated Always empty: protocol 3.3 removed `on_conflict_columns` (see `onConflict`). */
|
|
51
57
|
onConflictColumns: string[];
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
54
60
|
* Decode the `write_options` named argument of a write function's bind (a
|
|
55
61
|
* serialized one-row batch). Missing options mean a plain `count` write.
|
|
62
|
+
* Protocol 3.3: the batch carries only `result_mode`.
|
|
56
63
|
*/
|
|
57
64
|
export declare function writeOptions(bindCall: Pick<BindRequest, "arguments">): WriteOptions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@query-farm/vgi",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.50.0",
|
|
4
4
|
"description": "TypeScript framework for extending DuckDB with user-defined functions via the Vector Gateway Interface (VGI) over Arrow IPC.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "Query Farm LLC (https://query.farm)",
|
package/src/catalog/composite.ts
CHANGED
|
@@ -193,8 +193,8 @@ export class CompositeCatalogInterface extends CatalogInterface {
|
|
|
193
193
|
override async schemaDrop(...args: Parameters<CatalogInterface["schemaDrop"]>): Promise<void> {
|
|
194
194
|
await (this._route(args[0]).schemaDrop as (...a: typeof args) => unknown)(...args);
|
|
195
195
|
}
|
|
196
|
-
override async tableCreate(...args: Parameters<CatalogInterface["tableCreate"]>): Promise<void> {
|
|
197
|
-
await (this._route(args[0]).tableCreate as (...a: typeof args) => unknown)(...args);
|
|
196
|
+
override async tableCreate(...args: Parameters<CatalogInterface["tableCreate"]>): Promise<boolean | void> {
|
|
197
|
+
return (await (this._route(args[0]).tableCreate as (...a: typeof args) => unknown)(...args)) as boolean | void;
|
|
198
198
|
}
|
|
199
199
|
override async tableDrop(...args: Parameters<CatalogInterface["tableDrop"]>): Promise<void> {
|
|
200
200
|
await (this._route(args[0]).tableDrop as (...a: typeof args) => unknown)(...args);
|
|
@@ -39,21 +39,41 @@ export interface TableDescriptor {
|
|
|
39
39
|
definitionRevision?: Uint8Array | null;
|
|
40
40
|
name: string;
|
|
41
41
|
columns?: VgiSchema;
|
|
42
|
+
/**
|
|
43
|
+
* The table's scan function. It need not be listed in any schema's
|
|
44
|
+
* `functions`: the SDK always sends it in the table's schema listing so
|
|
45
|
+
* DuckDB knows its capabilities (projection/filter pushdown, rowid, ...),
|
|
46
|
+
* as `table_only` (absent from `duckdb_functions()`, not callable from SQL)
|
|
47
|
+
* unless `exposeScan` is set or a schema also lists it in `functions`.
|
|
48
|
+
*/
|
|
42
49
|
function?: VgiFunction;
|
|
50
|
+
/**
|
|
51
|
+
* Protocol 3.3: also expose the scan `function` as an ordinary, callable
|
|
52
|
+
* table function (`visibility: "public"`). Default false: the scan is sent
|
|
53
|
+
* `table_only`, so it resolves this table but is absent from
|
|
54
|
+
* `duckdb_functions()` and cannot be called directly. Listing the function
|
|
55
|
+
* in a schema's `functions` makes it public too. Requires `function`.
|
|
56
|
+
*/
|
|
57
|
+
exposeScan?: boolean;
|
|
43
58
|
arguments?: Arguments;
|
|
44
59
|
/**
|
|
45
60
|
* Table in-out function backing `INSERT INTO <table>`. It receives the new
|
|
46
61
|
* rows (the table's user columns) and returns a `writeResultSchema` batch
|
|
47
62
|
* for the mode in its `write_options` (see `write-results.ts`). Omitted
|
|
48
63
|
* means the table does not accept INSERT.
|
|
64
|
+
*
|
|
65
|
+
* Write functions are always sent `table_only` (protocol 3.3): DuckDB
|
|
66
|
+
* learns their capabilities (`has_finalize`, the write schema) but they are
|
|
67
|
+
* not callable from SQL, even when a schema also lists them in `functions`.
|
|
49
68
|
*/
|
|
50
69
|
insertFunction?: VgiFunction;
|
|
51
70
|
/**
|
|
52
71
|
* Table in-out function backing `UPDATE <table>`. It receives the changed
|
|
53
72
|
* columns plus the row-id column (`rowIdField()`, which the scan
|
|
54
73
|
* `function` must emit) for each updated row. Requires `function`, which
|
|
55
|
-
* must also support projection pushdown
|
|
56
|
-
* `functions
|
|
74
|
+
* must also support projection pushdown (see `rowIdField`). The scan need
|
|
75
|
+
* not be listed in the schema's `functions`: it is always sent, as
|
|
76
|
+
* `table_only` unless `exposeScan`.
|
|
57
77
|
*/
|
|
58
78
|
updateFunction?: VgiFunction;
|
|
59
79
|
/**
|
|
@@ -138,6 +158,19 @@ export interface TableDescriptor {
|
|
|
138
158
|
tags?: Record<string, string>;
|
|
139
159
|
}
|
|
140
160
|
|
|
161
|
+
/**
|
|
162
|
+
* Protocol 3.3 `FunctionInfo.visibility` values. Null/absent on the wire means
|
|
163
|
+
* `public`.
|
|
164
|
+
*
|
|
165
|
+
* - `public`: an ordinary catalog function, listed in `duckdb_functions()` and
|
|
166
|
+
* callable from SQL.
|
|
167
|
+
* - `table_only`: sent only so the client knows the capabilities of a table's
|
|
168
|
+
* scan or write function; hidden from `duckdb_functions()` and not callable.
|
|
169
|
+
*/
|
|
170
|
+
export const FUNCTION_VISIBILITY_PUBLIC = "public";
|
|
171
|
+
export const FUNCTION_VISIBILITY_TABLE_ONLY = "table_only";
|
|
172
|
+
export type FunctionVisibility = typeof FUNCTION_VISIBILITY_PUBLIC | typeof FUNCTION_VISIBILITY_TABLE_ONLY;
|
|
173
|
+
|
|
141
174
|
export interface ViewDescriptor {
|
|
142
175
|
name: string;
|
|
143
176
|
/** Ordered raw output identifiers; empty uses query names. */
|
package/src/catalog/interface.ts
CHANGED
|
@@ -168,8 +168,9 @@ export const encodeAttachCatalogInfo = (v: AttachCatalogInfo): Uint8Array =>
|
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
// ============================================================================
|
|
171
|
-
// ScanFunctionResult —
|
|
172
|
-
//
|
|
171
|
+
// ScanFunctionResult — one table function plus its arguments: what a catalog's
|
|
172
|
+
// tableScanFunctionGet returns (wrapped as one ScanBranch on the wire) and the
|
|
173
|
+
// write-function lookups' reply. Mirrors vgi-python's ScanFunctionResult.
|
|
173
174
|
// ============================================================================
|
|
174
175
|
|
|
175
176
|
import { deserializeBatch, serializeBatch, batchFromColumns } from "../util/arrow/index.js";
|
|
@@ -219,9 +220,9 @@ export interface ScanFunctionResultRecord {
|
|
|
219
220
|
|
|
220
221
|
/**
|
|
221
222
|
* Encode a ScanFunctionResult wire record — the single-row batch shape
|
|
222
|
-
* `{ function_name, arguments, required_extensions, schema_path }` that
|
|
223
|
-
*
|
|
224
|
-
*
|
|
223
|
+
* `{ function_name, arguments, required_extensions, schema_path }` that the
|
|
224
|
+
* write-function lookups return and that a function-backed table inlines into
|
|
225
|
+
* `TableInfo.scan_function` / `insert_function` / ....
|
|
225
226
|
*
|
|
226
227
|
* It exists so there is exactly one place that names those columns. The
|
|
227
228
|
* inline-scan path used to restate the schema locally even though codegen
|
|
@@ -304,11 +305,64 @@ export function decodeScanFunctionResult(inner: Record<string, unknown>): ScanFu
|
|
|
304
305
|
};
|
|
305
306
|
}
|
|
306
307
|
|
|
308
|
+
/** One decoded `ScanBranch`: a function branch, or a format branch (`formatName`). */
|
|
309
|
+
export interface ScanBranchInfo extends ScanFunctionResult {
|
|
310
|
+
/** SQL predicate routing rows to this branch, or null. */
|
|
311
|
+
branchFilter: string | null;
|
|
312
|
+
/** Whether INSERTs route to this branch. */
|
|
313
|
+
writable: boolean;
|
|
314
|
+
sourceCatalog: string | null;
|
|
315
|
+
sourceSchemaPath: string[] | null;
|
|
316
|
+
sourceTable: string | null;
|
|
317
|
+
/** DuckDB file format (e.g. `parquet`) for a format branch; null for a function branch. */
|
|
318
|
+
formatName: string | null;
|
|
319
|
+
formatLocations: string[] | null;
|
|
320
|
+
rowCount: bigint | null;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** A decoded `ScanBranchesResult` (the reply of `catalog_table_scan_branches_get`). */
|
|
324
|
+
export interface ScanBranchesInfo {
|
|
325
|
+
branches: ScanBranchInfo[];
|
|
326
|
+
requiredExtensions: string[];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const stringList = (value: unknown): string[] | null =>
|
|
330
|
+
value == null
|
|
331
|
+
? null
|
|
332
|
+
: (Array.isArray(value) ? value : [...(value as Iterable<unknown>)]).filter((v) => v != null).map(String);
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Decode a `ScanBranchesResult` wire dict (`branches`: one IPC stream per
|
|
336
|
+
* `ScanBranch`, `required_extensions`).
|
|
337
|
+
*/
|
|
338
|
+
export function decodeScanBranchesResult(inner: Record<string, unknown>): ScanBranchesInfo {
|
|
339
|
+
const raw = inner.branches == null ? [] : Array.isArray(inner.branches) ? inner.branches : [...(inner.branches as Iterable<unknown>)];
|
|
340
|
+
const branches = raw.map((bytes): ScanBranchInfo => {
|
|
341
|
+
const batch = deserializeBatch(toUint8Array(bytes as Uint8Array));
|
|
342
|
+
const row: Record<string, unknown> = {};
|
|
343
|
+
for (const f of batch.schema.fields) row[f.name] = batch.getChild(f.name)?.get(0) ?? null;
|
|
344
|
+
const fn = decodeScanFunctionResult(row);
|
|
345
|
+
return {
|
|
346
|
+
...fn,
|
|
347
|
+
branchFilter: row.branch_filter == null ? null : String(row.branch_filter),
|
|
348
|
+
writable: row.writable === true,
|
|
349
|
+
sourceCatalog: row.source_catalog == null ? null : String(row.source_catalog),
|
|
350
|
+
sourceSchemaPath: stringList(row.source_schema_path),
|
|
351
|
+
sourceTable: row.source_table == null ? null : String(row.source_table),
|
|
352
|
+
formatName: row.format_name == null ? null : String(row.format_name),
|
|
353
|
+
formatLocations: stringList(row.format_locations),
|
|
354
|
+
rowCount: row.row_count == null ? null : BigInt(row.row_count as bigint | number),
|
|
355
|
+
};
|
|
356
|
+
});
|
|
357
|
+
return { branches, requiredExtensions: stringList(inner.required_extensions) ?? [] };
|
|
358
|
+
}
|
|
359
|
+
|
|
307
360
|
/**
|
|
308
|
-
* Synthesise a one-branch `ScanBranchesResult` wire dict from a
|
|
309
|
-
* `tableScanFunctionGet`
|
|
310
|
-
* `table_scan_branches_get` (catalog_interface.py):
|
|
311
|
-
*
|
|
361
|
+
* Synthesise a one-branch `ScanBranchesResult` wire dict from a
|
|
362
|
+
* `tableScanFunctionGet` result. Mirrors vgi-python's default
|
|
363
|
+
* `table_scan_branches_get` (catalog_interface.py): this is how a
|
|
364
|
+
* single-source catalog answers `catalog_table_scan_branches_get`, the only
|
|
365
|
+
* scan-discovery RPC since protocol 3.3.
|
|
312
366
|
*
|
|
313
367
|
* Each branch is its own IPC stream carried in a `list<binary>` column. The
|
|
314
368
|
* legacy result's `arguments` field is already the nested-IPC form
|
|
@@ -789,6 +843,13 @@ export abstract class CatalogInterface {
|
|
|
789
843
|
* `catalogCapabilities()`), and the catalog must then enforce every one on
|
|
790
844
|
* every write and serve each back as an ENFORCED + ALL_ROWS `ConstraintInfo`
|
|
791
845
|
* record (see `constraintRecord`). Refuse any it cannot enforce.
|
|
846
|
+
*
|
|
847
|
+
* Return `false` when `onConflict` is `IGNORE` (`IF NOT EXISTS`) and the
|
|
848
|
+
* table already existed, leaving it unchanged; `true` or nothing means this
|
|
849
|
+
* call created the table. The worker sends this as the reply's `created`
|
|
850
|
+
* (protocol 3.3), which keeps `CREATE TABLE IF NOT EXISTS ... AS SELECT`
|
|
851
|
+
* from appending into the existing table. A catalog that returns nothing
|
|
852
|
+
* for an existing table makes that CTAS insert its rows into it.
|
|
792
853
|
*/
|
|
793
854
|
tableCreate(
|
|
794
855
|
attachOpaqueData: AttachOpaqueData,
|
|
@@ -798,7 +859,7 @@ export abstract class CatalogInterface {
|
|
|
798
859
|
onConflict: string,
|
|
799
860
|
constraintDefinitions?: Uint8Array[],
|
|
800
861
|
transactionOpaqueData?: TransactionOpaqueData
|
|
801
|
-
): Awaitable<void> {
|
|
862
|
+
): Awaitable<boolean | void> {
|
|
802
863
|
throw new CatalogReadOnlyError("table_create");
|
|
803
864
|
}
|
|
804
865
|
/**
|
|
@@ -890,6 +951,13 @@ export abstract class CatalogInterface {
|
|
|
890
951
|
): Awaitable<void> {
|
|
891
952
|
throw new CatalogReadOnlyError("table_drop");
|
|
892
953
|
}
|
|
954
|
+
/**
|
|
955
|
+
* The table function that reads a single-source table. Protocol 3.3 has no
|
|
956
|
+
* RPC of this name any more: the default `tableScanBranchesGet` calls it and
|
|
957
|
+
* sends the result as a one-branch `catalog_table_scan_branches_get` reply,
|
|
958
|
+
* so a single-source catalog implements only this. Override
|
|
959
|
+
* `tableScanBranchesGet` instead for a multi-source table.
|
|
960
|
+
*/
|
|
893
961
|
tableScanFunctionGet(
|
|
894
962
|
attachOpaqueData: AttachOpaqueData,
|
|
895
963
|
schemaPath: string[],
|