@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
@@ -2288,12 +2288,34 @@ class FunctionStorageSqlite {
2288
2288
  this.dbPath = dbPath ?? getDefaultDbPath();
2289
2289
  const Db = _loadDatabase();
2290
2290
  this._db = new Db(this.dbPath);
2291
- this._db.exec("PRAGMA journal_mode=WAL");
2291
+ this._db.exec(`PRAGMA busy_timeout=${BUSY_TIMEOUT_MS}`);
2292
+ this._setWal();
2292
2293
  this._db.exec("PRAGMA synchronous=NORMAL");
2293
- this._db.exec("PRAGMA busy_timeout=30000");
2294
2294
  this._db.exec("PRAGMA temp_store=MEMORY");
2295
2295
  this._db.exec("PRAGMA cache_size=-65536");
2296
- this._ensureTables();
2296
+ this._db.exec("BEGIN IMMEDIATE");
2297
+ try {
2298
+ this._ensureTables();
2299
+ this._db.exec("COMMIT");
2300
+ } catch (e) {
2301
+ try {
2302
+ this._db.exec("ROLLBACK");
2303
+ } catch {}
2304
+ throw e;
2305
+ }
2306
+ }
2307
+ _setWal() {
2308
+ const deadline = Date.now() + BUSY_TIMEOUT_MS;
2309
+ for (let delay = 5;; delay = Math.min(delay * 2, 100)) {
2310
+ try {
2311
+ this._db.exec("PRAGMA journal_mode=WAL");
2312
+ return;
2313
+ } catch (e) {
2314
+ if (!String(e?.code ?? "").startsWith("SQLITE_BUSY") || Date.now() >= deadline)
2315
+ throw e;
2316
+ Atomics.wait(_SLEEP_CELL, 0, 0, delay);
2317
+ }
2318
+ }
2297
2319
  }
