@query-farm/vgi 0.49.2 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) 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 +265 -170
  16. package/dist/index.js.map +16 -16
  17. package/dist/protocol/dispatch.d.ts +5 -3
  18. package/dist/serve-entry.js +43 -45
  19. package/dist/serve-entry.js.map +9 -9
  20. package/dist/worker-cf-entry.js +221 -154
  21. package/dist/worker-cf-entry.js.map +15 -15
  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/functions/storage.ts +44 -3
  31. package/src/generated/vgi-client.ts +6 -1
  32. package/src/generated/vgi-protocol-schemas.ts +8 -12
  33. package/src/generated/vgi-service.ts +9 -48
  34. package/src/index.core.ts +4 -3
  35. package/src/protocol/dispatch.ts +5 -3
  36. package/src/protocol/handlers/catalog/table.ts +14 -21
  37. 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();
@@ -4927,7 +4950,7 @@ import {
4927
4950
  Protocol
4928
4951
  } from "@query-farm/vgi-rpc";
4929
4952
  var VGI_PROTOCOL_NAME = "vgi.v3";
4930
- var VGI_PROTOCOL_VERSION = "3.2.0";
4953
+ var VGI_PROTOCOL_VERSION = "3.3.0";
4931
4954
  function exchangeStream(callbacks) {
4932
4955
  return { kind: "exchange", ...callbacks };
4933
4956
  }
@@ -5661,7 +5684,9 @@ var VGI_V3_METHODS = [
5661
5684
  params: schema2([
5662
5685
  field2("request", binary2(), false)
5663
5686
  ]),
5664
- result: schema2([]),
5687
+ result: schema2([
5688
+ field2("result", binary2(), false)
5689
+ ]),
5665
5690
  doc: "Create a new table."
5666
5691
  },
5667
5692
  {
@@ -5805,23 +5830,6 @@ var VGI_V3_METHODS = [
5805
5830
  ]),
5806
5831
  doc: "Get the list of scan branches for a multi-branch table. Returns `ScanBranchesResult` as IPC bytes."
5807
5832
  },
