@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
package/dist/index.js CHANGED
@@ -2331,12 +2331,34 @@ class FunctionStorageSqlite {
2331
2331
  this.dbPath = dbPath ?? getDefaultDbPath();
2332
2332
  const Db = _loadDatabase();
2333
2333
  this._db = new Db(this.dbPath);
2334
- this._db.exec("PRAGMA journal_mode=WAL");
2334
+ this._db.exec(`PRAGMA busy_timeout=${BUSY_TIMEOUT_MS}`);
2335
+ this._setWal();
2335
2336
  this._db.exec("PRAGMA synchronous=NORMAL");
2336
- this._db.exec("PRAGMA busy_timeout=30000");
2337
2337
  this._db.exec("PRAGMA temp_store=MEMORY");
2338
2338
  this._db.exec("PRAGMA cache_size=-65536");
2339
- this._ensureTables();
2339
+ this._db.exec("BEGIN IMMEDIATE");
2340
+ try {
2341
+ this._ensureTables();
2342
+ this._db.exec("COMMIT");
2343
+ } catch (e) {
2344
+ try {
2345
+ this._db.exec("ROLLBACK");
2346
+ } catch {}
2347
+ throw e;
2348
+ }
2349
+ }
2350
+ _setWal() {
2351
+ const deadline = Date.now() + BUSY_TIMEOUT_MS;
2352
+ for (let delay = 5;; delay = Math.min(delay * 2, 100)) {
2353
+ try {
2354
+ this._db.exec("PRAGMA journal_mode=WAL");
2355
+ return;
2356
+ } catch (e) {
2357
+ if (!String(e?.code ?? "").startsWith("SQLITE_BUSY") || Date.now() >= deadline)
2358
+ throw e;
2359
+ Atomics.wait(_SLEEP_CELL, 0, 0, delay);
2360
+ }
2361
+ }
2340
2362
  }