2298
2320
  close() {
2299
2321
  this._db.close();
@@ -2478,7 +2500,7 @@ function getDefaultStorage() {
2478
2500
  function bufferArg(data) {
2479
2501
  return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
2480
2502
  }
2481
- var _BUN_SQLITE_MOD = "bun:sqlite", _NODE_OS_MOD2 = "node:os", _NODE_PATH_MOD2 = "node:path", _NODE_FS_MOD2 = "node:fs", _Database = null, UnknownInvocationError, FrameworkNS, NS_WORKER2, _resolved = null, storage;
2503
+ var _BUN_SQLITE_MOD = "bun:sqlite", _NODE_OS_MOD2 = "node:os", _NODE_PATH_MOD2 = "node:path", _NODE_FS_MOD2 = "node:fs", _Database = null, UnknownInvocationError, FrameworkNS, NS_WORKER2, BUSY_TIMEOUT_MS = 30000, _SLEEP_CELL, _resolved = null, storage;
2482
2504
  var init_storage = __esm(() => {
2483
2505
  UnknownInvocationError = class UnknownInvocationError extends Error {
2484
2506
  constructor(message) {
@@ -2497,6 +2519,7 @@ var init_storage = __esm(() => {
2497
2519
  STREAMING_FINALIZE: textBytes("_vgi/streaming_finalize")
2498
2520
  };
2499
2521
  NS_WORKER2 = new TextEncoder().encode("worker");
2522
+ _SLEEP_CELL = new Int32Array(new SharedArrayBuffer(4));
2500
2523
  storage = new Proxy({}, {
2501
2524
  get(_t, prop, _r) {
2502
2525
  const inst = getDefaultStorage();
@@ -2780,16 +2803,18 @@ class WkbBoundsReader {
2780
2803
  this.offset += 8;
2781
2804
  return value;
2782
2805
  }
2783
- point(littleEndian, dimensions) {
2806
+ point(littleEndian, dimensions, isPointGeometry = false) {
2784
2807
  const x = this.float64(littleEndian);
2785
2808
  const y = this.float64(littleEndian);
2786
- for (let dimension = 2;dimension < dimensions; dimension++)
2787
- this.float64(littleEndian);
2788
- if (Number.isNaN(x) && Number.isNaN(y))
2809
+ let allNaN = Number.isNaN(x) && Number.isNaN(y);
2810
+ for (let dimension = 2;dimension < dimensions; dimension++) {
2811
+ allNaN = Number.isNaN(this.float64(littleEndian)) && allNaN;
2812
+ }
2813
+ if (isPointGeometry && allNaN)
2789
2814
  return null;
2790
- if (!Number.isFinite(x) || !Number.isFinite(y))
2791
- throw new FilterV2Error("WKB coordinate must be finite");
2792
- return { minX: x, minY: y, maxX: x, maxY: y };
2815
+ const [minX, maxX] = Number.isNaN(x) ? [-Infinity, Infinity] : [x, x];
2816
+ const [minY, maxY] = Number.isNaN(y) ? [-Infinity, Infinity] : [y, y];
2817
+ return { minX, minY, maxX, maxY };
2793
2818
  }
2794
2819
  count(littleEndian) {
2795
2820
  const count = this.uint32(littleEndian);
@@ -2841,7 +2866,7 @@ class WkbBoundsReader {
2841
2866
  if (hasSrid)
2842
2867
  this.uint32(littleEndian);
2843
2868
  if (type === 1)
2844
- return this.point(littleEndian, dimensions);
2869
+ return this.point(littleEndian, dimensions, true);
2845
2870
  if (type === 2)
2846
2871
  return this.points(littleEndian, dimensions);
2847
2872
  if (type === 3) {
@@ -3056,14 +3081,16 @@ class PushdownFilters {
3056
3081
  for (const predicate of this.predicates) {
3057
3082
  if (predicate.expression.node === "runtime_filter" && !predicate.expression.supported)
3058
3083
  continue;
3059
- let values;
3060
- try {
3061
- values = Array.from({ length: batch.numRows }, (_, row) => evaluateExpression(predicate.expression, batch, row, this.evaluationContext));
3062
- } catch (error) {
3063
- if (predicate.mode === "advisory")
3064
- continue;
3065
- throw error;
3066
- }
3084
+ const advisory = predicate.mode === "advisory";
3085
+ const values = Array.from({ length: batch.numRows }, (_, row) => {
3086
+ try {
3087
+ return evaluateExpression(predicate.expression, batch, row, this.evaluationContext);
3088
+ } catch (error) {
3089
+ if (advisory)
3090
+ return true;
3091
+ throw error;
3092
+ }
3093
+ });
3067
3094
  for (let row = 0;row < batch.numRows; row++)
3068
3095
  mask[row] &= values[row] === true ? 1 : 0;
3069
3096
  }
@@ -4923,7 +4950,7 @@ import {
4923
4950
  Protocol
4924
4951
  } from "@query-farm/vgi-rpc";
4925
4952
  var VGI_PROTOCOL_NAME = "vgi.v3";
4926
- var VGI_PROTOCOL_VERSION = "3.2.0";
4953
+ var VGI_PROTOCOL_VERSION = "3.3.0";
4927
4954
  function exchangeStream(callbacks) {
4928
4955
  return { kind: "exchange", ...callbacks };
4929
4956
  }
@@ -5657,7 +5684,9 @@ var VGI_V3_METHODS = [
5657
5684
  params: schema2([
5658
5685
  field2("request", binary2(), false)
5659
5686
  ]),
5660
- result: schema2([]),
5687
+ result: schema2([
5688
+ field2("result", binary2(), false)
5689
+ ]),
5661
5690
  doc: "Create a new table."
5662
5691
  },
5663
5692
  {
@@ -5801,23 +5830,6 @@ var VGI_V3_METHODS = [
5801
5830
  ]),
5802
5831
  doc: "Get the list of scan branches for a multi-branch table. Returns `ScanBranchesResult` as IPC bytes."
5803
5832
  },
5804
- {
5805
- name: "catalog_table_scan_function_get",
5806
- key: "catalogTableScanFunctionGet",
5807
- type: "unary",
5808
- params: schema2([
5809
- field2("attach_opaque_data", binary2(), false),
5810
- field2("schema_path", list2(field2("item", utf82(), true)), false),
5811
- field2("name", utf82(), false),
5812
- field2("at_unit", utf82(), true),
5813
- field2("at_value", utf82(), true),
5814
- field2("transaction_opaque_data", binary2(), true)
5815
- ]),
5816
- result: schema2([
5817
- field2("result", binary2(), false)
5818
- ]),
5819
- doc: "Get the scan function for a table. Returns `ScanFunctionResult` as IPC bytes."
5820
- },
5821
5833
  {
5822
5834
  name: "catalog_table_update_function_get",
5823
5835
  key: "catalogTableUpdateFunctionGet",
@@ -6280,9 +6292,6 @@ var UNIMPLEMENTED_VGI_SERVICE = Object.freeze({
6280
6292
  catalogTableScanBranchesGet: async () => {
6281
6293
  throw notImplemented("catalog_table_scan_branches_get");
6282
6294
  },
6283
- catalogTableScanFunctionGet: async () => {
6284
- throw notImplemented("catalog_table_scan_function_get");
6285
- },
6286
6295
  catalogTableUpdateFunctionGet: async () => {
6287
6296
  throw notImplemented("catalog_table_update_function_get");
6288
6297
  },
@@ -6406,7 +6415,7 @@ init_arrow();
6406
6415
 
6407
6416
  // src/generated/vgi-protocol-schemas.ts
6408
6417
  init_arrow();
6409
- var VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
6418
+ var VGI_CATALOG_CONTRACT_HASH = "e0965c93219b6ef6574d82c007c600462594a08085db1242b127ed27e193da0f";
6410
6419
  var CatalogInfoSchema = schema2([
6411
6420
  field2("name", utf82(), false),
6412
6421
  field2("implementation_version", utf82(), true),
@@ -6497,7 +6506,8 @@ var FunctionInfoSchema = schema2([
6497
6506
  field2("input_from_args", bool2(), false),
6498
6507
  field2("input_rows_per_call", int642(), true),
6499
6508
  field2("required_settings", list2(field2("item", utf82(), true)), false),
6500
- field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false)
6509
+ field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false),
6510
+ field2("visibility", utf82(), true)
6501
6511
  ]);
6502
6512
  var MacroInfoSchema = schema2([
6503
6513
  field2("comment", utf82(), true),
@@ -7210,6 +7220,9 @@ var CatalogTableConstraintsApplyResultSchema = schema2([
7210
7220
  field2("definition_revision", binary2(), false),
7211
7221
  field2("constraints", list2(field2("item", binary2(), true)), false)
7212
7222
  ]);
7223
+ var CatalogTableCreateResultSchema = schema2([
7224
+ field2("created", bool2(), false)
7225
+ ]);
7213
7226
  var CatalogTableGetResultSchema = schema2([
7214
7227
  field2("items", list2(field2("item", binary2(), true)), false)
7215
7228
  ]);
@@ -7615,14 +7628,6 @@ var CatalogTableScanBranchesGetParamsSchema = schema2([
7615
7628
  field2("transaction_opaque_data", binary2(), true),
7616
7629
  field2("pushdown_filters", binary2(), true)
7617
7630
  ]);
7618
- var CatalogTableScanFunctionGetParamsSchema = schema2([
7619
- field2("attach_opaque_data", binary2(), false),
7620
- field2("schema_path", list2(field2("item", utf82(), true)), false),
7621
- field2("name", utf82(), false),
7622
- field2("at_unit", utf82(), true),
7623
- field2("at_value", utf82(), true),
7624
- field2("transaction_opaque_data", binary2(), true)
7625
- ]);
7626
7631
  var CatalogTableUpdateFunctionGetParamsSchema = schema2([
7627
7632
  field2("attach_opaque_data", binary2(), false),
7628
7633
  field2("schema_path", list2(field2("item", utf82(), true)), false),
@@ -14419,8 +14424,11 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
14419
14424
  validateColumnMetadataIpc(toUint8Array(params.columns));
14420
14425
  validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
14421
14426
  requireCreateColumns(toUint8Array(params.columns), definitions);
14422
- 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);
14423
- return {};
14427
+ 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);
14428
+ if (created != null && typeof created !== "boolean") {
14429
+ throw new TypeError(`tableCreate must return a boolean or nothing, got ${typeof created}`);
14430
+ }
14431
+ return wrapResult({ created: created !== false }, CatalogTableCreateResultSchema);
14424
14432
  });
14425
14433
  const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
14426
14434
  const attach = toUint8Array(params.attach_opaque_data);
@@ -14465,11 +14473,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
14465
14473
  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);
14466
14474
  return { result: stats?.bytes ?? null };
14467
14475
  });
14468
- const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
14469
- const cat = getCatalog();
14470
- 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);
14471
- return wrapResult(scanResult, ScanFunctionResultSchema);
14472
- });
14473
14476
  const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
14474
14477
  const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
14475
14478
  const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
@@ -14570,7 +14573,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
14570
14573
  catalogTableCreate,
14571
14574
  catalogTableDrop,
14572
14575
  catalogTableColumnStatisticsGet,
14573
- catalogTableScanFunctionGet,
14574
14576
  catalogTableInsertFunctionGet,
14575
14577
  catalogTableUpdateFunctionGet,
14576
14578
  catalogTableDeleteFunctionGet,
@@ -16071,10 +16073,9 @@ function defineRowTransformFunction(config) {
16071
16073
  }
16072
16074
  };
16073
16075
  }
16074
- // src/catalog/read-only.ts
16075
- init_arrow();
16076
-
16077
16076
  // src/catalog/descriptors.ts
16077
+ var FUNCTION_VISIBILITY_PUBLIC = "public";
16078
+ var FUNCTION_VISIBILITY_TABLE_ONLY = "table_only";
16078
16079
  function schemaDescriptorPath(schema) {
16079
16080
  if (schema.path)
16080
16081
  return schema.path;
@@ -16083,6 +16084,9 @@ function schemaDescriptorPath(schema) {
16083
16084
  throw new Error("SchemaDescriptor requires a non-empty path");
16084
16085
  }
16085
16086
 
16087
+ // src/catalog/read-only.ts
16088
+ init_arrow();
16089
+
16086
16090
  // src/metadata/resolve.ts
16087
16091
  init_arrow();
16088
16092
  function arrowTypeToName(type) {
@@ -16281,6 +16285,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16281
16285
  _version = 1;
16282
16286
  _functionListings = new Map;
16283
16287
  _functionInfos = new Map;
16288
+ _builtListings;
16284
16289
  constructor(descriptor, registry, options = {}) {
16285
16290
  super();
16286
16291
  if (descriptor.defaultSchema != null && (descriptor.defaultSchema.length === 0 || descriptor.defaultSchema.includes("\x00"))) {
@@ -16309,12 +16314,18 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16309
16314
  }
16310
16315
  }
16311
16316
  }
16317
+ get _listings() {
16318
+ return (this._builtListings ??= buildFunctionListings(this._descriptor)).listings;
16319
+ }
16320
+ get _listedIn() {
16321
+ return (this._builtListings ??= buildFunctionListings(this._descriptor)).listedIn;
16322
+ }
16323
+ functionVisibility(schema, fn) {
16324
+ return this._listings.get(schema)?.get(fn) ?? null;
16325
+ }
16312
16326
  _schemaForFunction(fn) {
16313
- for (const sch of this._descriptor.schemas ?? []) {
16314
- if ((sch.functions ?? []).includes(fn))
16315
- return schemaDescriptorPath(sch);
16316
- }
16317
- return null;
16327
+ const sch = this._listedIn.get(fn);
16328
+ return sch ? schemaDescriptorPath(sch) : null;
16318
16329
  }
16319
16330
  catalogs() {
16320
16331
  return [this._descriptor.name];
@@ -16409,7 +16420,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16409
16420
  }
16410
16421
  _estimatedObjectCount(s) {
16411
16422
  let scalar = 0, aggregate = 0, table = 0;
16412
- for (const f of s.functions ?? []) {
16423
+ for (const f of this._listings.get(s)?.keys() ?? []) {
16413
16424
  if (f.kind === "scalar")
16414
16425
  scalar++;
16415
16426
  else if (f.kind === "aggregate")
@@ -16578,12 +16589,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16578
16589
  }
16579
16590
  schemaContentsFunctions(attachOpaqueData, path, type, transactionOpaqueData) {
16580
16591
  const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), path));
16581
- if (!schema || !schema.functions)
16592
+ const entries = schema ? this._listings.get(schema) : undefined;
16593
+ if (!schema || !entries || entries.size === 0)
16582
16594
  return [];
16595
+ const listed = [...entries.keys()];
16583
16596
  const kind = functionListingKind(type);
16584
16597
  const canonicalPath = schemaDescriptorPath(schema);
16585
16598
  if (!sameSpelling(path, canonicalPath)) {
16586
- return schema.functions.filter((f) => inListing(f, kind)).map((f) => this._functionToInfo(f, path));
16599
+ return listed.filter((f) => inListing(f, kind)).map((f) => this._functionToInfo(f, path, entries.get(f)));
16587
16600
  }
16588
16601
  let listings = this._functionListings.get(schema);
16589
16602
  if (!listings) {
@@ -16592,7 +16605,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16592
16605
  }
16593
16606
  let listing = listings.get(kind);
16594
16607
  if (!listing) {
16595
- listing = Object.freeze(schema.functions.filter((f) => inListing(f, kind)).map((f) => this._sharedFunctionInfo(schema, f)));
16608
+ listing = Object.freeze(listed.filter((f) => inListing(f, kind)).map((f) => this._sharedFunctionInfo(schema, f)));
16596
16609
  listings.set(kind, listing);
16597
16610
  }
16598
16611
  return listing.slice();
@@ -16605,106 +16618,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16605
16618
  }
16606
16619
  let info = infos.get(f);
16607
16620
  if (!info) {
16608
- info = freezeCatalogItem(structuredClone(this._functionToInfo(f, schemaDescriptorPath(schema))));
16621
+ const visibility = this.functionVisibility(schema, f) ?? FUNCTION_VISIBILITY_PUBLIC;
16622
+ info = freezeCatalogItem(structuredClone(this._functionToInfo(f, schemaDescriptorPath(schema), visibility)));
16609
16623
  infos.set(f, info);
16610
16624
  }
16611
16625
  return info;
16612
16626
  }
16613
- _functionToInfo(f, path) {
16614
- const meta = resolveMetadata(f);
16615
- const argSchema = argumentSpecsToSchema(f.argumentSpecs);
16616
- const argBytes = serializeSchema(argSchema);
16617
- const defaults = f.meta.parameterDefaultValues ?? null;
16618
- if (defaults) {
16619
- if (defaults.numRows !== 1) {
16620
- throw new Error(`parameterDefaultValues must contain exactly one row, got ${defaults.numRows}`);
16621
- }
16622
- let argumentIndex = 0;
16623
- for (const defaultField of defaults.schema.fields) {
16624
- while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
16625
- argumentIndex++;
16626
- }
16627
- if (argumentIndex === argSchema.fields.length) {
16628
- throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
16629
- }
16630
- const argumentField = argSchema.fields[argumentIndex];
16631
- if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
16632
- throw new Error(`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` + `expected ${typeSignature(argumentField.type)}`);
16633
- }
16634
- argumentIndex++;
16635
- }
16636
- }
16637
- const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
16638
- const requiredSecrets = meta.requiredSecrets.map((s) => ({
16639
- secret_type: s.secretType,
16640
- scope: s.scope,
16641
- secret_name: s.secretName
16642
- }));
16643
- const derivedTags = {};
16644
- const tags = { ...derivedTags, ...meta.tags ?? {} };
16645
- return {
16646
- comment: null,
16647
- tags,
16648
- name: f.meta.name,
16649
- schema_path: normalizeSchemaPath(path),
16650
- function_type: meta.functionType.toUpperCase(),
16651
- arguments: argBytes,
16652
- output_schema: outputSchemaBytes,
16653
- parameter_default_values: defaults ? serializeBatch(defaults) : null,
16654
- stability: meta.stability,
16655
- null_handling: meta.nullHandling,
16656
- argument_monotonicity: meta.argumentMonotonicity,
16657
- description: meta.description,
16658
- examples: meta.examples.map((e) => ({
16659
- sql: e.sql,
16660
- description: e.description,
16661
- expected_output: null
16662
- })),
16663
- categories: meta.categories,
16664
- projection_pushdown: meta.projectionPushdown,
16665
- filter_pushdown: meta.filterPushdown,
16666
- sampling_pushdown: meta.samplingPushdown,
16667
- late_materialization: f.kind === "table" && f.meta.lateMaterialization === true ? true : null,
16668
- filter_semantic_profiles: meta.filterSemanticProfiles,
16669
- additional_filter_functions: meta.additionalFilterFunctions.map((value) => ({
16670
- namespace: value.namespace,
16671
- name: value.name,
16672
- version: BigInt(value.version)
16673
- })),
16674
- runtime_filter_algorithms: meta.runtimeFilterAlgorithms.map((value) => ({
16675
- namespace: value.namespace,
16676
- name: value.name,
16677
- version: BigInt(value.version)
16678
- })),
16679
- filter_evaluation_contexts: meta.filterEvaluationContexts.map((value) => ({
16680
- profile: value.profile,
16681
- provider_fingerprint: value.providerFingerprint
16682
- })),
16683
- order_preservation: meta.preservesOrder,
16684
- max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
16685
- supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
16686
- supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
16687
- filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
16688
- supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
16689
- split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
16690
- partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
16691
- order_dependent: meta.orderDependent,
16692
- distinct_dependent: meta.distinctDependent,
16693
- supports_window: false,
16694
- streaming_partitioned: false,
16695
- has_finalize: f.kind === "table_in_out" && f.meta.hasFinalize === true || f.kind === "table_buffering",
16696
- source_order_dependent: f.kind === "table_buffering" && f.meta.sourceOrderDependent === true,
16697
- sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
16698
- requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
16699
- input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
16700
- input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
16701
- required_settings: meta.requiredSettings,
16702
- required_secrets: requiredSecrets.map((s) => ({
16703
- secret_type: s.secret_type,
16704
- scope: s.scope,
16705
- secret_name: s.secret_name
16706
- }))
16707
- };
16627
+ _functionToInfo(f, path, visibility) {
16628
+ return functionInfoFor(f, path, visibility);
16708
16629
  }
16709
16630
  _globalFunctionInfos() {
16710
16631
  const globals = this._descriptor.globalFunctions ?? [];
@@ -17070,6 +16991,104 @@ function sameSpelling(left, right) {
17070
16991
  const b = normalizeSchemaPath(right);
17071
16992
  return a.length === b.length && a.every((part, i) => part === b[i]);
17072
16993
  }
16994
+ function functionInfoFor(f, schemaPath, visibility = FUNCTION_VISIBILITY_PUBLIC) {
16995
+ const path = schemaPath;
16996
+ const meta = resolveMetadata(f);
16997
+ const argSchema = argumentSpecsToSchema(f.argumentSpecs);
16998
+ const argBytes = serializeSchema(argSchema);
16999
+ const defaults = f.meta.parameterDefaultValues ?? null;
17000
+ if (defaults) {
17001
+ if (defaults.numRows !== 1) {
17002
+ throw new Error(`parameterDefaultValues must contain exactly one row, got ${defaults.numRows}`);
17003
+ }
17004
+ let argumentIndex = 0;
17005
+ for (const defaultField of defaults.schema.fields) {
17006
+ while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
17007
+ argumentIndex++;
17008
+ }
17009
+ if (argumentIndex === argSchema.fields.length) {
17010
+ throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
17011
+ }
17012
+ const argumentField = argSchema.fields[argumentIndex];
17013
+ if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
17014
+ throw new Error(`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` + `expected ${typeSignature(argumentField.type)}`);
17015
+ }
17016
+ argumentIndex++;
17017
+ }
17018
+ }
17019
+ const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
17020
+ const requiredSecrets = meta.requiredSecrets.map((s) => ({
17021
+ secret_type: s.secretType,
17022
+ scope: s.scope,
17023
+ secret_name: s.secretName
17024
+ }));
17025
+ const derivedTags = {};
17026
+ const tags = { ...derivedTags, ...meta.tags ?? {} };
17027
+ return {
17028
+ comment: null,
17029
+ tags,
17030
+ name: f.meta.name,
17031
+ schema_path: normalizeSchemaPath(path),
17032
+ function_type: meta.functionType.toUpperCase(),
17033
+ arguments: argBytes,
17034
+ output_schema: outputSchemaBytes,
17035
+ parameter_default_values: defaults ? serializeBatch(defaults) : null,
17036
+ stability: meta.stability,
17037
+ null_handling: meta.nullHandling,
17038
+ argument_monotonicity: meta.argumentMonotonicity,
17039
+ description: meta.description,
17040
+ examples: meta.examples.map((e) => ({
17041
+ sql: e.sql,
17042
+ description: e.description,
17043
+ expected_output: null
17044
+ })),
17045
+ categories: meta.categories,
17046
+ projection_pushdown: meta.projectionPushdown,
17047
+ filter_pushdown: meta.filterPushdown,
17048
+ sampling_pushdown: meta.samplingPushdown,
17049
+ late_materialization: f.kind === "table" && f.meta.lateMaterialization === true ? true : null,
17050
+ filter_semantic_profiles: meta.filterSemanticProfiles,
17051
+ additional_filter_functions: meta.additionalFilterFunctions.map((value) => ({
17052
+ namespace: value.namespace,
17053
+ name: value.name,
17054
+ version: BigInt(value.version)
17055
+ })),
17056
+ runtime_filter_algorithms: meta.runtimeFilterAlgorithms.map((value) => ({
17057
+ namespace: value.namespace,
17058
+ name: value.name,
17059
+ version: BigInt(value.version)
17060
+ })),
17061
+ filter_evaluation_contexts: meta.filterEvaluationContexts.map((value) => ({
17062
+ profile: value.profile,
17063
+ provider_fingerprint: value.providerFingerprint
17064
+ })),
17065
+ order_preservation: meta.preservesOrder,
17066
+ max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
17067
+ supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
17068
+ supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
17069
+ filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
17070
+ supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
17071
+ split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
17072
+ partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
17073
+ order_dependent: meta.orderDependent,
17074
+ distinct_dependent: meta.distinctDependent,
17075
+ supports_window: false,
17076
+ streaming_partitioned: false,
17077
+ has_finalize: f.kind === "table_in_out" && f.meta.hasFinalize === true || f.kind === "table_buffering",
17078
+ source_order_dependent: f.kind === "table_buffering" && f.meta.sourceOrderDependent === true,
17079
+ sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
17080
+ requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
17081
+ input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
17082
+ input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
17083
+ required_settings: meta.requiredSettings,
17084
+ required_secrets: requiredSecrets.map((s) => ({
17085
+ secret_type: s.secret_type,
17086
+ scope: s.scope,
17087
+ secret_name: s.secret_name
17088
+ })),
17089
+ visibility
17090
+ };
17091
+ }
17073
17092
  function writeFunctionOf(table, operation) {
17074
17093
  return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
17075
17094
  }
@@ -17079,7 +17098,59 @@ function validateTableScanPlanning(table) {
17079
17098
  throw new Error(`Table '${table.name}': scanPlanning 'filtered' requires columns and no function; the catalog's ` + "tableScanBranchesPlan supplies the scan per query");
17080
17099
  }
17081
17100
  }
17101
+ function buildFunctionListings(descriptor) {
17102
+ const listings = new Map;
17103
+ const listedIn = new Map;
17104
+ const writeFunctions = new Set;
17105
+ for (const sch of descriptor.schemas ?? []) {
17106
+ for (const tbl of sch.tables ?? []) {
17107
+ for (const op of WRITE_OPERATIONS) {
17108
+ const fn = writeFunctionOf(tbl, op);
17109
+ if (fn)
17110
+ writeFunctions.add(fn);
17111
+ }
17112
+ }
17113
+ }
17114
+ const listingOf = (sch) => {
17115
+ let listing = listings.get(sch);
17116
+ if (!listing)
17117
+ listings.set(sch, listing = new Map);
17118
+ return listing;
17119
+ };
17120
+ for (const sch of descriptor.schemas ?? []) {
17121
+ const listing = listingOf(sch);
17122
+ for (const fn of sch.functions ?? []) {
17123
+ if (!listedIn.has(fn))
17124
+ listedIn.set(fn, sch);
17125
+ listing.set(fn, writeFunctions.has(fn) ? FUNCTION_VISIBILITY_TABLE_ONLY : FUNCTION_VISIBILITY_PUBLIC);
17126
+ }
17127
+ }
17128
+ const declared = new Set(listedIn.keys());
17129
+ for (const sch of descriptor.schemas ?? []) {
17130
+ for (const tbl of sch.tables ?? []) {
17131
+ const named = [
17132
+ [tbl.function, false],
17133
+ ...WRITE_OPERATIONS.map((op) => [writeFunctionOf(tbl, op), true])
17134
+ ];
17135
+ for (const [fn, isWrite] of named) {
17136
+ if (!fn || declared.has(fn))
17137
+ continue;
17138
+ const owner = listedIn.get(fn) ?? sch;
17139
+ if (!listedIn.has(fn))
17140
+ listedIn.set(fn, owner);
17141
+ const listing = listingOf(owner);
17142
+ const visibility = !isWrite && !writeFunctions.has(fn) && tbl.exposeScan === true ? FUNCTION_VISIBILITY_PUBLIC : FUNCTION_VISIBILITY_TABLE_ONLY;
17143
+ if (listing.get(fn) !== FUNCTION_VISIBILITY_PUBLIC)
17144
+ listing.set(fn, visibility);
17145
+ }
17146
+ }
17147
+ }
17148
+ return { listings, listedIn };
17149
+ }
17082
17150
  function validateWritableTable(table) {
17151
+ if (table.exposeScan && !table.function) {
17152
+ throw new Error(`Table '${table.name}': exposeScan requires a scan function (set 'function')`);
17153
+ }
17083
17154
  const modes = validateWriteResultModes(table.writeResultModes ?? {});
17084
17155
  for (const operation of Object.keys(modes)) {
17085
17156
  if (!writeFunctionOf(table, operation)) {
@@ -17238,7 +17309,7 @@ class CompositeCatalogInterface extends CatalogInterface {
17238
17309
  await this._route(args[0]).schemaDrop(...args);
17239
17310
  }
17240
17311
  async tableCreate(...args) {
17241
- await this._route(args[0]).tableCreate(...args);
17312
+ return await this._route(args[0]).tableCreate(...args);
17242
17313
  }
17243
17314
  async tableDrop(...args) {
17244
17315
  await this._route(args[0]).tableDrop(...args);
@@ -17880,4 +17951,4 @@ export {
17880
17951
  validateTableConstraints
17881
17952
  };
17882
17953
 
17883
- //# debugId=35578DCB4B92363164756E2164756E21
17954
+ //# debugId=8B1EF29F9A3EBA6D64756E2164756E21