@query-farm/vgi 0.20.0 → 0.22.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 (54) hide show
  1. package/dist/arrow/impl-arrowjs/index.d.ts +7 -0
  2. package/dist/arrow/impl-flechette/arrowjs-shape.d.ts +16 -0
  3. package/dist/arrow/impl-flechette/compat.d.ts +22 -0
  4. package/dist/arrow/impl-flechette/index.d.ts +2 -0
  5. package/dist/arrow/impl-flechette/ipc.d.ts +1 -1
  6. package/dist/arrow/index.d.ts +2 -2
  7. package/dist/arrow/predicates.d.ts +16 -0
  8. package/dist/cache-control.d.ts +33 -0
  9. package/dist/catalog/composite.d.ts +2 -0
  10. package/dist/catalog/interface.d.ts +11 -0
  11. package/dist/client-entry.js +9 -3
  12. package/dist/client-entry.js.map +7 -7
  13. package/dist/functions/registry.d.ts +31 -0
  14. package/dist/functions/scalar.d.ts +7 -3
  15. package/dist/generated/vgi-client.d.ts +16 -0
  16. package/dist/index.core.d.ts +2 -2
  17. package/dist/index.js +175 -19
  18. package/dist/index.js.map +19 -19
  19. package/dist/protocol/handlers/function.d.ts +8 -0
  20. package/dist/protocol/handlers/shared.d.ts +4 -0
  21. package/dist/protocol/types.d.ts +8 -0
  22. package/dist/serve-entry.js +40 -13
  23. package/dist/serve-entry.js.map +10 -10
  24. package/dist/util/arrow/index.d.ts +1 -1
  25. package/dist/worker-cf-entry.js +167 -17
  26. package/dist/worker-cf-entry.js.map +17 -17
  27. package/dist/worker.d.ts +9 -0
  28. package/package.json +5 -5
  29. package/src/arrow/impl-arrowjs/index.ts +10 -0
  30. package/src/arrow/impl-flechette/arrowjs-shape.ts +78 -0
  31. package/src/arrow/impl-flechette/canonical.ts +19 -0
  32. package/src/arrow/impl-flechette/compat.ts +254 -0
  33. package/src/arrow/impl-flechette/empty.ts +5 -1
  34. package/src/arrow/impl-flechette/index.ts +8 -0
  35. package/src/arrow/impl-flechette/ipc.ts +72 -6
  36. package/src/arrow/impl-flechette/normalize-type.ts +10 -2
  37. package/src/arrow/impl-flechette/schema.ts +13 -9
  38. package/src/arrow/index.ts +3 -0
  39. package/src/arrow/predicates.ts +59 -0
  40. package/src/cache-control.ts +35 -0
  41. package/src/catalog/composite.ts +9 -0
  42. package/src/catalog/interface.ts +15 -0
  43. package/src/catalog/read-only.ts +13 -0
  44. package/src/functions/registry.ts +127 -5
  45. package/src/functions/scalar.ts +10 -5
  46. package/src/generated/vgi-client.ts +17 -1
  47. package/src/index.core.ts +4 -0
  48. package/src/protocol/dispatch.ts +1 -0
  49. package/src/protocol/handlers/function.ts +38 -9
  50. package/src/protocol/handlers/shared.ts +25 -1
  51. package/src/protocol/serializers/bind.ts +7 -0
  52. package/src/protocol/types.ts +8 -0
  53. package/src/util/arrow/index.ts +1 -0
  54. package/src/worker.ts +15 -1
@@ -5,11 +5,42 @@ export interface OverloadContext {
5
5
  arguments?: Arguments;
6
6
  inputSchema?: VgiSchema | null;
7
7
  isScalar?: boolean;
8
+ /**
9
+ * Catalog schema that declares the function, from `BindRequest.schema_name`.
10
+ * A worker may register the same name in more than one schema, so the bare
11
+ * name is not a unique key. When set, resolution is scoped to that schema and
12
+ * never falls back to another one; when absent, every schema is searched.
13
+ */
14
+ schemaName?: string | null;
15
+ /**
16
+ * Catalog that owns the function, resolved from the bind's
17
+ * `attach_opaque_data`. Two catalogs served by one worker may each declare
18
+ * the same schema *and* function name, in which case only the catalog tells
19
+ * them apart. Absent for calls with no attachment.
20
+ */
21
+ catalogName?: string | null;
8
22
  }