5808
- {
5809
- name: "catalog_table_scan_function_get",
5810
- key: "catalogTableScanFunctionGet",
5811
- type: "unary",
5812
- params: schema2([
5813
- field2("attach_opaque_data", binary2(), false),
5814
- field2("schema_path", list2(field2("item", utf82(), true)), false),
5815
- field2("name", utf82(), false),
5816
- field2("at_unit", utf82(), true),
5817
- field2("at_value", utf82(), true),
5818
- field2("transaction_opaque_data", binary2(), true)
5819
- ]),
5820
- result: schema2([
5821
- field2("result", binary2(), false)
5822
- ]),
5823
- doc: "Get the scan function for a table. Returns `ScanFunctionResult` as IPC bytes."
5824
- },
5825
5833
  {
5826
5834
  name: "catalog_table_update_function_get",
5827
5835
  key: "catalogTableUpdateFunctionGet",
@@ -6284,9 +6292,6 @@ var UNIMPLEMENTED_VGI_SERVICE = Object.freeze({
6284
6292
  catalogTableScanBranchesGet: async () => {
6285
6293
  throw notImplemented("catalog_table_scan_branches_get");
6286
6294
  },
6287
- catalogTableScanFunctionGet: async () => {
6288
- throw notImplemented("catalog_table_scan_function_get");
6289
- },
6290
6295
  catalogTableUpdateFunctionGet: async () => {
6291
6296
  throw notImplemented("catalog_table_update_function_get");
6292
6297
  },
@@ -6410,7 +6415,7 @@ init_arrow();
6410
6415
 
6411
6416
  // src/generated/vgi-protocol-schemas.ts
6412
6417
  init_arrow();
6413
- var VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
6418
+ var VGI_CATALOG_CONTRACT_HASH = "e0965c93219b6ef6574d82c007c600462594a08085db1242b127ed27e193da0f";
6414
6419
  var CatalogInfoSchema = schema2([
6415
6420
  field2("name", utf82(), false),
6416
6421
  field2("implementation_version", utf82(), true),
@@ -6501,7 +6506,8 @@ var FunctionInfoSchema = schema2([
6501
6506
  field2("input_from_args", bool2(), false),
6502
6507
  field2("input_rows_per_call", int642(), true),
6503
6508
  field2("required_settings", list2(field2("item", utf82(), true)), false),
6504
- 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)
6505
6511
  ]);
6506
6512
  var MacroInfoSchema = schema2([
6507
6513
  field2("comment", utf82(), true),
@@ -7214,6 +7220,9 @@ var CatalogTableConstraintsApplyResultSchema = schema2([
7214
7220
  field2("definition_revision", binary2(), false),
7215
7221
  field2("constraints", list2(field2("item", binary2(), true)), false)
7216
7222
  ]);
7223
+ var CatalogTableCreateResultSchema = schema2([
7224
+ field2("created", bool2(), false)
7225
+ ]);
7217
7226
  var CatalogTableGetResultSchema = schema2([
7218
7227
  field2("items", list2(field2("item", binary2(), true)), false)
7219
7228
  ]);
@@ -7619,14 +7628,6 @@ var CatalogTableScanBranchesGetParamsSchema = schema2([
7619
7628
  field2("transaction_opaque_data", binary2(), true),
7620
7629
  field2("pushdown_filters", binary2(), true)
7621
7630
  ]);
7622
- var CatalogTableScanFunctionGetParamsSchema = schema2([
7623
- field2("attach_opaque_data", binary2(), false),
7624
- field2("schema_path", list2(field2("item", utf82(), true)), false),
7625
- field2("name", utf82(), false),
7626
- field2("at_unit", utf82(), true),
7627
- field2("at_value", utf82(), true),
7628
- field2("transaction_opaque_data", binary2(), true)
7629
- ]);
7630
7631
  var CatalogTableUpdateFunctionGetParamsSchema = schema2([
7631
7632
  field2("attach_opaque_data", binary2(), false),
7632
7633
  field2("schema_path", list2(field2("item", utf82(), true)), false),
@@ -14423,8 +14424,11 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
14423
14424
  validateColumnMetadataIpc(toUint8Array(params.columns));
14424
14425
  validateColumnExpressionsIpc(toUint8Array(params.columns), params.schema_path);
14425
14426
  requireCreateColumns(toUint8Array(params.columns), definitions);
14426
- 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);
14427
- 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);
14428
14432
  });
14429
14433
  const catalogTableConstraintsApply = catalogHandler(keys, async (params) => {
14430
14434
  const attach = toUint8Array(params.attach_opaque_data);
@@ -14469,11 +14473,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
14469
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);
14470
14474
  return { result: stats?.bytes ?? null };
14471
14475
  });
14472
- const catalogTableScanFunctionGet = catalogHandler(keys, async (params) => {
14473
- const cat = getCatalog();
14474
- 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);
14475
- return wrapResult(scanResult, ScanFunctionResultSchema);
14476
- });
14477
14476
  const optionalTx = (params) => params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
14478
14477
  const catalogTableInsertFunctionGet = catalogHandler(keys, async (params) => {
14479
14478
  const result = await getCatalog().tableInsertFunctionGet(toUint8Array(params.attach_opaque_data), params.schema_path, params.name, optionalTx(params), params.writable_branch_function_name ?? null);
@@ -14574,7 +14573,6 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
14574
14573
  catalogTableCreate,
14575
14574
  catalogTableDrop,
14576
14575
  catalogTableColumnStatisticsGet,
14577
- catalogTableScanFunctionGet,
14578
14576
  catalogTableInsertFunctionGet,
14579
14577
  catalogTableUpdateFunctionGet,
14580
14578
  catalogTableDeleteFunctionGet,
@@ -16075,10 +16073,9 @@ function defineRowTransformFunction(config) {
16075
16073
  }
16076
16074
  };
16077
16075
  }
16078
- // src/catalog/read-only.ts
16079
- init_arrow();
16080
-
16081
16076
  // src/catalog/descriptors.ts
16077
+ var FUNCTION_VISIBILITY_PUBLIC = "public";
16078
+ var FUNCTION_VISIBILITY_TABLE_ONLY = "table_only";
16082
16079
  function schemaDescriptorPath(schema) {
16083
16080
  if (schema.path)
16084
16081
  return schema.path;
@@ -16087,6 +16084,9 @@ function schemaDescriptorPath(schema) {
16087
16084
  throw new Error("SchemaDescriptor requires a non-empty path");
16088
16085
  }
16089
16086
 
16087
+ // src/catalog/read-only.ts
16088
+ init_arrow();
16089
+
16090
16090
  // src/metadata/resolve.ts
16091
16091
  init_arrow();
16092
16092
  function arrowTypeToName(type) {
@@ -16285,6 +16285,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16285
16285
  _version = 1;
16286
16286
  _functionListings = new Map;
16287
16287
  _functionInfos = new Map;
16288
+ _builtListings;
16288
16289
  constructor(descriptor, registry, options = {}) {
16289
16290
  super();
16290
16291
  if (descriptor.defaultSchema != null && (descriptor.defaultSchema.length === 0 || descriptor.defaultSchema.includes("\x00"))) {
@@ -16313,12 +16314,18 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16313
16314
  }
16314
16315
  }
16315
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
+ }
16316
16326
  _schemaForFunction(fn) {
16317
- for (const sch of this._descriptor.schemas ?? []) {
16318
- if ((sch.functions ?? []).includes(fn))
16319
- return schemaDescriptorPath(sch);
16320
- }
16321
- return null;
16327
+ const sch = this._listedIn.get(fn);
16328
+ return sch ? schemaDescriptorPath(sch) : null;
16322
16329
  }
16323
16330
  catalogs() {
16324
16331
  return [this._descriptor.name];
@@ -16413,7 +16420,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16413
16420
  }
16414
16421
  _estimatedObjectCount(s) {
16415
16422
  let scalar = 0, aggregate = 0, table = 0;
16416
- for (const f of s.functions ?? []) {
16423
+ for (const f of this._listings.get(s)?.keys() ?? []) {
16417
16424
  if (f.kind === "scalar")
16418
16425
  scalar++;
16419
16426
  else if (f.kind === "aggregate")
@@ -16582,12 +16589,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16582
16589
  }
16583
16590
  schemaContentsFunctions(attachOpaqueData, path, type, transactionOpaqueData) {
16584
16591
  const schema = this._descriptor.schemas.find((s) => schemaPathsEqual(schemaDescriptorPath(s), path));
16585
- if (!schema || !schema.functions)
16592
+ const entries = schema ? this._listings.get(schema) : undefined;
16593
+ if (!schema || !entries || entries.size === 0)
16586
16594
  return [];
16595
+ const listed = [...entries.keys()];
16587
16596
  const kind = functionListingKind(type);
16588
16597
  const canonicalPath = schemaDescriptorPath(schema);
16589
16598
  if (!sameSpelling(path, canonicalPath)) {
16590
- 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)));
16591
16600
  }
16592
16601
  let listings = this._functionListings.get(schema);
16593
16602
  if (!listings) {
@@ -16596,7 +16605,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16596
16605
  }
16597
16606
  let listing = listings.get(kind);
16598
16607
  if (!listing) {
16599
- 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)));
16600
16609
  listings.set(kind, listing);
16601
16610
  }
