@query-farm/vgi 0.49.1 → 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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/dist/catalog/composite.d.ts +1 -1
  3. package/dist/catalog/descriptors.d.ts +34 -2
  4. package/dist/catalog/interface.d.ts +47 -8
  5. package/dist/catalog/read-only.d.ts +48 -1
  6. package/dist/client/client.d.ts +13 -7
  7. package/dist/client-entry.d.ts +1 -1
  8. package/dist/client-entry.js +40 -16
  9. package/dist/client-entry.js.map +6 -6
  10. package/dist/functions/storage.d.ts +7 -0
  11. package/dist/generated/vgi-client.d.ts +4 -0
  12. package/dist/generated/vgi-protocol-schemas.d.ts +2 -2
  13. package/dist/generated/vgi-service.d.ts +7 -26
  14. package/dist/index.core.d.ts +4 -3
  15. package/dist/index.js +285 -186
  16. package/dist/index.js.map +17 -17
  17. package/dist/protocol/dispatch.d.ts +5 -3
  18. package/dist/serve-entry.js +63 -61
  19. package/dist/serve-entry.js.map +10 -10
  20. package/dist/worker-cf-entry.js +241 -170
  21. package/dist/worker-cf-entry.js.map +16 -16
  22. package/dist/write-results.d.ts +8 -1
  23. package/package.json +1 -1
  24. package/src/catalog/composite.ts +2 -2
  25. package/src/catalog/descriptors.ts +35 -2
  26. package/src/catalog/interface.ts +78 -10
  27. package/src/catalog/read-only.ts +297 -175
  28. package/src/client/client.ts +22 -13
  29. package/src/client-entry.ts +4 -0
  30. package/src/filter-pushdown/evaluate.ts +30 -14
  31. package/src/functions/storage.ts +44 -3
  32. package/src/generated/vgi-client.ts +6 -1
  33. package/src/generated/vgi-protocol-schemas.ts +8 -12
  34. package/src/generated/vgi-service.ts +9 -48
  35. package/src/index.core.ts +4 -3
  36. package/src/protocol/dispatch.ts +5 -3
  37. package/src/protocol/handlers/catalog/table.ts +14 -21
  38. package/src/write-results.ts +8 -3
@@ -229,13 +229,24 @@ class WkbBoundsReader {
229
229
  return value;
230
230
  }
231
231
 