9
23
  export declare class FunctionRegistry {
10
24
  private _functions;
25
+ private _bySchema;
26
+ private _byCatalog;
11
27
  register(func: VgiFunction): void;
28
+ /**
29
+ * Record that `func` is declared in `schemaName`, in addition to the flat
30
+ * by-name index. Idempotent, and independent of `register()` so a function
31
+ * reachable from several schemas (e.g. a scan function referenced by tables in
32
+ * more than one schema) resolves from any of them.
33
+ */
34
+ registerInSchema(func: VgiFunction, schemaName: string, catalogName?: string): void;
35
+ /** Schemas that declare `functionName`, sorted — for error messages. */
36
+ schemasFor(functionName: string): string[];
12
37
  get(name: string, context?: OverloadContext): VgiFunction;
38
+ /**
39
+ * Pick one function from an already-scoped candidate list, by argument shape
40
+ * and types. Scoping (catalog / schema) happens in `get()`; by the time this
41
+ * runs, every candidate is a legitimate overload of the same name.
42
+ */
43
+ private _disambiguate;
13
44
  has(name: string): boolean;
14
45
  names(): string[];
15
46
  all(): VgiFunction[];
@@ -112,10 +112,14 @@ export interface ScalarFunctionConfig<P extends Record<string, VgiDataType> = Re
112
112
  /**
113
113
  * Result-cache opt-in: when set, this CacheControl's `vgi.cache.*` metadata
114
114
  * rides every output batch's custom metadata (per-batch — NOT the schema,
115
- * which the IPC stream fixes at open), so the extension can memoize the
116
- * scalar's output per distinct input value. A pure, deterministic scalar
117
- * only — advertising this on a non-pure scalar serves stale rows. Mirrors
115
+ * which the IPC stream fixes at open). A pure, deterministic scalar only —
116
+ * advertising this on a non-pure scalar serves stale rows. Mirrors
118
117
  * vgi-python's `ScalarFunction.CACHE_CONTROL`.
118
+ *
119
+ * Per-VALUE memoization (the extension remembering one output per distinct
120
+ * input value) additionally requires `perValue: true`, which is off by
121
+ * default because a memo serve only beats a worker call when the call is
122
+ * expensive — see {@link CacheControl.perValue}.
119
123
  */
120
124
  cacheControl?: CacheControl;
121
125
  }
@@ -141,6 +141,7 @@ export interface AggregateBindRequest {
141
141
  settings?: /** @record-batch */ Uint8Array | null;
142
142
  secrets?: /** @record-batch */ Uint8Array | null;
143
143
  attach_opaque_data?: Uint8Array | null;
144
+ schema_name?: string | null;
144
145
  }