2341
2363
  close() {
2342
2364
  this._db.close();
@@ -2524,7 +2546,7 @@ function setStorage(impl) {
2524
2546
  function bufferArg(data) {
2525
2547
  return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
2526
2548
  }
2527
- var _BUN_SQLITE_MOD = "bun:sqlite", _NODE_OS_MOD = "node:os", _NODE_PATH_MOD = "node:path", _NODE_FS_MOD = "node:fs", _Database = null, UnknownInvocationError, FrameworkNS, NS_WORKER2, _resolved = null, storage;
2549
+ var _BUN_SQLITE_MOD = "bun:sqlite", _NODE_OS_MOD = "node:os", _NODE_PATH_MOD = "node:path", _NODE_FS_MOD = "node:fs", _Database = null, UnknownInvocationError, FrameworkNS, NS_WORKER2, BUSY_TIMEOUT_MS = 30000, _SLEEP_CELL, _resolved = null, storage;
2528
2550
  var init_storage = __esm(() => {
2529
2551
  UnknownInvocationError = class UnknownInvocationError extends Error {
2530
2552
  constructor(message) {
@@ -2543,6 +2565,7 @@ var init_storage = __esm(() => {
2543
2565
  STREAMING_FINALIZE: textBytes("_vgi/streaming_finalize")
2544
2566
  };
2545
2567
  NS_WORKER2 = new TextEncoder().encode("worker");
2568
+ _SLEEP_CELL = new Int32Array(new SharedArrayBuffer(4));
2546
2569
  storage = new Proxy({}, {
2547
2570
  get(_t, prop, _r) {
2548
2571
  const inst = getDefaultStorage();
@@ -2698,10 +2721,6 @@ function writeOptions(bindCall) {
2698
2721
  return out;
2699
2722
  if (row.result_mode != null)
2700
2723
  out.resultMode = coerceWriteResultMode(row.result_mode);
2701
- if (row.on_conflict != null)
2702
- out.onConflict = String(row.on_conflict);
2703
- if (row.on_conflict_columns != null)
2704
- out.onConflictColumns = Array.from(row.on_conflict_columns);
2705
2724
  return out;
2706
2725
  }
2707
2726
  // src/secrets/requirements.ts
@@ -4262,16 +4281,18 @@ class WkbBoundsReader {
4262
4281
  this.offset += 8;
4263
4282
  return value;
4264
4283
  }
4265
- point(littleEndian, dimensions) {
4284
+ point(littleEndian, dimensions, isPointGeometry = false) {
4266
4285
  const x = this.float64(littleEndian);
4267
4286
  const y = this.float64(littleEndian);
4268
- for (let dimension = 2;dimension < dimensions; dimension++)
4269
- this.float64(littleEndian);
4270
- if (Number.isNaN(x) && Number.isNaN(y))
4287
+ let allNaN = Number.isNaN(x) && Number.isNaN(y);
4288
+ for (let dimension = 2;dimension < dimensions; dimension++) {
4289
+ allNaN = Number.isNaN(this.float64(littleEndian)) && allNaN;
4290
+ }
4291
+ if (isPointGeometry && allNaN)
4271
4292
  return null;
4272
- if (!Number.isFinite(x) || !Number.isFinite(y))
4273
- throw new FilterV2Error("WKB coordinate must be finite");
4274
- return { minX: x, minY: y, maxX: x, maxY: y };
4293
+ const [minX, maxX] = Number.isNaN(x) ? [-Infinity, Infinity] : [x, x];
4294
+ const [minY, maxY] = Number.isNaN(y) ? [-Infinity, Infinity] : [y, y];
4295
+ return { minX, minY, maxX, maxY };
4275
4296
  }
4276
4297
  count(littleEndian) {
4277
4298
  const count = this.uint32(littleEndian);
@@ -4323,7 +4344,7 @@ class WkbBoundsReader {
4323
4344
  if (hasSrid)
4324
4345
  this.uint32(littleEndian);
4325
4346
  if (type === 1)
4326
- return this.point(littleEndian, dimensions);
4347
+ return this.point(littleEndian, dimensions, true);
4327
4348
  if (type === 2)
4328
4349
  return this.points(littleEndian, dimensions);
4329
4350
  if (type === 3) {
@@ -4538,14 +4559,16 @@ class PushdownFilters {
4538
4559
  for (const predicate of this.predicates) {
4539
4560
  if (predicate.expression.node === "runtime_filter" && !predicate.expression.supported)
4540
4561
  continue;
4541
- let values;
4542
- try {
4543
- values = Array.from({ length: batch.numRows }, (_, row) => evaluateExpression(predicate.expression, batch, row, this.evaluationContext));
4544
- } catch (error) {
4545
- if (predicate.mode === "advisory")
4546
- continue;
4547
- throw error;
4548
- }
4562
+ const advisory = predicate.mode === "advisory";
4563
+ const values = Array.from({ length: batch.numRows }, (_, row) => {
4564
+ try {
4565
+ return evaluateExpression(predicate.expression, batch, row, this.evaluationContext);
4566
+ } catch (error) {
4567
+ if (advisory)
4568
+ return true;
4569
+ throw error;
4570
+ }
4571
+ });
4549
4572
  for (let row = 0;row < batch.numRows; row++)
4550
4573
  mask[row] &= values[row] === true ? 1 : 0;
4551
4574
  }
@@ -8950,7 +8973,7 @@ function decodeASDCollection(schema, bytes) {
8950
8973
 
8951
8974
  // src/generated/vgi-protocol-schemas.ts
8952
8975
  init_arrow();
8953
- var VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
8976
+ var VGI_CATALOG_CONTRACT_HASH = "e0965c93219b6ef6574d82c007c600462594a08085db1242b127ed27e193da0f";
8954
8977
  var CatalogInfoSchema = schema2([
8955
8978
  field2("name", utf82(), false),
8956
8979
  field2("implementation_version", utf82(), true),
@@ -9041,7 +9064,8 @@ var FunctionInfoSchema = schema2([
9041
9064
  field2("input_from_args", bool2(), false),
9042
9065
  field2("input_rows_per_call", int642(), true),
9043
9066
  field2("required_settings", list2(field2("item", utf82(), true)), false),
9044
- field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false)
9067
+ field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false),
9068
+ field2("visibility", utf82(), true)
9045
9069
  ]);
9046
9070
  var MacroInfoSchema = schema2([
9047
9071
  field2("comment", utf82(), true),
@@ -9754,6 +9778,9 @@ var CatalogTableConstraintsApplyResultSchema = schema2([
9754
9778
  field2("definition_revision", binary2(), false),
9755
9779
  field2("constraints", list2(field2("item", binary2(), true)), false)
9756
9780
  ]);
9781
+ var CatalogTableCreateResultSchema = schema2([
9782
+ field2("created", bool2(), false)
9783
+ ]);
9757
9784
  var CatalogTableGetResultSchema = schema2([
9758
9785
  field2("items", list2(field2("item", binary2(), true)), false)
9759
9786
  ]);
@@ -10159,14 +10186,6 @@ var CatalogTableScanBranchesGetParamsSchema = schema2([
10159
10186
  field2("transaction_opaque_data", binary2(), true),
10160
10187
  field2("pushdown_filters", binary2(), true)
10161
10188
  ]);
10162
- var CatalogTableScanFunctionGetParamsSchema = schema2([
10163
- field2("attach_opaque_data", binary2(), false),
10164
- field2("schema_path", list2(field2("item", utf82(), true)), false),
10165
- field2("name", utf82(), false),
10166
- field2("at_unit", utf82(), true),
10167
- field2("at_value", utf82(), true),
10168
- field2("transaction_opaque_data", binary2(), true)
10169
- ]);
10170
10189
  var CatalogTableUpdateFunctionGetParamsSchema = schema2([
10171
10190
  field2("attach_opaque_data", binary2(), false),
10172
10191
  field2("schema_path", list2(field2("item", utf82(), true)), false),
@@ -11767,6 +11786,29 @@ function decodeScanFunctionResult(inner) {
11767
11786
  schemaPath: inner.schema_path == null ? null : (Array.isArray(inner.schema_path) ? inner.schema_path : [...inner.schema_path]).filter((value) => value != null).map(String)
11768
11787
  };
11769
11788
  }
11789
+ var stringList = (value) => value == null ? null : (Array.isArray(value) ? value : [...value]).filter((v) => v != null).map(String);
11790
+ function decodeScanBranchesResult(inner) {
11791
+ const raw = inner.branches == null ? [] : Array.isArray(inner.branches) ? inner.branches : [...inner.branches];
11792
+ const branches = raw.map((bytes) => {
11793
+ const batch = deserializeBatch(toUint8Array(bytes));
11794
+ const row = {};
11795
+ for (const f of batch.schema.fields)
11796
+ row[f.name] = batch.getChild(f.name)?.get(0) ?? null;
11797
+ const fn = decodeScanFunctionResult(row);
11798
+ return {
11799
+ ...fn,
11800
+ branchFilter: row.branch_filter == null ? null : String(row.branch_filter),
11801
+ writable: row.writable === true,
11802
+ sourceCatalog: row.source_catalog == null ? null : String(row.source_catalog),
11803
+ sourceSchemaPath: stringList(row.source_schema_path),
11804
+ sourceTable: row.source_table == null ? null : String(row.source_table),
11805
+ formatName: row.format_name == null ? null : String(row.format_name),
11806
+ formatLocations: stringList(row.format_locations),
11807
+ rowCount: row.row_count == null ? null : BigInt(row.row_count)
11808
+ };
11809
+ });
11810
+ return { branches, requiredExtensions: stringList(inner.required_extensions) ?? [] };
11811
+ }
11770
11812
  function singleBranchResult(legacy) {
11771
11813
  return {
11772
11814
  branches: [
@@ -12113,6 +12155,16 @@ function sameBytes2(a, b) {
12113
12155
  return false;
12114
12156
  return true;
12115
12157
  }
12158
+ // src/catalog/descriptors.ts
12159
+ var FUNCTION_VISIBILITY_PUBLIC = "public";
12160
+ var FUNCTION_VISIBILITY_TABLE_ONLY = "table_only";
12161
+ function schemaDescriptorPath(schema) {
12162
+ if (schema.path)
12163
+ return schema.path;
12164
+ if (schema.name)
12165
+ return [schema.name];
12166
+ throw new Error("SchemaDescriptor requires a non-empty path");
12167
+ }
12116
12168
  // src/catalog/scan-planning.ts
12117
12169
  init_arrow();
12118
12170
  var SCAN_PLANNING_BIND = "bind";
@@ -12502,15 +12554,6 @@ function encodeValidatedTableInfo(info) {
12502
12554
  // src/catalog/read-only.ts
12503
12555
  init_arrow();
12504
12556
 
12505
- // src/catalog/descriptors.ts
12506
- function schemaDescriptorPath(schema) {
12507
- if (schema.path)
12508
- return schema.path;
12509
- if (schema.name)
12510
- return [schema.name];
12511
- throw new Error("SchemaDescriptor requires a non-empty path");
12512
- }
12513
-
12514
12557
  // src/metadata/types.ts
12515
12558
  var CatalogFunctionType;
12516
12559
  ((CatalogFunctionType) => {
@@ -12871,6 +12914,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
12871
12914
  _version = 1;
12872
12915
  _functionListings = new Map;
12873
12916
  _functionInfos = new Map;
12917
+ _builtListings;
12874
12918
  constructor(descriptor, registry, options = {}) {
12875
12919
  super();
12876
12920
  if (descriptor.defaultSchema != null && (descriptor.defaultSchema.length === 0 || descriptor.defaultSchema.includes("\x00"))) {
@@ -12899,12 +12943,18 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
12899
12943
  }
12900
12944
  }
12901
12945
  }
12946
+ get _listings() {
12947
+ return (this._builtListings ??= buildFunctionListings(this._descriptor)).listings;
12948
+ }
12949
+ get _listedIn() {
12950
+ return (this._builtListings ??= buildFunctionListings(this._descriptor)).listedIn;
12951
+ }
12952
+ functionVisibility(schema, fn) {
12953
+ return this._listings.get(schema)?.get(fn) ?? null;
12954
+ }
12902
12955
  _schemaForFunction(fn) {
12903
- for (const sch of this._descriptor.schemas ?? []) {
12904
- if ((sch.functions ?? []).includes(fn))
12905
- return schemaDescriptorPath(sch);
12906
- }
12907
- return null;
12956
+ const sch = this._listedIn.get(fn);
12957
+ return sch ? schemaDescriptorPath(sch) : null;
12908
12958
  }
12909
12959
  catalogs() {
12910
12960
  return [this._descriptor.name];
@@ -12999,7 +13049,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
12999
13049
  }
13000
13050
  _estimatedObjectCount(s) {
13001
13051
  let scalar = 0, aggregate = 0, table = 0;
13002
- for (const f of s.functions ?? []) {
13052
+ for (const f of this._listings.get(s)?.keys() ?? []) {
13003
13053
  if (f.kind === "scalar")
13004
13054
  scalar++;
13005
13055
  else if (f.kind === "aggregate")
@@ -13168,12 +13218,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
13168
13218
  }
13169
13219
  schemaContentsFunctions(attachOpaqueData, path, type, transactionOpaqueData) {
13170
13220
  const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), path));
13171
- if (!schema || !schema.functions)
13221
+ const entries = schema ? this._listings.get(schema) : undefined;
13222
+ if (!schema || !entries || entries.size === 0)
13172
13223
  return [];
13224
+ const listed = [...entries.keys()];
13173
13225
  const kind = functionListingKind(type);
13174
13226
  const canonicalPath = schemaDescriptorPath(schema);
13175
13227
  if (!sameSpelling(path, canonicalPath)) {
13176
- return schema.functions.filter((f) => inListing(f, kind)).map((f) => this._functionToInfo(f, path));
13228
+ return listed.filter((f) => inListing(f, kind)).map((f) => this._functionToInfo(f, path, entries.get(f)));
13177
13229
  }
13178
13230
  let listings = this._functionListings.get(schema);
13179
13231
  if (!listings) {
@@ -13182,7 +13234,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
13182
13234
  }
13183
13235
  let listing = listings.get(kind);
13184
13236
  if (!listing) {
13185
- listing = Object.freeze(schema.functions.filter((f) => inListing(f, kind)).map((f) => this._sharedFunctionInfo(schema, f)));
13237
+ listing = Object.freeze(listed.filter((f) => inListing(f, kind)).map((f) => this._sharedFunctionInfo(schema, f)));
13186
13238
  listings.set(kind, listing);
13187
13239
  }
13188
13240
  return listing.slice();
@@ -13195,106 +13247,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
13195
13247
  }
13196
13248
  let info = infos.get(f);
13197
13249
  if (!info) {
13198
- info = freezeCatalogItem(structuredClone(this._functionToInfo(f, schemaDescriptorPath(schema))));
13250
+ const visibility = this.functionVisibility(schema, f) ?? FUNCTION_VISIBILITY_PUBLIC;
13251
+ info = freezeCatalogItem(structuredClone(this._functionToInfo(f, schemaDescriptorPath(schema), visibility)));
13199
13252
  infos.set(f, info);
13200
13253
  }
13201
13254
  return info;
13202
13255
  }
13203
- _functionToInfo(f, path) {
13204
- const meta = resolveMetadata(f);
13205
- const argSchema = argumentSpecsToSchema(f.argumentSpecs);
13206
- const argBytes = serializeSchema(argSchema);
13207
- const defaults = f.meta.parameterDefaultValues ?? null;
13208
- if (defaults) {
13209
- if (defaults.numRows !== 1) {
13210
- throw new Error(`parameterDefaultValues must contain exactly one row, got ${defaults.numRows}`);
13211
- }
13212
- let argumentIndex = 0;
13213
- for (const defaultField of defaults.schema.fields) {
13214
- while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
13215
- argumentIndex++;
13216
- }
13217
- if (argumentIndex === argSchema.fields.length) {
13218
- throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
13219
- }
13220
- const argumentField = argSchema.fields[argumentIndex];
13221
- if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
13222
- throw new Error(`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` + `expected ${typeSignature(argumentField.type)}`);
13223
- }
13224
- argumentIndex++;
13225
- }
13226
- }
13227
- const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
13228
- const requiredSecrets = meta.requiredSecrets.map((s) => ({
13229
- secret_type: s.secretType,
13230
- scope: s.scope,
13231
- secret_name: s.secretName
13232
- }));
13233
- const derivedTags = {};
13234
- const tags = { ...derivedTags, ...meta.tags ?? {} };
13235
- return {
13236
- comment: null,
13237
- tags,
13238
- name: f.meta.name,
13239
- schema_path: normalizeSchemaPath(path),
13240
- function_type: meta.functionType.toUpperCase(),
13241
- arguments: argBytes,
13242
- output_schema: outputSchemaBytes,
13243
- parameter_default_values: defaults ? serializeBatch(defaults) : null,
13244
- stability: meta.stability,
13245
- null_handling: meta.nullHandling,
13246
- argument_monotonicity: meta.argumentMonotonicity,
13247
- description: meta.description,
13248
- examples: meta.examples.map((e) => ({
13249
- sql: e.sql,
13250
- description: e.description,
13251
- expected_output: null
13252
- })),
13253
- categories: meta.categories,
13254
- projection_pushdown: meta.projectionPushdown,
13255
- filter_pushdown: meta.filterPushdown,
13256
- sampling_pushdown: meta.samplingPushdown,
13257
- late_materialization: f.kind === "table" && f.meta.lateMaterialization === true ? true : null,
13258
- filter_semantic_profiles: meta.filterSemanticProfiles,
13259
- additional_filter_functions: meta.additionalFilterFunctions.map((value) => ({
13260
- namespace: value.namespace,
13261
- name: value.name,
13262
- version: BigInt(value.version)
13263
- })),
13264
- runtime_filter_algorithms: meta.runtimeFilterAlgorithms.map((value) => ({
13265
- namespace: value.namespace,
13266
- name: value.name,
13267
- version: BigInt(value.version)
13268
- })),
13269
- filter_evaluation_contexts: meta.filterEvaluationContexts.map((value) => ({
13270
- profile: value.profile,
13271
- provider_fingerprint: value.providerFingerprint
13272
- })),
13273
- order_preservation: meta.preservesOrder,
13274
- max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
13275
- supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
13276
- supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
13277
- filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
13278
- supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
13279
- split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
13280
- partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
13281
- order_dependent: meta.orderDependent,
13282
- distinct_dependent: meta.distinctDependent,
13283
- supports_window: false,
13284
- streaming_partitioned: false,
13285
- has_finalize: f.kind === "table_in_out" && f.meta.hasFinalize === true || f.kind === "table_buffering",
13286
- source_order_dependent: f.kind === "table_buffering" && f.meta.sourceOrderDependent === true,
13287
- sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
13288
- requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
13289
- input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
13290
- input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
13291
- required_settings: meta.requiredSettings,
13292
- required_secrets: requiredSecrets.map((s) => ({
13293
- secret_type: s.secret_type,
13294
- scope: s.scope,
13295
- secret_name: s.secret_name
13296
- }))
13297
- };
13256
+ _functionToInfo(f, path, visibility) {
13257
+ return functionInfoFor(f, path, visibility);
13298
13258
  }
13299
13259
  _globalFunctionInfos() {
13300
13260
  const globals = this._descriptor.globalFunctions ?? [];
@@ -13660,6 +13620,104 @@ function sameSpelling(left, right) {
13660
13620
  const b = normalizeSchemaPath(right);
13661
13621
  return a.length === b.length && a.every((part, i) => part === b[i]);
13662
13622
  }
13623
+ function functionInfoFor(f, schemaPath, visibility = FUNCTION_VISIBILITY_PUBLIC) {
13624
+ const path = schemaPath;
13625
+ const meta = resolveMetadata(f);
13626
+ const argSchema = argumentSpecsToSchema(f.argumentSpecs);
13627
+ const argBytes = serializeSchema(argSchema);
13628
+ const defaults = f.meta.parameterDefaultValues ?? null;
13629
+ if (defaults) {
13630
+ if (defaults.numRows !== 1) {
13631
+ throw new Error(`parameterDefaultValues must contain exactly one row, got ${defaults.numRows}`);
13632
+ }
13633
+ let argumentIndex = 0;
13634
+ for (const defaultField of defaults.schema.fields) {
13635
+ while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
13636
+ argumentIndex++;
13637
+ }
13638
+ if (argumentIndex === argSchema.fields.length) {
13639
+ throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
13640
+ }
13641
+ const argumentField = argSchema.fields[argumentIndex];
13642
+ if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
13643
+ throw new Error(`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` + `expected ${typeSignature(argumentField.type)}`);
13644
+ }
13645
+ argumentIndex++;
13646
+ }
13647
+ }
13648
+ const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
13649
+ const requiredSecrets = meta.requiredSecrets.map((s) => ({
13650
+ secret_type: s.secretType,
13651
+ scope: s.scope,
13652
+ secret_name: s.secretName
13653
+ }));
13654
+ const derivedTags = {};
13655
+ const tags = { ...derivedTags, ...meta.tags ?? {} };
13656
+ return {
13657
+ comment: null,
13658
+ tags,
13659
+ name: f.meta.name,
13660
+ schema_path: normalizeSchemaPath(path),
13661
+ function_type: meta.functionType.toUpperCase(),
13662
+ arguments: argBytes,
13663
+ output_schema: outputSchemaBytes,
13664
+ parameter_default_values: defaults ? serializeBatch(defaults) : null,
13665
+ stability: meta.stability,
13666
+ null_handling: meta.nullHandling,
13667
+ argument_monotonicity: meta.argumentMonotonicity,
13668
+ description: meta.description,
13669
+ examples: meta.examples.map((e) => ({
13670
+ sql: e.sql,
13671
+ description: e.description,
13672
+ expected_output: null
13673
+ })),
13674
+ categories: meta.categories,
13675
+ projection_pushdown: meta.projectionPushdown,
13676
+ filter_pushdown: meta.filterPushdown,
13677
+ sampling_pushdown: meta.samplingPushdown,
13678
+ late_materialization: f.kind === "table" && f.meta.lateMaterialization === true ? true : null,
13679
+ filter_semantic_profiles: meta.filterSemanticProfiles,
13680
+ additional_filter_functions: meta.additionalFilterFunctions.map((value) => ({
13681
+ namespace: value.namespace,
13682
+ name: value.name,
13683
+ version: BigInt(value.version)
13684
+ })),
13685
+ runtime_filter_algorithms: meta.runtimeFilterAlgorithms.map((value) => ({
13686
+ namespace: value.namespace,
13687
+ name: value.name,
13688
+ version: BigInt(value.version)
13689
+ })),
13690
+ filter_evaluation_contexts: meta.filterEvaluationContexts.map((value) => ({
13691
+ profile: value.profile,
13692
+ provider_fingerprint: value.providerFingerprint
13693
+ })),
13694
+ order_preservation: meta.preservesOrder,
13695
+ max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
13696
+ supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
13697
+ supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
13698
+ filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
13699
+ supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
13700
+ split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
13701
+ partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
13702
+ order_dependent: meta.orderDependent,
13703
+ distinct_dependent: meta.distinctDependent,
13704
+ supports_window: false,
13705
+ streaming_partitioned: false,
13706
+ has_finalize: f.kind === "table_in_out" && f.meta.hasFinalize === true || f.kind === "table_buffering",
13707
+ source_order_dependent: f.kind === "table_buffering" && f.meta.sourceOrderDependent === true,
13708
+ sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
13709
+ requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
13710
+ input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
13711
+ input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
13712
+ required_settings: meta.requiredSettings,
13713
+ required_secrets: requiredSecrets.map((s) => ({
13714
+ secret_type: s.secret_type,
13715
+ scope: s.scope,
13716
+ secret_name: s.secret_name
13717
+ })),
13718
+ visibility
13719
+ };
13720
+ }
13663
13721
  function writeFunctionOf(table, operation) {
13664
13722
  return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
13665
13723
  }
@@ -13669,7 +13727,59 @@ function validateTableScanPlanning(table) {
13669
13727
  throw new Error(`Table '${table.name}': scanPlanning 'filtered' requires columns and no function; the catalog's ` + "tableScanBranchesPlan supplies the scan per query");
13670
13728
  }
13671
13729
  }
13730
+ function buildFunctionListings(descriptor) {
13731
+ const listings = new Map;
13732
+ const listedIn = new Map;
13733
+ const writeFunctions = new Set;
13734
+ for (const sch of descriptor.schemas ?? []) {
13735
+ for (const tbl of sch.tables ?? []) {
13736
+ for (const op of WRITE_OPERATIONS) {
13737
+ const fn = writeFunctionOf(tbl, op);
13738
+ if (fn)
13739
+ writeFunctions.add(fn);
13740
+ }
13741
+ }
13742
+ }
13743
+ const listingOf = (sch) => {
13744
+ let listing = listings.get(sch);
13745
+ if (!listing)
13746
+ listings.set(sch, listing = new Map);
13747
+ return listing;
13748
+ };
13749
+ for (const sch of descriptor.schemas ?? []) {
13750
+ const listing = listingOf(sch);
13751
+ for (const fn of sch.functions ?? []) {
13752
+ if (!listedIn.has(fn))
13753
+ listedIn.set(fn, sch);
13754
+ listing.set(fn, writeFunctions.has(fn) ? FUNCTION_VISIBILITY_TABLE_ONLY : FUNCTION_VISIBILITY_PUBLIC);
13755
+ }
13756
+ }
13757
+ const declared = new Set(listedIn.keys());
13758
+ for (const sch of descriptor.schemas ?? []) {
13759
+ for (const tbl of sch.tables ?? []) {
13760
+ const named = [
13761
+ [tbl.function, false],
13762
+ ...WRITE_OPERATIONS.map((op) => [writeFunctionOf(tbl, op), true])
13763
+ ];
13764
+ for (const [fn, isWrite] of named) {
13765
+ if (!fn || declared.has(fn))
13766
+ continue;
13767
+ const owner = listedIn.get(fn) ?? sch;
13768
+ if (!listedIn.has(fn))
13769
+ listedIn.set(fn, owner);
13770
+ const listing = listingOf(owner);
13771
+ const visibility = !isWrite && !writeFunctions.has(fn) && tbl.exposeScan === true ? FUNCTION_VISIBILITY_PUBLIC : FUNCTION_VISIBILITY_TABLE_ONLY;
13772
+ if (listing.get(fn) !== FUNCTION_VISIBILITY_PUBLIC)
13773
+ listing.set(fn, visibility);
13774
+ }
13775
+ }
13776
+ }
13777
+ return { listings, listedIn };
13778
+ }
13672
13779
  function validateWritableTable(table) {
13780
+ if (table.exposeScan && !table.function) {
13781
+ throw new Error(`Table '${table.name}': exposeScan requires a scan function (set 'function')`);
13782
+ }
13673
13783
  const modes = validateWriteResultModes(table.writeResultModes ?? {});
13674
13784
  for (const operation of Object.keys(modes)) {
13675
13785
  if (!writeFunctionOf(table, operation)) {
@@ -13828,7 +13938,7 @@ class CompositeCatalogInterface extends CatalogInterface {
13828
13938
  await this._route(args[0]).schemaDrop(...args);
13829
13939
  }
13830
13940
  async tableCreate(...args) {
13831
- await this._route(args[0]).tableCreate(...args);
13941
+ return await this._route(args[0]).tableCreate(...args);
13832
13942
  }
13833
13943
  async tableDrop(...args) {
13834
13944
  await this._route(args[0]).tableDrop(...args);
@@ -14429,7 +14539,7 @@ import {
14429
14539
  Protocol
14430
14540
  } from "@query-farm/vgi-rpc";
14431
14541
  var VGI_PROTOCOL_NAME = "vgi.v3";
14432
- var VGI_PROTOCOL_VERSION = "3.2.0";
14542
+ var VGI_PROTOCOL_VERSION = "3.3.0";
14433
14543
  function exchangeStream(callbacks) {
14434
14544
  return { kind: "exchange", ...callbacks };
14435
14545
  }
@@ -15163,7 +15273,9 @@ var VGI_V3_METHODS = [
15163
15273
  params: schema2([
15164
15274
  field2("request", binary2(), false)
15165
15275
  ]),
15166
- result: schema2([]),
15276
+ result: schema2([
15277
+ field2("result", binary2(), false)
15278
+ ]),
15167
15279
  doc: "Create a new table."
15168
15280
  },
15169
15281
  {
@@ -15307,23 +15419,6 @@ var VGI_V3_METHODS = [
15307
15419
  ]),
15308
15420
  doc: "Get the list of scan branches for a multi-branch table. Returns `ScanBranchesResult` as IPC bytes."
15309
15421
  },
15310
- {
15311
- name: "catalog_table_scan_function_get",
15312
- key: "catalogTableScanFunctionGet",
15313
- type: "unary",
15314
- params: schema2([
15315
- field2("attach_opaque_data", binary2(), false),
15316
- field2("schema_path", list2(field2("item", utf82(), true)), false),
15317
- field2("name", utf82(), false),
15318
- field2("at_unit", utf82(), true),
15319
- field2("at_value", utf82(), true),
15320
- field2("transaction_opaque_data", binary2(), true)
15321
- ]),
15322
- result: schema2([
15323
- field2("result", binary2(), false)
15324
- ]),
15325
- doc: "Get the scan function for a table. Returns `ScanFunctionResult` as IPC bytes."
15326
- },
15327
15422
  {
15328
15423
  name: "catalog_table_update_function_get",
15329
15424
  key: "catalogTableUpdateFunctionGet",
@@ -15786,9 +15881,6 @@ var UNIMPLEMENTED_VGI_SERVICE = Object.freeze({
15786
15881
  catalogTableScanBranchesGet: async () => {
15787
15882
  throw notImplemented("catalog_table_scan_branches_get");
15788
15883
  },
15789
- catalogTableScanFunctionGet: async () => {
15790
- throw notImplemented("catalog_table_scan_function_get");
15791
- },
15792
15884
  catalogTableUpdateFunctionGet: async () => {
15793
15885
  throw notImplemented("catalog_table_update_function_get");
15794
15886
  },
@@ -18331,8 +18423,11 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
18331
18423
  validateColumnMetadataIpc(toUint8Array(params.columns));
18332
18424
  validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
18333
18425
  requireCreateColumns(toUint8Array(params.columns), definitions);
18334
- await cat.tableCreate(attach, params.schema_path, params.name, toUint8Array(params.columns), params.on_conflict, definitions, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18335
- return {};
18426
+ const created = await cat.tableCreate(attach, params.schema_path, params.name, toUint8Array(params.columns), params.on_conflict, definitions, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18427
+ if (created != null && typeof created !== "boolean") {
18428
+ throw new TypeError(`tableCreate must return a boolean or nothing, got ${typeof created}`);
18429
+ }
18430
+ return wrapResult({ created: created !== false }, CatalogTableCreateResultSchema);
18336
18431
  });
18337
18432
  const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
18338
18433
  const attach = toUint8Array(params.attach_opaque_data);
@@ -18377,11 +18472,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
18377
18472
  const stats = await cat.tableColumnStatisticsGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18378
18473
  return { result: stats?.bytes ?? null };
18379
18474
  });
18380
- const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
18381
- const cat = getCatalog();
18382
- const scanResult = await cat.tableScanFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, params.at_unit, params.at_value, params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined);
18383
- return wrapResult(scanResult, ScanFunctionResultSchema);
18384
- });
18385
18475
  const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
18386
18476
  const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
18387
18477
  const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
@@ -18482,7 +18572,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
18482
18572
  catalogTableCreate,
18483
18573
  catalogTableDrop,
18484
18574
  catalogTableColumnStatisticsGet,
18485
- catalogTableScanFunctionGet,
18486
18575
  catalogTableInsertFunctionGet,
18487
18576
  catalogTableUpdateFunctionGet,
18488
18577
  catalogTableDeleteFunctionGet,
@@ -19612,7 +19701,7 @@ class VgiClient {
19612
19701
  return items[0] ?? null;
19613
19702
  }
19614
19703
  async tableCreate(attachOpaqueData, schemaPath, name, columns, onConflict, constraintDefinitions = [], transactionOpaqueData) {
19615
- await this.rpc.call("catalog_table_create", {
19704
+ const result = await this.rpc.call("catalog_table_create", {
19616
19705
  request: encodeASD(TableCreateRequestSchema, {
19617
19706
  attach_opaque_data: attachOpaqueData,
19618
19707
  schema_path: normalizeSchemaPath(schemaPath),
@@ -19623,6 +19712,9 @@ class VgiClient {
19623
19712
  transaction_opaque_data: transactionOpaqueData ?? null
19624
19713
  })
19625
19714
  });
19715
+ if (!result)
19716
+ throw new VgiClientError("table_create returned null");
19717
+ return unwrapResult(result).created === true;
19626
19718
  }
19627
19719
  async tableDrop(attachOpaqueData, schemaPath, name, ignoreNotFound, cascade, transactionOpaqueData) {
19628
19720
  await this.rpc.call("catalog_table_drop", {
@@ -19634,18 +19726,19 @@ class VgiClient {
19634
19726
  transaction_opaque_data: transactionOpaqueData ?? null
19635
19727
  });
19636
19728
  }
19637
- async tableScanFunctionGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
19638
- const result = await this.rpc.call("catalog_table_scan_function_get", {
19729
+ async tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
19730
+ const result = await this.rpc.call("catalog_table_scan_branches_get", {
19639
19731
  attach_opaque_data: attachOpaqueData,
19640
19732
  schema_path: normalizeSchemaPath(schemaPath),
19641
19733
  name,
19642
19734
  at_unit: atUnit ?? null,
19643
19735
  at_value: atValue ?? null,
19644
- transaction_opaque_data: transactionOpaqueData ?? null
19736
+ transaction_opaque_data: transactionOpaqueData ?? null,
19737
+ pushdown_filters: null
19645
19738
  });
19646
19739
  if (!result)
19647
- throw new VgiClientError("table_scan_function_get returned null");
19648
- return decodeScanFunctionResult(unwrapResult(result));
19740
+ throw new VgiClientError("table_scan_branches_get returned null");
19741
+ return decodeScanBranchesResult(unwrapResult(result));
19649
19742
  }
19650
19743
  async tableCommentSet(attachOpaqueData, schemaPath, name, comment, ignoreNotFound, transactionOpaqueData) {
19651
19744
  await this.rpc.call("catalog_table_comment_set", {
@@ -20393,6 +20486,8 @@ export {
20393
20486
  DateUnit3 as DateUnit,
20394
20487
  DistinctDependence,
20395
20488
  EXCHANGE_STATE_SCHEMA,
20489
+ FUNCTION_VISIBILITY_PUBLIC,
20490
+ FUNCTION_VISIBILITY_TABLE_ONLY,
20396
20491
  FilteringOutputCollector,
20397
20492
  FunctionNotFoundError,
20398
20493
  FunctionRegistry,
@@ -20528,6 +20623,8 @@ export {
20528
20623
  decodeMacroOverload,
20529
20624
  decodeRangeKey,
20530
20625
  decodeRangePartitioning,
20626
+ decodeScanBranchesResult,
20627
+ decodeScanFunctionResult,
20531
20628
  decodeSchemaInfo,
20532
20629
  decodeSqlExpression,
20533
20630
  decodeTableInfo,
@@ -20578,6 +20675,7 @@ export {
20578
20675
  encodeMacroOverload,
20579
20676
  encodeRangeKey,
20580
20677
  encodeRangePartitioning,
20678
+ encodeScanFunctionResult,
20581
20679
  encodeSchemaInfo,
20582
20680
  encodeSqlExpression,
20583
20681
  encodeTableInfo,
@@ -20597,6 +20695,7 @@ export {
20597
20695
  fromBranded,
20598
20696
  fromBrandedBigInt,
20599
20697
  fromBrandedNumber,
20698
+ functionInfoFor,
20600
20699
  storage as functionStorage,
20601
20700
  generatedExpressionMetadata,
20602
20701
  grantKeysFromArgv,
@@ -20719,4 +20818,4 @@ export {
20719
20818
  writeRowsBatch
20720
20819
  };
20721
20820
 
20722
- //# debugId=52476A3C118F9C0764756E2164756E21
20821
+ //# debugId=AC96D7597A143B4C64756E2164756E21