16602
16611
  return listing.slice();
@@ -16609,106 +16618,14 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
16609
16618
  }
16610
16619
  let info = infos.get(f);
16611
16620
  if (!info) {
16612
- 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)));
16613
16623
  infos.set(f, info);
16614
16624
  }
16615
16625
  return info;
16616
16626
  }
16617
- _functionToInfo(f, path) {
16618
- const meta = resolveMetadata(f);
16619
- const argSchema = argumentSpecsToSchema(f.argumentSpecs);
16620
- const argBytes = serializeSchema(argSchema);
16621
- const defaults = f.meta.parameterDefaultValues ?? null;
16622
- if (defaults) {
16623
- if (defaults.numRows !== 1) {
16624
- throw new Error(`parameterDefaultValues must contain exactly one row, got ${defaults.numRows}`);
16625
- }
16626
- let argumentIndex = 0;
16627
- for (const defaultField of defaults.schema.fields) {
16628
- while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex].name !== defaultField.name) {
16629
- argumentIndex++;
16630
- }
16631
- if (argumentIndex === argSchema.fields.length) {
16632
- throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
16633
- }
16634
- const argumentField = argSchema.fields[argumentIndex];
16635
- if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
16636
- throw new Error(`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` + `expected ${typeSignature(argumentField.type)}`);
16637
- }
16638
- argumentIndex++;
16639
- }
16640
- }
16641
- const outputSchemaBytes = serializeSchema(f.defaultOutputSchema ?? schema2([]));
16642
- const requiredSecrets = meta.requiredSecrets.map((s) => ({
16643
- secret_type: s.secretType,
16644
- scope: s.scope,
16645
- secret_name: s.secretName
16646
- }));
16647
- const derivedTags = {};
16648
- const tags = { ...derivedTags, ...meta.tags ?? {} };
16649
- return {
16650
- comment: null,
16651
- tags,
16652
- name: f.meta.name,
16653
- schema_path: normalizeSchemaPath(path),
16654
- function_type: meta.functionType.toUpperCase(),
16655
- arguments: argBytes,
16656
- output_schema: outputSchemaBytes,
16657
- parameter_default_values: defaults ? serializeBatch(defaults) : null,
16658
- stability: meta.stability,
16659
- null_handling: meta.nullHandling,
16660
- argument_monotonicity: meta.argumentMonotonicity,
16661
- description: meta.description,
16662
- examples: meta.examples.map((e) => ({
16663
- sql: e.sql,
16664
- description: e.description,
16665
- expected_output: null
16666
- })),
16667
- categories: meta.categories,
16668
- projection_pushdown: meta.projectionPushdown,
16669
- filter_pushdown: meta.filterPushdown,
16670
- sampling_pushdown: meta.samplingPushdown,
16671
- late_materialization: f.kind === "table" && f.meta.lateMaterialization === true ? true : null,
16672
- filter_semantic_profiles: meta.filterSemanticProfiles,
16673
- additional_filter_functions: meta.additionalFilterFunctions.map((value) => ({
16674
- namespace: value.namespace,
16675
- name: value.name,
16676
- version: BigInt(value.version)
16677
- })),
16678
- runtime_filter_algorithms: meta.runtimeFilterAlgorithms.map((value) => ({
16679
- namespace: value.namespace,
16680
- name: value.name,
16681
- version: BigInt(value.version)
16682
- })),
16683
- filter_evaluation_contexts: meta.filterEvaluationContexts.map((value) => ({
16684
- profile: value.profile,
16685
- provider_fingerprint: value.providerFingerprint
16686
- })),
16687
- order_preservation: meta.preservesOrder,
16688
- max_workers: meta.maxWorkers ?? DEFAULT_MAX_WORKERS,
16689
- supports_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true || f.kind === "table" && f.meta.supportsBatchIndex === true,
16690
- supports_splits: f.kind === "table" && f.meta.supportsSplits === true,
16691
- filters_exactly_applied: f.kind === "table" && f.meta.filtersExactlyApplied === true,
16692
- supports_positions: f.kind === "table" && f.meta.supportsPositions === true,
16693
- split_token_ttl_seconds: f.kind === "table" ? f.meta.splitTokenTtlSeconds ?? null : null,
16694
- partition_kind: f.kind === "table" && f.meta.partitionKind ? f.meta.partitionKind : "NOT_PARTITIONED",
16695
- order_dependent: meta.orderDependent,
16696
- distinct_dependent: meta.distinctDependent,
16697
- supports_window: false,
16698
- streaming_partitioned: false,
16699
- has_finalize: f.kind === "table_in_out" && f.meta.hasFinalize === true || f.kind === "table_buffering",
16700
- source_order_dependent: f.kind === "table_buffering" && f.meta.sourceOrderDependent === true,
16701
- sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
16702
- requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
16703
- input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
16704
- input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
16705
- required_settings: meta.requiredSettings,
16706
- required_secrets: requiredSecrets.map((s) => ({
16707
- secret_type: s.secret_type,
16708
- scope: s.scope,
16709
- secret_name: s.secret_name
16710
- }))
16711
- };
16627
+ _functionToInfo(f, path, visibility) {
16628
+ return functionInfoFor(f, path, visibility);
16712
16629
  }