145
146
  export interface AggregateBindResponse {
146
147
  output_schema: Uint8Array;
@@ -151,6 +152,7 @@ export interface AggregateCombineRequest {
151
152
  execution_id: Uint8Array;
152
153
  merge_batch: Uint8Array;
153
154
  attach_opaque_data?: Uint8Array | null;
155
+ schema_name?: string | null;
154
156
  }
155
157
  export interface AggregateCombineResponse {
156
158
  }
@@ -159,6 +161,7 @@ export interface AggregateDestructorRequest {
159
161
  execution_id: Uint8Array;
160
162
  group_ids_batch: Uint8Array;
161
163
  attach_opaque_data?: Uint8Array | null;
164
+ schema_name?: string | null;
162
165
  }
163
166
  export interface AggregateDestructorResponse {
164
167
  }
@@ -168,6 +171,7 @@ export interface AggregateFinalizeRequest {
168
171
  group_ids_batch: Uint8Array;
169
172
  output_schema: Uint8Array;
170
173
  attach_opaque_data?: Uint8Array | null;
174
+ schema_name?: string | null;
171
175
  }
172
176
  export interface AggregateFinalizeResponse {
173
177
  result_batch: Uint8Array;
@@ -177,6 +181,7 @@ export interface AggregateStreamingChunkRequest {
177
181
  execution_id: Uint8Array;
178
182
  input_batch: Uint8Array;
179
183
  attach_opaque_data?: Uint8Array | null;
184
+ schema_name?: string | null;
180
185
  }
181
186
  export interface AggregateStreamingChunkResponse {
182
187
  result_batch: Uint8Array;
@@ -185,6 +190,7 @@ export interface AggregateStreamingCloseRequest {
185
190
  function_name: string;
186
191
  execution_id: Uint8Array;
187
192
  attach_opaque_data?: Uint8Array | null;
193
+ schema_name?: string | null;
188
194
  }
189
195
  export interface AggregateStreamingCloseResponse {
190
196
  }
@@ -198,6 +204,7 @@ export interface AggregateStreamingOpenRequest {
198
204
  settings?: /** @record-batch */ Uint8Array | null;
199
205
  secrets?: /** @record-batch */ Uint8Array | null;
200
206
  attach_opaque_data?: Uint8Array | null;
207
+ schema_name?: string | null;
201
208
  }
202
209
  export interface AggregateStreamingOpenResponse {
203
210
  execution_id: Uint8Array;
@@ -207,6 +214,7 @@ export interface AggregateUpdateRequest {
207
214
  execution_id: Uint8Array;
208
215
  input_batch: Uint8Array;
209
216
  attach_opaque_data?: Uint8Array | null;
217
+ schema_name?: string | null;
210
218
  }
211
219
  export interface AggregateUpdateResponse {
212
220
  }
@@ -218,6 +226,7 @@ export interface AggregateWindowRequest {
218
226
  frame_starts: number[];
219
227
  frame_ends: number[];
220
228
  attach_opaque_data?: Uint8Array | null;
229
+ schema_name?: string | null;
221
230
  }
222
231
  export interface AggregateWindowResponse {
223
232
  result_batch: Uint8Array;
@@ -232,6 +241,7 @@ export interface AggregateWindowBatchRequest {
232
241
  frame_starts: number[];
233
242
  frame_ends: number[];
234
243
  attach_opaque_data?: Uint8Array | null;
244
+ schema_name?: string | null;
235
245
  }
236
246
  export interface AggregateWindowBatchResponse {
237
247
  result_batch: Uint8Array;
@@ -241,6 +251,7 @@ export interface AggregateWindowDestructorRequest {
241
251
  execution_id: Uint8Array;
242
252
  partition_id: number;
243
253
  attach_opaque_data?: Uint8Array | null;
254
+ schema_name?: string | null;
244
255
  }
245
256
  export interface AggregateWindowDestructorResponse {
246
257
  }
@@ -255,6 +266,7 @@ export interface AggregateWindowInitRequest {
255
266
  frame_stats: Uint8Array;
256
267
  all_valid: Uint8Array;
257
268
  attach_opaque_data?: Uint8Array | null;
269
+ schema_name?: string | null;
258
270
  }
259
271
  export interface AggregateWindowInitResponse {
260
272
  }
@@ -281,6 +293,7 @@ export interface BindRequest {
281
293
  at_value?: string | null;
282
294
  copy_from?: CopyFromContext | null;
283
295
  copy_to?: CopyToContext | null;
296
+ schema_name?: string | null;
284
297
  }
285
298
  export interface BindResponse {
286
299
  output_schema: Uint8Array;
@@ -409,6 +422,7 @@ export interface TableBufferingCombineRequest {
409
422
  state_ids: Uint8Array[];
410
423
  attach_opaque_data?: Uint8Array | null;
411
424
  transaction_id?: Uint8Array | null;
425
+ schema_name?: string | null;
412
426
  }
413
427
  export interface TableBufferingCombineResponse {
414
428
  finalize_state_ids: Uint8Array[];
@@ -418,6 +432,7 @@ export interface TableBufferingDestructorRequest {
418
432
  execution_id: Uint8Array;
419
433
  attach_opaque_data?: Uint8Array | null;
420
434
  transaction_id?: Uint8Array | null;
435
+ schema_name?: string | null;
421
436
  }
422
437
  export interface TableBufferingDestructorResponse {
423
438
  }
@@ -428,6 +443,7 @@ export interface TableBufferingProcessRequest {
428
443
  attach_opaque_data?: Uint8Array | null;
429
444
  transaction_id?: Uint8Array | null;
430
445
  batch_index?: number | null;
446
+ schema_name?: string | null;
431
447
  }
432
448
  export interface TableBufferingProcessResponse {
433
449
  state_id: Uint8Array;
@@ -1,4 +1,4 @@
1
- export { CACHE_ETAG_KEY, CACHE_EXPIRES_KEY, CACHE_IF_MODIFIED_SINCE_KEY, CACHE_IF_NONE_MATCH_KEY, CACHE_LAST_MODIFIED_KEY, CACHE_NO_STORE_KEY, CACHE_NOT_MODIFIED_KEY, CACHE_REVALIDATABLE_KEY, CACHE_SCOPE_CATALOG, CACHE_SCOPE_KEY, CACHE_SCOPE_TRANSACTION, CACHE_STALE_IF_ERROR_KEY, CACHE_STALE_WHILE_REVALIDATE_KEY, CACHE_TTL_KEY, type CacheControl, cacheControlMetadata, type CacheScope, } from "./cache-control.js";
1
+ export { CACHE_ETAG_KEY, CACHE_EXPIRES_KEY, CACHE_IF_MODIFIED_SINCE_KEY, CACHE_IF_NONE_MATCH_KEY, CACHE_LAST_MODIFIED_KEY, CACHE_NO_STORE_KEY, CACHE_NOT_MODIFIED_KEY, CACHE_PARTITION_SCOPE_KEY, CACHE_PER_VALUE_KEY, CACHE_REVALIDATABLE_KEY, CACHE_SCOPE_CATALOG, CACHE_SCOPE_KEY, CACHE_SCOPE_TRANSACTION, CACHE_STALE_IF_ERROR_KEY, CACHE_STALE_WHILE_REVALIDATE_KEY, CACHE_TTL_KEY, type CacheControl, cacheControlMetadata, type CacheScope, } from "./cache-control.js";
2
2
  export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParameters, type ScalarParameterDef } from "./functions/scalar.js";
3
3
  export { defineTableFunction, type TableFunctionConfig, type TableBindParams, type TableProcessParams } from "./functions/table.js";
4
4
  export { defineAggregate, GROUP_COLUMN_NAME, type AggregateFunctionConfig, type AggregateBindParams, type AggregateUpdateParams, type AggregateFinalizeParams, } from "./functions/aggregate.js";
@@ -32,7 +32,7 @@ export { toUint8Array } from "./util/bytes.js";
32
32
  export { iterRows, batchFromRows, batchFromColumns, emptyBatch, filterBatch, projectSchema, projectBatch, batchToScalarDict, batchToSecretDict, safeNumber, } from "./util/arrow/index.js";
33
33
  export { type SecretFields, type SecretsDict, secretType, secretsOfType, secretForScope, secretForScopeOfType, } from "./secrets/helpers.js";
34
34
  export { serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, } from "./util/arrow/index.js";
35
- export { schema, field, nullType, int8, int16, int64, uint8, uint16, uint32, uint64, float16, float64, utf8, binary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, timestampSeconds, timestampMillis, timestampMicros, timestampNanos, durationSeconds, durationMillis, durationMicros, durationNanos, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, codecFor, asDate32, asDate64Ms, asTime32S, asTime32Ms, asTime64Us, asTime64Ns, asTimestampSeconds, asTimestampMillis, asTimestampMicros, asTimestampNanos, asDurationSeconds, asDurationMillis, asDurationMicros, asDurationNanos, asUnscaledDecimal, asInt64, asUint64, fromBranded, fromBrandedNumber, fromBrandedBigInt, TypeId, isNull, isInt, isFloat, isBinary, isUtf8, isBool, isDecimal, isDate, isTime, isTimestamp, isInterval, isList, isStruct, isUnion, isFixedSizeBinary, isFixedSizeList, isMap, isDuration, isDictionary, isBatch, readCanonicalValue, columnFromArray, decodeDictValue, backend, } from "./arrow/index.js";
35
+ export { schema, field, nullType, int8, int16, int64, uint8, uint16, uint32, uint64, float16, float64, utf8, binary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, timestampSeconds, timestampMillis, timestampMicros, timestampNanos, durationSeconds, durationMillis, durationMicros, durationNanos, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, codecFor, asDate32, asDate64Ms, asTime32S, asTime32Ms, asTime64Us, asTime64Ns, asTimestampSeconds, asTimestampMillis, asTimestampMicros, asTimestampNanos, asDurationSeconds, asDurationMillis, asDurationMicros, asDurationNanos, asUnscaledDecimal, asInt64, asUint64, fromBranded, fromBrandedNumber, fromBrandedBigInt, TypeId, isNull, isInt, isFloat, isBinary, isUtf8, isBool, isDecimal, isDate, isTime, isTimestamp, isInterval, isList, isStruct, isUnion, isFixedSizeBinary, isFixedSizeList, isMap, isDuration, isDictionary, isBatch, typeSignature, readCanonicalValue, columnFromArray, decodeDictValue, backend, adoptArrowJsShape, } from "./arrow/index.js";
36
36
  export type { VgiTypeId, VgiDataType, VgiField, VgiSchema, VgiColumn, VgiColumnData, VgiBatch, VgiBackendInfo, TaggedUnion, NullDescriptor, BoolType, IntType, Int8Type, Int16Type, Int32Type, Int64Type, Uint8Type, Uint16Type, Uint32Type, Uint64Type, FloatType, Utf8Type, LargeUtf8Type, BinaryType, LargeBinaryType, FixedSizeBinaryType, DecimalType, Date32Type, Date64Type, Time32Type, Time64Type, TimestampType, DurationType, IntervalType, ListType, FixedSizeListType, StructType, MapType, DictionaryType, UnionType, TypedField, TUnit, RichValue, RawValue, ValueFor, Repr, Codec, Branded, Date32, Date64Ms, Time32S, Time32Ms, Time64Us, Time64Ns, TimestampSeconds, TimestampMillis, TimestampMicros, TimestampNanos, DurationSeconds, DurationMillis, DurationMicros, DurationNanos, UnscaledDecimal, Int64Raw, Uint64Raw, } from "./arrow/index.js";
37
37
  export type { ScalarComputeRow, ScalarOutputValue, ScalarComputeResult } from "./functions/scalar.js";
38
38
  export { type FunctionStorage, FunctionStorageSqlite, BoundStorage, UnknownInvocationError, resolveStorageFromEnv, setStorage, storage as functionStorage, } from "./functions/storage.js";
package/dist/index.js CHANGED
@@ -95,6 +95,42 @@ function isDuration(t) {
95
95
  function isDictionary(t) {
96
96
  return t.typeId === TypeId.Dictionary;
97
97
  }
98
+ function typeSignature(t) {
99
+ if (t == null)
100
+ return "null";
101
+ const a = t;
102
+ const kids = () => Array.isArray(a.children) ? a.children.map((c) => `${c?.name ?? ""}:${typeSignature(c?.type ?? c)}`).join(",") : "";
103
+ switch (t.typeId) {
104
+ case TypeId.Int:
105
+ return `int${a.bitWidth}${a.isSigned ?? a.signed ?? true ? "" : "u"}`;
106
+ case TypeId.Float:
107
+ return `float${a.precision}`;
108
+ case TypeId.Decimal:
109
+ return `decimal${a.bitWidth ?? 128}(${a.precision},${a.scale})`;
110
+ case TypeId.Date:
111
+ case TypeId.Time:
112
+ case TypeId.Duration:
113
+ return `${t.typeId}[${a.unit}]`;
114
+ case TypeId.Timestamp:
115
+ return `ts[${a.unit},${a.timezone ?? ""}]`;
116
+ case TypeId.Interval:
117
+ return `iv[${a.unit}]`;
118
+ case TypeId.FixedSizeBinary:
119
+ return `fsb(${a.byteWidth ?? a.stride})`;
120
+ case TypeId.FixedSizeList:
121
+ return `fsl(${a.listSize ?? a.stride},${kids()})`;
122
+ case TypeId.List:
123
+ case TypeId.Struct:
124
+ case TypeId.Map:
125
+ return `${t.typeId}<${kids()}>`;
126
+ case TypeId.Union:
127
+ return `union(${a.mode},${kids()})`;
128
+ case TypeId.Dictionary:
129
+ return `dict(${typeSignature(a.dictionary)},${typeSignature(a.indices)},${a.ordered ?? a.isOrdered ?? false})`;
130
+ default:
131
+ return Array.isArray(a.children) ? `${t.typeId}<${kids()}>` : String(t.typeId);
132
+ }
133
+ }
98
134
  function isBatch(x) {
99
135
  return x != null && typeof x.numRows === "number" && x.schema != null && Array.isArray(x.schema.fields);
100
136
  }
@@ -1825,11 +1861,15 @@ __export(exports_impl_arrowjs, {
1825
1861
  batchFromRows: () => batchFromRows,
1826
1862
  batchFromColumns: () => batchFromColumns,
1827
1863
  backend: () => backend,
1864
+ adoptArrowJsShape: () => adoptArrowJsShape,
1828
1865
  UnionMode: () => UnionMode,
1829
1866
  TimeUnit: () => TimeUnit,
1830
1867
  IntervalUnit: () => IntervalUnit,
1831
1868
  DateUnit: () => DateUnit
1832
1869
  });
1870
+ function adoptArrowJsShape(batch) {
1871
+ return batch;
1872
+ }
1833
1873
  var backend;
1834
1874
  var init_impl_arrowjs = __esm(() => {
1835
1875
  init_schema();
@@ -1945,6 +1985,7 @@ __export(exports_arrow, {
1945
1985
  uint64: () => uint642,
1946
1986
  uint32: () => uint322,
1947
1987
  uint16: () => uint162,
1988
+ typeSignature: () => typeSignature,
1948
1989
  timestampSeconds: () => timestampSeconds,
1949
1990
  timestampNanos: () => timestampNanos,
1950
1991
  timestampMillis: () => timestampMillis,
@@ -2048,6 +2089,7 @@ __export(exports_arrow, {
2048
2089
  asDurationMicros: () => asDurationMicros,
2049
2090
  asDate64Ms: () => asDate64Ms,
2050
2091
  asDate32: () => asDate32,
2092
+ adoptArrowJsShape: () => adoptArrowJsShape,
2051
2093
  UnionMode: () => UnionMode2,
2052
2094
  TypeId: () => TypeId,
2053
2095
  TimeUnit: () => TimeUnit2,
@@ -2568,6 +2610,8 @@ var CACHE_REVALIDATABLE_KEY = "vgi.cache.revalidatable";
2568
2610
  var CACHE_STALE_WHILE_REVALIDATE_KEY = "vgi.cache.stale_while_revalidate";
2569
2611
  var CACHE_STALE_IF_ERROR_KEY = "vgi.cache.stale_if_error";
2570
2612
  var CACHE_NOT_MODIFIED_KEY = "vgi.cache.not_modified";
2613
+ var CACHE_PARTITION_SCOPE_KEY = "vgi.cache.partition_scope";
2614
+ var CACHE_PER_VALUE_KEY = "vgi.cache.per_value";
2571
2615
  var CACHE_IF_NONE_MATCH_KEY = "vgi.cache.if_none_match";
2572
2616
  var CACHE_IF_MODIFIED_SINCE_KEY = "vgi.cache.if_modified_since";
2573
2617
  var CACHE_SCOPE_CATALOG = "catalog";
@@ -2604,6 +2648,10 @@ function cacheControlMetadata(cc, extra) {
2604
2648
  md.set(CACHE_STALE_IF_ERROR_KEY, String(cc.staleIfError));
2605
2649
  if (cc.notModified)
2606
2650
  md.set(CACHE_NOT_MODIFIED_KEY, "1");
2651
+ if (cc.partitionScope)
2652
+ md.set(CACHE_PARTITION_SCOPE_KEY, "1");
2653
+ if (cc.perValue)
2654
+ md.set(CACHE_PER_VALUE_KEY, "1");
2607
2655
  return md;
2608
2656
  }
2609
2657
  // src/functions/scalar.ts
@@ -5060,7 +5108,8 @@ var BIND_REQUEST_SCHEMA = schema2([
5060
5108
  field2("transaction_opaque_data", binary2(), true),
5061
5109
  field2("resolved_secrets_provided", bool2(), false),
5062
5110
  field2("at_unit", utf82(), true),
5063
- field2("at_value", utf82(), true)
5111
+ field2("at_value", utf82(), true),
5112
+ field2("schema_name", utf82(), true)
5064
5113
  ]);
5065
5114
  var COPY_FROM_STRUCT_TYPE = struct2([
5066
5115
  field2("format", utf82(), false),
@@ -5092,7 +5141,8 @@ function serializeBindRequest(req) {
5092
5141
  transaction_opaque_data: req.transaction_opaque_data ?? null,
5093
5142
  resolved_secrets_provided: req.resolved_secrets_provided ?? false,
5094
5143
  at_unit: req.at_unit ?? null,
5095
- at_value: req.at_value ?? null
5144
+ at_value: req.at_value ?? null,
5145
+ schema_name: req.schema_name ?? null
5096
5146
  };
5097
5147
  const extraFields = [];
5098
5148
  if (req.copy_from) {
@@ -5164,6 +5214,7 @@ function deserializeBindRequest(params) {
5164
5214
  resolved_secrets_provided: params.resolved_secrets_provided ?? false,
5165
5215
  at_unit: params.at_unit ? String(params.at_unit) : null,
5166
5216
  at_value: params.at_value ? String(params.at_value) : null,
5217
+ schema_name: params.schema_name ? String(params.schema_name) : null,
5167
5218
  copy_from: parseCopyFromContext(params.copy_from),
5168
5219
  copy_to: parseCopyToContext(params.copy_to)
5169
5220
  };
@@ -6741,6 +6792,10 @@ function isPromise(v) {
6741
6792
  }
6742
6793
 
6743
6794
  class CatalogInterface {
6795
+ catalogNameForAttach(_attachOpaqueData) {
6796
+ const names = this.catalogs();
6797
+ return names.length === 1 ? names[0] : null;
6798
+ }
6744
6799
  create(name, onConflict, options) {
6745
6800
  throw new CatalogReadOnlyError("create");
6746
6801
  }
@@ -6975,6 +7030,17 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
6975
7030
  super();
6976
7031
  this._descriptor = descriptor;
6977
7032
  this._registry = registry;
7033
+ for (const sch of descriptor.schemas ?? []) {
7034
+ for (const fn of sch.functions ?? [])
7035
+ registry.registerInSchema(fn, sch.name, descriptor.name);
7036
+ for (const tbl of sch.tables ?? []) {
7037
+ for (const key of ["function", "insertFunction", "updateFunction", "deleteFunction"]) {
7038
+ const fn = tbl[key];
7039
+ if (fn)
7040
+ registry.registerInSchema(fn, sch.name, descriptor.name);
7041
+ }
7042
+ }
7043
+ }
6978
7044
  }
6979
7045
  catalogs() {
6980
7046
  return [this._descriptor.name];
@@ -7597,6 +7663,13 @@ class CompositeCatalogInterface extends CatalogInterface {
7597
7663
  }
7598
7664
  return route;
7599
7665
  }
7666
+ catalogNameForAttach(attachOpaqueData) {
7667
+ try {
7668
+ return this._route(attachOpaqueData).catalogNameForAttach(attachOpaqueData);
7669
+ } catch {
7670
+ return null;
7671
+ }
7672
+ }
7600
7673
  catalogs() {
7601
7674
  const all = [];
7602
7675
  for (const b of this._backends)
@@ -7694,8 +7767,11 @@ class CompositeCatalogInterface extends CatalogInterface {
7694
7767
  init_arrow();
7695
7768
  var EXACT_MATCH_SCORE = 2;
7696
7769
  var FAMILY_MATCH_SCORE = 1;
7770
+ function typesIdentical(a, b) {
7771
+ return typeSignature(a) === typeSignature(b);
7772
+ }
7697
7773
  function typesCompatible(actual, declared) {
7698
- if (actual.toString() === declared.toString())
7774
+ if (typesIdentical(actual, declared))
7699
7775
  return true;
7700
7776
  if (isInt(actual) && isInt(declared))
7701
7777
  return true;
@@ -7723,7 +7799,7 @@ function scoreTypes(specs, actualTypes) {
7723
7799
  const actual = actualTypes[i];
7724
7800
  if (actual === null)
7725
7801
  continue;
7726
- if (actual.toString() === spec.arrowType.toString()) {
7802
+ if (typesIdentical(actual, spec.arrowType)) {
7727
7803
  score += EXACT_MATCH_SCORE;
7728
7804
  } else if (typesCompatible(actual, spec.arrowType)) {
7729
7805
  score += FAMILY_MATCH_SCORE;
@@ -7736,7 +7812,7 @@ function scoreTypes(specs, actualTypes) {
7736
7812
  const actual = actualTypes[i];
7737
7813
  if (actual === null)
7738
7814
  continue;
7739
- if (actual.toString() === varArgsSpec.arrowType.toString()) {
7815
+ if (typesIdentical(actual, varArgsSpec.arrowType)) {
7740
7816
  score += EXACT_MATCH_SCORE;
7741
7817
  } else if (typesCompatible(actual, varArgsSpec.arrowType)) {
7742
7818
  score += FAMILY_MATCH_SCORE;
@@ -7822,9 +7898,17 @@ function filterByArgumentTypes(candidates, args, inputSchema, isScalar) {
7822
7898
  const maxScore = Math.max(...scored.map((s) => s.score));
7823
7899
  return scored.filter((s) => s.score === maxScore).map((s) => s.func);
7824
7900
  }
7901
+ function schemaKey(schemaName, functionName) {
7902
+ return `${schemaName.toLowerCase()}\x00${functionName}`;
7903
+ }
7904
+ function catalogKey(catalogName, schemaName, functionName) {
7905
+ return `${catalogName.toLowerCase()}\x00${schemaKey(schemaName, functionName)}`;
7906
+ }
7825
7907
 
7826
7908
  class FunctionRegistry {
7827
7909
  _functions = new Map;
7910
+ _bySchema = new Map;
7911
+ _byCatalog = new Map;
7828
7912
  register(func) {
7829
7913
  const name = func.meta.name;
7830
7914
  if (!this._functions.has(name)) {
@@ -7832,11 +7916,57 @@ class FunctionRegistry {
7832
7916
  }
7833
7917
  this._functions.get(name).push(func);
7834
7918
  }
7919
+ registerInSchema(func, schemaName, catalogName) {
7920
+ const add = (map3, key) => {
7921
+ const bucket = map3.get(key);
7922
+ if (!bucket) {
7923
+ map3.set(key, [func]);
7924
+ return;
7925
+ }
7926
+ if (!bucket.includes(func))
7927
+ bucket.push(func);
7928
+ };
7929
+ add(this._bySchema, schemaKey(schemaName, func.meta.name));
7930
+ if (catalogName) {
7931
+ add(this._byCatalog, catalogKey(catalogName, schemaName, func.meta.name));
7932
+ }
7933
+ }
7934
+ schemasFor(functionName) {
7935
+ const out = [];
7936
+ for (const key of this._bySchema.keys()) {
7937
+ const [schema3, name] = key.split("\x00");
7938
+ if (name === functionName)
7939
+ out.push(schema3);
7940
+ }
7941
+ return out.sort();
7942
+ }
7835
7943
  get(name, context) {
7836
- const candidates = this._functions.get(name);
7944
+ let candidates = this._functions.get(name);
7945
+ const catalogName = context?.catalogName;
7946
+ const schemaName = context?.schemaName;
7947
+ if (catalogName && schemaName) {
7948
+ const scoped = this._byCatalog.get(catalogKey(catalogName, schemaName, name));
7949
+ if (scoped && scoped.length > 0) {
7950
+ return this._disambiguate(name, scoped, context);
7951
+ }
7952
+ }
7953
+ if (schemaName) {
7954
+ const scoped = this._bySchema.get(schemaKey(schemaName, name));
7955
+ if (scoped && scoped.length > 0) {
7956
+ candidates = scoped;
7957
+ } else if (candidates && candidates.length > 0) {
7958
+ const schemas = this.schemasFor(name);
7959
+ if (schemas.length > 0) {
7960
+ throw new Error(`Function '${name}' is not registered in schema '${schemaName}'. ` + `It is available in: [${schemas.join(", ")}]`);
7961
+ }
7962
+ }
7963
+ }
7837
7964
  if (!candidates || candidates.length === 0) {
7838
7965
  throw new FunctionNotFoundError(name, this.names());
7839
7966
  }
7967
+ return this._disambiguate(name, candidates, context);
7968
+ }
7969
+ _disambiguate(name, candidates, context) {
7840
7970
  if (candidates.length === 1) {
7841
7971
  return candidates[0];
7842
7972
  }
@@ -8122,11 +8252,21 @@ function wrapResult(values, innerSchema) {
8122
8252
  const batch = batchFromColumns(Object.fromEntries(a.fields.map((f) => [f.name, [values[f.name] ?? null]])), a);
8123
8253
  return { result: serializeBatch(batch) };
8124
8254
  }
8125
- function overloadContext(req) {
8255
+ function overloadContext(req, catalogInterface) {
8256
+ let catalogName = null;
8257
+ if (catalogInterface && req.attach_opaque_data) {
8258
+ try {
8259
+ catalogName = catalogInterface.catalogNameForAttach(req.attach_opaque_data);
8260
+ } catch {
8261
+ catalogName = null;
8262
+ }
8263
+ }
8126
8264
  return {
8127
8265
  arguments: req.arguments,
8128
8266
  inputSchema: req.input_schema,
8129
- isScalar: String(req.function_type).toLowerCase() === "scalar"
8267
+ isScalar: String(req.function_type).toLowerCase() === "scalar",
8268
+ schemaName: req.schema_name ?? null,
8269
+ catalogName
8130
8270
  };
8131
8271
  }
8132
8272
  function recoverFinalizeState(request, recoverExchangeState) {
@@ -9099,7 +9239,7 @@ var columnOpParams = schema2([
9099
9239
 
9100
9240
  // src/protocol/handlers/function.ts
9101
9241
  function registerFunctionMethods(protocol, config) {
9102
- const { registry, signingKey } = config;
9242
+ const { registry, signingKey, catalogInterface } = config;
9103
9243
  async function stripAttach(attach, ctx) {
9104
9244
  if (attach == null)
9105
9245
  return null;
@@ -9108,6 +9248,15 @@ function registerFunctionMethods(protocol, config) {
9108
9248
  return env;
9109
9249
  return openAttach(env, ctx?.auth, signingKey);
9110
9250
  }
9251
+ async function strippedContext(bindCall, ctx) {
9252
+ let attach = null;
9253
+ try {
9254
+ attach = await stripAttach(bindCall.attach_opaque_data, ctx);
9255
+ } catch {
9256
+ attach = null;
9257
+ }
9258
+ return overloadContext({ ...bindCall, attach_opaque_data: attach }, catalogInterface);
9259
+ }
9111
9260
  const initHeaderSchema = schema2([
9112
9261
  field2("execution_id", binary2(), false),
9113
9262
  field2("opaque_data", binary2(), true),
@@ -9124,7 +9273,7 @@ function registerFunctionMethods(protocol, config) {
9124
9273
  const innerParams = unwrapRequest(params.request);
9125
9274
  const request = deserializeBindRequest(innerParams);
9126
9275
  request.attach_opaque_data = await stripAttach(request.attach_opaque_data, ctx);
9127
- const func = registry.get(request.function_name, overloadContext(request));
9276
+ const func = registry.get(request.function_name, overloadContext(request, catalogInterface));
9128
9277
  const response = await func.bind(request);
9129
9278
  const serialized = serializeBindResponse(response);
9130
9279
  return wrapResult(serialized, BindResultSchema);
@@ -9139,7 +9288,7 @@ function registerFunctionMethods(protocol, config) {
9139
9288
  const innerParams = unwrapRequest(params.request);
9140
9289
  const request = deserializeInitRequest(innerParams);
9141
9290
  request.bind_call.attach_opaque_data = await stripAttach(request.bind_call.attach_opaque_data, undefined);
9142
- const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call));
9291
+ const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call, catalogInterface));
9143
9292
  const initResponse = await func.globalInit(request);
9144
9293
  const accumulatedState = recoverFinalizeState(request, config.recoverExchangeState);
9145
9294
  const handlers = func.createStreamHandlers(request, initResponse, accumulatedState);
@@ -9169,6 +9318,7 @@ function registerFunctionMethods(protocol, config) {
9169
9318
  return state;
9170
9319
  },
9171
9320
  exchange: async (state, input, out) => {
9321
+ input = adoptArrowJsShape(input);
9172
9322
  let handlers;
9173
9323
  let handlerState;
9174
9324
  if (state._handlers) {
@@ -9178,7 +9328,7 @@ function registerFunctionMethods(protocol, config) {
9178
9328
  const initRequestBatch = deserializeBatch(state.initRequestIpc);
9179
9329
  const initRequestDict = batchToScalarDict(initRequestBatch);
9180
9330
  const request = deserializeInitRequest(initRequestDict);
9181
- const func = registry.get(state.functionName, overloadContext(request.bind_call));
9331
+ const func = registry.get(state.functionName, await strippedContext(request.bind_call));
9182
9332
  const executionId = state.executionId;
9183
9333
  const opaqueData = state.opaqueData ?? null;
9184
9334
  const initResponse = {
@@ -9226,7 +9376,7 @@ function registerFunctionMethods(protocol, config) {
9226
9376
  handler: async (params) => {
9227
9377
  const innerParams = unwrapRequest(params.request);
9228
9378
  const request = deserializeCardinalityRequest(innerParams);
9229
- const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call));
9379
+ const func = registry.get(request.bind_call.function_name, await strippedContext(request.bind_call));
9230
9380
  let cardResult;
9231
9381
  if (func.cardinality) {
9232
9382
  cardResult = serializeTableCardinality(await func.cardinality(request));
@@ -9239,10 +9389,10 @@ function registerFunctionMethods(protocol, config) {
9239
9389
  protocol.unary("table_function_statistics", {
9240
9390
  params: REQUEST_PARAMS_SCHEMA,
9241
9391
  result: RESULT_BINARY_NULLABLE_SCHEMA,
9242
- handler: (params) => {
9392
+ handler: async (params) => {
9243
9393
  const innerParams = unwrapRequest(params.request);
9244
9394
  const request = deserializeCardinalityRequest(innerParams);
9245
- const func = registry.get(request.bind_call.function_name, overloadContext(request.bind_call));
9395
+ const func = registry.get(request.bind_call.function_name, await strippedContext(request.bind_call));
9246
9396
  if (!func.statistics)
9247
9397
  return { result: null };
9248
9398
  const stats = func.statistics(request);
@@ -9262,7 +9412,7 @@ function registerFunctionMethods(protocol, config) {
9262
9412
  const bindCall = deserializeBindRequest(bindParams);
9263
9413
  const globalExecutionId = toUint8Array(innerParams.global_execution_id);
9264
9414
  const bindOpaqueData = innerParams.bind_opaque_data ? toUint8Array(innerParams.bind_opaque_data) : null;
9265
- const func = registry.get(bindCall.function_name, overloadContext(bindCall));
9415
+ const func = registry.get(bindCall.function_name, await strippedContext(bindCall));
9266
9416
  const map3 = func.dynamicToString ? await func.dynamicToString({ bindCall, bindOpaqueData, globalExecutionId }) : {};
9267
9417
  const keys = Object.keys(map3);
9268
9418
  const values = keys.map((k) => map3[k] ?? "");
@@ -10262,7 +10412,8 @@ function buildVgiProtocol(config) {
10262
10412
  registerFunctionMethods(protocol, {
10263
10413
  registry: config.registry,
10264
10414
  recoverExchangeState: config.recoverExchangeState,
10265
- signingKey: config.signingKey
10415
+ signingKey: config.signingKey,
10416
+ catalogInterface: config.catalogInterface
10266
10417
  });
10267
10418
  registerAggregateMethods(protocol, config.registry);
10268
10419
  registerTableBufferingMethods(protocol, config.registry, config.signingKey);
@@ -11647,7 +11798,7 @@ class Worker {
11647
11798
  _catalogInterface;
11648
11799
  _catalogName;
11649
11800
  constructor(config) {
11650
- this._registry = new FunctionRegistry;
11801
+ this._registry = config.registry ?? new FunctionRegistry;
11651
11802
  this._catalogName = config.catalogName;
11652
11803
  if (config.functions) {
11653
11804
  for (const func of config.functions) {
@@ -11659,6 +11810,7 @@ class Worker {
11659
11810
  if (schema3.functions) {
11660
11811
  for (const func of schema3.functions) {
11661
11812
  this._registry.register(func);
11813
+ this._registry.registerInSchema(func, schema3.name, config.catalog.name);
11662
11814
  }
11663
11815
  }
11664
11816
  }
@@ -11754,6 +11906,7 @@ export {
11754
11906
  uint642 as uint64,
11755
11907
  uint322 as uint32,
11756
11908
  uint162 as uint16,
11909
+ typeSignature,
11757
11910
  toUint8Array,
11758
11911
  toSchema,
11759
11912
  timestampSeconds,
@@ -11918,6 +12071,7 @@ export {
11918
12071
  arrowToMetadatas,
11919
12072
  arrowStateSerializer,
11920
12073
  argumentSpecsToSchema,
12074
+ adoptArrowJsShape,
11921
12075
  Worker,
11922
12076
  VgiError,
11923
12077
  VgiClientError,
@@ -11966,6 +12120,8 @@ export {
11966
12120
  CACHE_SCOPE_KEY,
11967
12121
  CACHE_SCOPE_CATALOG,
11968
12122
  CACHE_REVALIDATABLE_KEY,
12123
+ CACHE_PER_VALUE_KEY,
12124
+ CACHE_PARTITION_SCOPE_KEY,
11969
12125
  CACHE_NO_STORE_KEY,
11970
12126
  CACHE_NOT_MODIFIED_KEY,
11971
12127
  CACHE_LAST_MODIFIED_KEY,
@@ -11980,4 +12136,4 @@ export {
11980
12136
  ArgumentValidationError
11981
12137
  };
11982
12138
 
11983
- //# debugId=8787F3CC30C0C60C64756E2164756E21
12139
+ //# debugId=AC11F66207EB748964756E2164756E21