232
- private point(littleEndian: boolean, dimensions: number): Bounds | null {
232
+ /**
233
+ * One vertex, as DuckDB core `&&` sees it: NaN on an axis leaves that axis
234
+ * unbounded and ±inf are ordinary values. Only a POINT geometry whose
235
+ * coordinates are ALL NaN, Z and M included (how WKB spells POINT EMPTY),
236
+ * has no vertex at all: `POINT Z (nan nan 5)` is a vertex unbounded on both
237
+ * axes, as are all-NaN coordinates in a LINESTRING or POLYGON.
238
+ */
239
+ private point(littleEndian: boolean, dimensions: number, isPointGeometry = false): Bounds | null {
233
240
  const x = this.float64(littleEndian);
234
241
  const y = this.float64(littleEndian);
235
- for (let dimension = 2; dimension < dimensions; dimension++) this.float64(littleEndian);
236
- if (Number.isNaN(x) && Number.isNaN(y)) return null;
237
- if (!Number.isFinite(x) || !Number.isFinite(y)) throw new FilterV2Error("WKB coordinate must be finite");
238
- return { minX: x, minY: y, maxX: x, maxY: y };
242
+ let allNaN = Number.isNaN(x) && Number.isNaN(y);
243
+ for (let dimension = 2; dimension < dimensions; dimension++) {
244
+ allNaN = Number.isNaN(this.float64(littleEndian)) && allNaN;
245
+ }
246
+ if (isPointGeometry && allNaN) return null;
247
+ const [minX, maxX] = Number.isNaN(x) ? [-Infinity, Infinity] : [x, x];
248
+ const [minY, maxY] = Number.isNaN(y) ? [-Infinity, Infinity] : [y, y];
249
+ return { minX, minY, maxX, maxY };
239
250
  }
240
251
 
241
252
  private count(littleEndian: boolean): number {
@@ -286,7 +297,7 @@ class WkbBoundsReader {
286
297
  }
287
298
  if (hasSrid) this.uint32(littleEndian);
288
299
 
289
- if (type === 1) return this.point(littleEndian, dimensions);
300
+ if (type === 1) return this.point(littleEndian, dimensions, true);
290
301
  if (type === 2) return this.points(littleEndian, dimensions);
291
302
  if (type === 3) {
292
303
  let bounds: Bounds | null = null;
@@ -503,14 +514,19 @@ export class PushdownFilters {
503
514
  mask.fill(1);
504
515
  for (const predicate of this.predicates) {
505
516
  if (predicate.expression.node === "runtime_filter" && !predicate.expression.supported) continue;
506
- let values: unknown[];
507
- try {
508
- values = Array.from({ length: batch.numRows }, (_, row) => evaluateExpression(
509
- predicate.expression, batch, row, this.evaluationContext));
510
- } catch (error) {
511
- if (predicate.mode === "advisory") continue;
512
- throw error;
513
- }
517
+ // A required predicate that cannot be evaluated fails the scan: DuckDB
518
+ // has dropped it from its own plan. An advisory one only prunes, so a
519
+ // row it cannot evaluate (malformed WKB, a non-binary value, ...) is
520
+ // kept, and the other rows are still filtered.
521
+ const advisory = predicate.mode === "advisory";
522
+ const values = Array.from({ length: batch.numRows }, (_, row) => {
523
+ try {
524
+ return evaluateExpression(predicate.expression, batch, row, this.evaluationContext);
525
+ } catch (error) {
526
+ if (advisory) return true;
527
+ throw error;
528
+ }
529
+ });
514
530
  for (let row = 0; row < batch.numRows; row++) mask[row]! &= values[row] === true ? 1 : 0;
515
531
  }
516
532
  return mask;
@@ -184,6 +184,10 @@ function int64FromKey(b: Uint8Array): number {
184
184
  return Number(new DataView(b.buffer, b.byteOffset, 8).getBigInt64(0, false));
185
185
  }
186
186
 
187
+ const BUSY_TIMEOUT_MS = 30000;
188
+ // Synchronous sleep for the constructor's lock-retry loop.
189
+ const _SLEEP_CELL = new Int32Array(new SharedArrayBuffer(4));
190
+
187
191
  export class FunctionStorageSqlite implements FunctionStorage {
188
192
  readonly dbPath: string;
189
193
  private _db: Database;
@@ -196,12 +200,49 @@ export class FunctionStorageSqlite implements FunctionStorage {
196
200
  // writes across processes via file locking.
197
201
  const Db = _loadDatabase();
198
202
  this._db = new Db(this.dbPath);
199
- this._db.exec("PRAGMA journal_mode=WAL");
203
+ // busy_timeout must come first so every later statement waits for
204
+ // another process's lock instead of failing at once with SQLITE_BUSY
205
+ // ("database is locked") — several workers on one host routinely open
206
+ // the same brand-new file at the same moment.
207
+ this._db.exec(`PRAGMA busy_timeout=${BUSY_TIMEOUT_MS}`);
208
+ this._setWal();
200
209
  this._db.exec("PRAGMA synchronous=NORMAL");
201
- this._db.exec("PRAGMA busy_timeout=30000");
202
210
  this._db.exec("PRAGMA temp_store=MEMORY");
203
211
  this._db.exec("PRAGMA cache_size=-65536");
204
- this._ensureTables();
212
+ // BEGIN IMMEDIATE takes the write lock up front (honouring busy_timeout),
213
+ // so concurrent schema setup serializes instead of hitting the
214
+ // read-to-write upgrade deadlock SQLite reports as an immediate BUSY.
215
+ this._db.exec("BEGIN IMMEDIATE");
216
+ try {
217
+ this._ensureTables();
218
+ this._db.exec("COMMIT");
219
+ } catch (e) {
220
+ try {
221
+ this._db.exec("ROLLBACK");
222
+ } catch {
223
+ // No transaction left to roll back.
224
+ }
225
+ throw e;
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Switch to WAL. Converting a fresh rollback-journal file needs an exclusive
231
+ * lock, and when two connections attempt it together SQLite returns
232
+ * SQLITE_BUSY without consulting the busy handler (waiting could deadlock),
233
+ * so retry here until busy_timeout's worth of time has passed.
234
+ */
235
+ private _setWal(): void {
236
+ const deadline = Date.now() + BUSY_TIMEOUT_MS;
237
+ for (let delay = 5; ; delay = Math.min(delay * 2, 100)) {
238
+ try {
239
+ this._db.exec("PRAGMA journal_mode=WAL");
240
+ return;
241
+ } catch (e: any) {
242
+ if (!String(e?.code ?? "").startsWith("SQLITE_BUSY") || Date.now() >= deadline) throw e;
243
+ Atomics.wait(_SLEEP_CELL, 0, 0, delay);
244
+ }
245
+ }
205
246
  }
206
247
 
207
248
  close(): void {
@@ -2,7 +2,7 @@
2
2
  // GENERATED by vgi.codegen.ts_client. DO NOT EDIT BY HAND.
3
3
  //
4
4
  // Generator: vgi-gen-ts-client v1
5
- // Content hash: ea9cbf1729ea
5
+ // Content hash: da655aba43cc
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python vgi-gen-ts-client \
@@ -185,6 +185,7 @@ export interface FunctionInfo {
185
185
  input_rows_per_call?: number | null;
186
186
  required_settings: string[];
187
187
  required_secrets: SecretLookupEntry[];
188
+ visibility?: string | null;
188
189
  }
189
190
 
190
191
  export interface QueryEvaluationContext {
@@ -667,6 +668,10 @@ export interface TableCreateRequest {
667
668
  layout?: /** @ipc-record TableLayout */ Uint8Array | null;
668
669
  }
669
670
 
671
+ export interface TableCreateResponse {
672
+ created: boolean;
673
+ }
674
+
670
675
  export interface TransactionBeginResponse {
671
676
  transaction_opaque_data?: Uint8Array | null;
672
677
  }
@@ -2,7 +2,7 @@
2
2
  // GENERATED by vgi.codegen.ts_schemas. DO NOT EDIT BY HAND.
3
3
  //
4
4
  // Generator: vgi-gen-ts-schemas v2
5
- // Content hash: b46c5420bb5d
5
+ // Content hash: f5e8b0f6823e
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python vgi-gen-ts-schemas \
@@ -30,7 +30,7 @@ import {
30
30
  } from "../arrow/index.js";
31
31
 
32
32
  /** Canonical fingerprint of the nested catalog wire schemas. */
33
- export const VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
33
+ export const VGI_CATALOG_CONTRACT_HASH = "e0965c93219b6ef6574d82c007c600462594a08085db1242b127ed27e193da0f";
34
34
 
35
35
  // Origin: CatalogInfo
36
36
  export const CatalogInfoSchema = schema([
@@ -132,6 +132,7 @@ export const FunctionInfoSchema = schema([
132
132
  field("input_rows_per_call", int64(), true),
133
133
  field("required_settings", list(field("item", utf8(), true)), false),
134
134
  field("required_secrets", list(field("item", struct([field("secret_type", utf8(), false), field("scope", utf8(), true), field("secret_name", utf8(), true)]), true)), false),
135
+ field("visibility", utf8(), true),
135
136
  ]);
136
137
 
137
138
  // Origin: MacroInfo
@@ -1057,6 +1058,11 @@ export const CatalogTableConstraintsApplyResultSchema = schema([
1057
1058
  field("constraints", list(field("item", binary(), true)), false),
1058
1059
  ]);
1059
1060
 
1061
+ // Origin: method 'catalog_table_create' result
1062
+ export const CatalogTableCreateResultSchema = schema([
1063
+ field("created", bool(), false),
1064
+ ]);
1065
+
1060
1066
  // Origin: method 'catalog_table_get' result
1061
1067
  export const CatalogTableGetResultSchema = schema([
1062
1068
  field("items", list(field("item", binary(), true)), false),
@@ -1614,16 +1620,6 @@ export const CatalogTableScanBranchesGetParamsSchema = schema([
1614
1620
  field("pushdown_filters", binary(), true),
1615
1621
  ]);
1616
1622
 
1617
- // Origin: method 'catalog_table_scan_function_get' params
1618
- export const CatalogTableScanFunctionGetParamsSchema = schema([
1619
- field("attach_opaque_data", binary(), false),
1620
- field("schema_path", list(field("item", utf8(), true)), false),
1621
- field("name", utf8(), false),
1622
- field("at_unit", utf8(), true),
1623
- field("at_value", utf8(), true),
1624
- field("transaction_opaque_data", binary(), true),
1625
- ]);
1626
-
1627
1623
  // Origin: method 'catalog_table_update_function_get' params
1628
1624
  export const CatalogTableUpdateFunctionGetParamsSchema = schema([
1629
1625
  field("attach_opaque_data", binary(), false),
@@ -2,7 +2,7 @@
2
2
  // GENERATED by vgi.codegen.ts_registry. DO NOT EDIT BY HAND.
3
3
  //
4
4
  // Generator: python -m vgi.codegen.ts_registry v1
5
- // Content hash: 2ebfceb69d3f
5
+ // Content hash: c142d70fe6ee
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python python scripts/regen_generated.py
@@ -38,7 +38,7 @@ import {
38
38
  export const VGI_PROTOCOL_NAME = "vgi.v3";
39
39
 
40
40
  /** The protocol's semver, stamped on every request by a client of this protocol. */
41
- export const VGI_PROTOCOL_VERSION = "3.2.0";
41
+ export const VGI_PROTOCOL_VERSION = "3.3.0";
42
42
 
43
43
  /** What a unary handler returns: the result row, now or later. */
44
44
  export type VgiReply<T> = T | ExternalRef | Promise<T | ExternalRef>;
@@ -793,22 +793,6 @@ export interface CatalogTableScanBranchesGetParams {
793
793
  pushdown_filters: Uint8Array | null;
794
794
  }
795
795
 
796
- /** The params of `catalog_table_scan_function_get`, one property per params-schema column. */
797
- export interface CatalogTableScanFunctionGetParams {
798
- /** The `attach_opaque_data` column (`binary`). */
799
- attach_opaque_data: Uint8Array;
800
- /** The `schema_path` column (`list<item: string>`). */
801
- schema_path: WireList<string | null>;
802
- /** The `name` column (`string`). */
803
- name: string;
804
- /** The `at_unit` column (`string`, nullable). */
805
- at_unit: string | null;
806
- /** The `at_value` column (`string`, nullable). */
807
- at_value: string | null;
808
- /** The `transaction_opaque_data` column (`binary`, nullable). */
809
- transaction_opaque_data: Uint8Array | null;
810
- }
811
-
812
796
  /** The params of `catalog_table_update_function_get`, one property per params-schema column. */
813
797
  export interface CatalogTableUpdateFunctionGetParams {
814
798
  /** The `attach_opaque_data` column (`binary`). */
@@ -1414,9 +1398,11 @@ export interface VgiService {
1414
1398
  /**
1415
1399
  * Create a new table.
1416
1400
  *
1401
+ * Protocol 3.3: the reply says whether this call created the table (``created = false`` when ``IF NOT EXISTS`` found an existing one), so ``CREATE TABLE IF NOT EXISTS ... AS SELECT`` does not append into it.
1402
+ *
1417
1403
  * Wire method `catalog_table_create` (unary). Default: answers `UNIMPLEMENTED`.
1418
1404
  */
1419
- catalogTableCreate(params: CatalogTableCreateParams, ctx: CallContext): VgiReply<NoResult>;
1405
+ catalogTableCreate(params: CatalogTableCreateParams, ctx: CallContext): VgiReply<{ result: Uint8Array }>;
1420
1406
 
1421
1407
  /**
1422
1408
  * Get the delete function for a table. Returns `WriteFunctionResult` as IPC bytes.
@@ -1481,7 +1467,7 @@ export interface VgiService {
1481
1467
  *
1482
1468
  * Protocol 3.2: ``pushdown_filters`` carries the query's predicates on the table (an Arrow IPC stream holding one VGI Filter Encoding v2 snapshot batch; column indexes refer to ``TableInfo.columns``) when the table declares ``scan_planning = "filtered"``. Every predicate is advisory. ``None`` means none were collected. See ``docs/protocol/scan-planning.md``.
1483
1469
  *
1484
- * Additive successor to ``catalog_table_scan_function_get``. Workers that only implement the legacy method continue to work — the VGI extension's C++ side catches ``MethodNotImplementedError`` and falls back to the legacy RPC, wrapping the single-function result as a one-branch list. Workers that implement BOTH the legacy and the branches method guarantee single-process compatibility with both old and new extensions.
1470
+ * Protocol 3.3: this is the only scan-discovery method; the single-function ``catalog_table_scan_function_get`` was removed. Every worker must answer it (a single-source table returns one branch). A worker answering ``MethodNotImplemented`` is a protocol error, not a fallback.
1485
1471
  *
1486
1472
  * Multi-branch tables compose a logical scan from N physical sources (canonical case: Kafka hot tier + Iceberg cold tier). The extension's optimizer rewrite stitches the branches together via ``LogicalSetOperation(UNION_ALL, ...)``, one arm per branch.
1487
1473
  *
@@ -1489,13 +1475,6 @@ export interface VgiService {
1489
1475
  */
1490
1476
  catalogTableScanBranchesGet(params: CatalogTableScanBranchesGetParams, ctx: CallContext): VgiReply<{ result: Uint8Array }>;
1491
1477
 
1492
- /**
1493
- * Get the scan function for a table. Returns `ScanFunctionResult` as IPC bytes.
1494
- *
1495
- * Wire method `catalog_table_scan_function_get` (unary). Default: answers `UNIMPLEMENTED`.
1496
- */
1497
- catalogTableScanFunctionGet(params: CatalogTableScanFunctionGetParams, ctx: CallContext): VgiReply<{ result: Uint8Array }>;
1498
-
1499
1478
  /**
1500
1479
  * Get the update function for a table. Returns `WriteFunctionResult` as IPC bytes.
1501
1480
  *
@@ -2401,7 +2380,9 @@ export const VGI_V3_METHODS: readonly VgiMethodSpec[] = [
2401
2380
  params: schema([
2402
2381
  field("request", binary(), false),
2403
2382
  ]),
2404
- result: schema([]),
2383
+ result: schema([
2384
+ field("result", binary(), false),
2385
+ ]),
2405
2386
  doc: "Create a new table.",
2406
2387
  },
2407
2388
  {
@@ -2545,23 +2526,6 @@ export const VGI_V3_METHODS: readonly VgiMethodSpec[] = [
2545
2526
  ]),
2546
2527
  doc: "Get the list of scan branches for a multi-branch table. Returns `ScanBranchesResult` as IPC bytes.",
2547
2528
  },
2548
- {
2549
- name: "catalog_table_scan_function_get",
2550
- key: "catalogTableScanFunctionGet",
2551
- type: "unary",
2552
- params: schema([
2553
- field("attach_opaque_data", binary(), false),
2554
- field("schema_path", list(field("item", utf8(), true)), false),
2555
- field("name", utf8(), false),
2556
- field("at_unit", utf8(), true),
2557
- field("at_value", utf8(), true),
2558
- field("transaction_opaque_data", binary(), true),
2559
- ]),
2560
- result: schema([
2561
- field("result", binary(), false),
2562
- ]),
2563
- doc: "Get the scan function for a table. Returns `ScanFunctionResult` as IPC bytes.",
2564
- },
2565
2529
  {
2566
2530
  name: "catalog_table_update_function_get",
2567
2531
  key: "catalogTableUpdateFunctionGet",
@@ -3029,9 +2993,6 @@ export const UNIMPLEMENTED_VGI_SERVICE: VgiService = Object.freeze({
3029
2993
  catalogTableScanBranchesGet: async () => {
3030
2994
  throw notImplemented("catalog_table_scan_branches_get");
3031
2995
  },
3032
- catalogTableScanFunctionGet: async () => {
3033
- throw notImplemented("catalog_table_scan_function_get");
3034
- },
3035
2996
  catalogTableUpdateFunctionGet: async () => {
3036
2997
  throw notImplemented("catalog_table_update_function_get");
3037
2998
  },
package/src/index.core.ts CHANGED
@@ -106,9 +106,10 @@ export {
106
106
  export type { VgiFunction, FunctionMeta, StreamHandlers, FunctionExample, HandlerState } from "./functions/types.js";
107
107
 
108
108
  // Catalog
109
- export { CatalogInterface, type CatalogAttachResult, type CatalogAttachResultInit, buildCatalogAttachResult, type SchemaContentsInfo, type CatalogContentsResult, type SchemaInfo, encodeSchemaInfo, decodeSchemaInfo, type TableInfo, encodeTableInfo, decodeTableInfo, type ViewInfo, encodeViewInfo, decodeViewInfo, type CatalogInfo, encodeCatalogInfo, decodeCatalogInfo, type FunctionInfo, encodeFunctionInfo, decodeFunctionInfo, type FunctionInfoOptions, type MacroInfo, encodeMacroInfo, decodeMacroInfo, type MacroType, type CopyFromFormatInfo, encodeCopyFromFormatInfo, type AttachOpaqueData, type TransactionOpaqueData, buildScanBranchesResult, encodeFormatOptions, type ScanBranchInput } from "./catalog/interface.js";
110
- export type { CatalogDescriptor, SchemaDescriptor, TableDescriptor, ViewDescriptor, MacroDescriptor, SettingDescriptor, SecretTypeDescriptor, ForeignKeyDef, DefaultValue } from "./catalog/descriptors.js";
111
- export { ReadOnlyCatalogInterface, READ_ONLY_ITEM_ATTACH_ID } from "./catalog/read-only.js";
109
+ export { CatalogInterface, type CatalogAttachResult, type CatalogAttachResultInit, buildCatalogAttachResult, type SchemaContentsInfo, type CatalogContentsResult, type SchemaInfo, encodeSchemaInfo, decodeSchemaInfo, type TableInfo, encodeTableInfo, decodeTableInfo, type ViewInfo, encodeViewInfo, decodeViewInfo, type CatalogInfo, encodeCatalogInfo, decodeCatalogInfo, type FunctionInfo, encodeFunctionInfo, decodeFunctionInfo, type FunctionInfoOptions, type MacroInfo, encodeMacroInfo, decodeMacroInfo, type MacroType, type CopyFromFormatInfo, encodeCopyFromFormatInfo, type AttachOpaqueData, type TransactionOpaqueData, buildScanBranchesResult, encodeFormatOptions, type ScanBranchInput, encodeScanFunctionResult, decodeScanFunctionResult, type ScanFunctionResult, decodeScanBranchesResult, type ScanBranchInfo, type ScanBranchesInfo } from "./catalog/interface.js";
110
+ export type { CatalogDescriptor, SchemaDescriptor, TableDescriptor, ViewDescriptor, MacroDescriptor, SettingDescriptor, SecretTypeDescriptor, ForeignKeyDef, DefaultValue, FunctionVisibility } from "./catalog/descriptors.js";
111
+ export { FUNCTION_VISIBILITY_PUBLIC, FUNCTION_VISIBILITY_TABLE_ONLY } from "./catalog/descriptors.js";
112
+ export { ReadOnlyCatalogInterface, READ_ONLY_ITEM_ATTACH_ID, functionInfoFor } from "./catalog/read-only.js";
112
113
  // vgi.v3 records: constraints, capabilities, column expressions, indexes, macro overloads.
113
114
  export * from "./catalog/public-codecs.js";
114
115
  export { CompositeCatalogInterface } from "./catalog/composite.js";
@@ -73,18 +73,20 @@ export { VGI_PROTOCOL_NAME };
73
73
 
74
74
  /**
75
75
  * The `vgi.v3` protocol hash `vgi_rpc.Reflection.v1` must report for this
76
- * worker: the combined reference's 85 methods. Every SDK hosts
76
+ * worker: the combined reference's 84 methods. Every SDK hosts
77
77
  * every `vgi.v3` method with the reference's schemas, so the hash is one value
78
78
  * across the ports; a method this SDK does not implement is still registered
79
79
  * with the generated UNIMPLEMENTED default (src/generated/vgi-service.ts). The
80
80
  * hash covers method names, types and the params/result/header schemas only
81
81
  * (WIRE_PROTOCOL.md §14).
82
82
  *
83
- * It changes only with vgi.v3's protocol version (currently 3.2.0). Asserted
83
+ * It changes only with vgi.v3's protocol version (currently 3.3.0: 3.3 removed
84
+ * catalog_table_scan_function_get and gave catalog_table_create a `created`
85
+ * result). Asserted
84
86
  * by src/protocol/__tests__/vgi-v3-hash.test.ts; if that test fails, the
85
87
  * surface drifted from the reference -- fix the schemas, do not bump this.
86
88
  */
87
- export const VGI_V3_PROTOCOL_HASH = "171ac8263bf22ffdd5dd4ac2c3d3c4e1dc186a7ceba45d386f324af8c9c6fced";
89
+ export const VGI_V3_PROTOCOL_HASH = "ad10c6b137db8cd0054c8c3d80b0f50946382d52bbd549beaad209e00c180f08";
88
90
 
89
91
  /**
90
92
  * This worker's `vgi.v3` implementation: the generated UNIMPLEMENTED default
@@ -2,12 +2,14 @@
2
2
  import { encodeValidatedTableInfo, validateColumnMetadataIpc } from "../../../catalog/column-metadata.js";
3
3
  import { validateColumnExpressionsIpc } from "../../../catalog/column-expressions.js";
4
4
  import { MethodNotImplementedError } from "@query-farm/vgi-rpc";
5
- // Catalog table handlers: table_get/create/drop, scan_function_get,
5
+ // Catalog table handlers: table_get/create/drop, scan_branches_get (the only
6
+ // scan-discovery RPC since protocol 3.3), the write-function lookups,
6
7
  // column_statistics_get, comment_set, rename, plus all column_* mutations.
7
8
 
8
9
  import type { VgiService } from "../../../generated/vgi-service.js";
9
10
  import {
10
11
  CatalogTableConstraintsApplyResultSchema,
12
+ CatalogTableCreateResultSchema,
11
13
  CatalogTableGetResultSchema,
12
14
  ScanBranchesResultSchema,
13
15
  ScanFunctionResultSchema,
@@ -79,7 +81,7 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
79
81
  validateColumnMetadataIpc(toUint8Array(params.columns));
80
82
  validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
81
83
  requireCreateColumns(toUint8Array(params.columns), definitions);
82
- await cat.tableCreate(
84
+ const created = await cat.tableCreate(
83
85
  attach,
84
86
  params.schema_path,
85
87
  params.name,
@@ -88,7 +90,12 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
88
90
  definitions,
89
91
  params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
90
92
  );
91
- return {};
93
+ // Protocol 3.3 `created`: a catalog returns false only when IF NOT EXISTS
94
+ // found the table; nothing (the pre-3.3 contract) means it created it.
95
+ if (created != null && typeof created !== "boolean") {
96
+ throw new TypeError(`tableCreate must return a boolean or nothing, got ${typeof created}`);
97
+ }
98
+ return wrapResult({ created: created !== false }, CatalogTableCreateResultSchema);
92
99
  });
93
100
 
94
101
  // catalog_table_constraints_apply (ALTER TABLE ... SET/DROP NOT NULL and
@@ -152,20 +159,6 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
152
159
  return { result: stats?.bytes ?? null };
153
160
  });
154
161
 
155
- // catalog_table_scan_function_get
156
- const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
157
- const cat = getCatalog();
158
- const scanResult = await cat.tableScanFunctionGet(
159
- toUint8Array(params.attach_opaque_data),
160
- params.schema_path,
161
- params.name,
162
- params.at_unit,
163
- params.at_value,
164
- params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined
165
- );
166
- return wrapResult(scanResult, ScanFunctionResultSchema);
167
- });
168
-
169
162
  // catalog_table_{insert,update,delete}_function_get — the table in-out
170
163
  // function backing each DML statement. A catalog whose tables inline these
171
164
  // into TableInfo is only asked when the client skipped the inline value.
@@ -200,9 +193,10 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
200
193
  return wrapResult(result, ScanFunctionResultSchema);
201
194
  });
202
195
 
203
- // catalog_table_scan_branches_get — branches-aware variant of
204
- // scan_function_get. The branches-aware C++ extension calls this for every
205
- // table scan; single-source catalogs synthesise a one-branch result.
196
+ // catalog_table_scan_branches_get — the extension calls this for every table
197
+ // scan. Protocol 3.3 removed catalog_table_scan_function_get, so it is the
198
+ // only scan-discovery RPC; a single-source catalog's tableScanFunctionGet is
199
+ // wrapped as a one-branch result by the CatalogInterface default.
206
200
  //
207
201
  // Protocol 3.2: always dispatches to tableScanBranchesPlan with the
208
202
  // `pushdown_filters` wrapped as a ScanPlanningFilters (decoded lazily against
@@ -396,7 +390,6 @@ export function catalogTableHandlers(getCatalog: GetCatalog, signingKey?: Uint8A
396
390
  catalogTableCreate,
397
391
  catalogTableDrop,
398
392
  catalogTableColumnStatisticsGet,
399
- catalogTableScanFunctionGet,
400
393
  catalogTableInsertFunctionGet,
401
394
  catalogTableUpdateFunctionGet,
402
395
  catalogTableDeleteFunctionGet,
@@ -152,14 +152,21 @@ export function writeResultBatch(
152
152
  /** What DuckDB asked a write function for, decoded from `write_options`. */
153
153
  export interface WriteOptions {
154
154
  resultMode: WriteResultMode;
155
- /** `throw` (default), or the INSERT ... ON CONFLICT action DuckDB requested. */
155
+ /**
156
+ * @deprecated Always `"throw"`. Protocol 3.3 removed `on_conflict` from the
157
+ * `write_options` batch: DuckDB rewrites every `INSERT ... ON CONFLICT` and
158
+ * `INSERT OR REPLACE` into a MERGE before any catalog hook runs, so a write
159
+ * function never received anything else.
160
+ */
156
161
  onConflict: string;
162
+ /** @deprecated Always empty: protocol 3.3 removed `on_conflict_columns` (see `onConflict`). */
157
163
  onConflictColumns: string[];
158
164
  }
159
165
 
160
166
  /**
161
167
  * Decode the `write_options` named argument of a write function's bind (a
162
168
  * serialized one-row batch). Missing options mean a plain `count` write.
169
+ * Protocol 3.3: the batch carries only `result_mode`.
163
170
  */
164
171
  export function writeOptions(bindCall: Pick<BindRequest, "arguments">): WriteOptions {
165
172
  const out: WriteOptions = { resultMode: "count", onConflict: "throw", onConflictColumns: [] };
@@ -168,7 +175,5 @@ export function writeOptions(bindCall: Pick<BindRequest, "arguments">): WriteOpt
168
175
  const row = [...iterRows(deserializeBatch(toUint8Array(raw)))][0] as Record<string, unknown> | undefined;
169
176
  if (!row) return out;
170
177
  if (row.result_mode != null) out.resultMode = coerceWriteResultMode(row.result_mode);
171
- if (row.on_conflict != null) out.onConflict = String(row.on_conflict);
172
- if (row.on_conflict_columns != null) out.onConflictColumns = Array.from(row.on_conflict_columns as Iterable<string>);
173
178
  return out;
174
179
  }