16713
16630
  _globalFunctionInfos() {
16714
16631
  const globals = this._descriptor.globalFunctions ?? [];
@@ -17074,6 +16991,104 @@ function sameSpelling(left, right) {
17074
16991
  const b = normalizeSchemaPath(right);
17075
16992
  return a.length === b.length && a.every((part, i) => part === b[i]);
17076
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
+ }
17077
17092
  function writeFunctionOf(table, operation) {
17078
17093
  return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
17079
17094
  }
@@ -17083,7 +17098,59 @@ function validateTableScanPlanning(table) {
17083
17098
  throw new Error(`Table '${table.name}': scanPlanning 'filtered' requires columns and no function; the catalog's ` + "tableScanBranchesPlan supplies the scan per query");
17084
17099
  }
17085
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
+ }
17086
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
+ }
17087
17154
  const modes = validateWriteResultModes(table.writeResultModes ?? {});
17088
17155
  for (const operation of Object.keys(modes)) {
17089
17156
  if (!writeFunctionOf(table, operation)) {
@@ -17242,7 +17309,7 @@ class CompositeCatalogInterface extends CatalogInterface {
17242
17309
  await this._route(args[0]).schemaDrop(...args);
17243
17310
  }
17244
17311
  async tableCreate(...args) {
17245
- await this._route(args[0]).tableCreate(...args);
17312
+ return await this._route(args[0]).tableCreate(...args);
17246
17313
  }
17247
17314
  async tableDrop(...args) {
17248
17315
  await this._route(args[0]).tableDrop(...args);
@@ -17884,4 +17951,4 @@ export {
17884
17951
  validateTableConstraints
17885
17952
  };
17886
17953
 
17887
- //# debugId=8D435BE08315C5EF64756E2164756E21
17954
+ //# debugId=8B1EF29F9A3EBA6D64756E2164756E21