@query-farm/vgi 0.51.0 → 0.52.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 (70) hide show
  1. package/README.md +45 -3
  2. package/dist/client-entry.js +833 -775
  3. package/dist/client-entry.js.map +10 -10
  4. package/dist/functions/storage-blobs.d.ts +173 -0
  5. package/dist/functions/storage-cf-do.d.ts +12 -0
  6. package/dist/functions/storage.d.ts +22 -0
  7. package/dist/functions/table.d.ts +6 -1
  8. package/dist/generated/vgi-client.d.ts +7 -1
  9. package/dist/generated/vgi-protocol-schemas.d.ts +10 -9
  10. package/dist/generated/vgi-protocol-types.d.ts +244 -2
  11. package/dist/generated/vgi-service.d.ts +1 -1
  12. package/dist/hosted.d.ts +117 -0
  13. package/dist/http/blob-vendor.d.ts +33 -0
  14. package/dist/http/fetch.d.ts +53 -2
  15. package/dist/http/hosted-auth.d.ts +45 -0
  16. package/dist/index.core.d.ts +9 -2
  17. package/dist/index.js +5238 -3619
  18. package/dist/index.js.map +44 -28
  19. package/dist/protocol/arguments-ref.d.ts +107 -0
  20. package/dist/protocol/dispatch.d.ts +3 -2
  21. package/dist/protocol/handlers/function.d.ts +21 -0
  22. package/dist/protocol/serialize.d.ts +1 -1
  23. package/dist/protocol/serializers/bind.d.ts +27 -1
  24. package/dist/protocol/serializers/cardinality.d.ts +1 -1
  25. package/dist/protocol/serializers/splits.d.ts +7 -0
  26. package/dist/protocol/state-serializer.d.ts +8 -7
  27. package/dist/protocol/stream-init.d.ts +17 -0
  28. package/dist/protocol/types.d.ts +24 -0
  29. package/dist/secrets/lookups.d.ts +31 -0
  30. package/dist/serve-entry.d.ts +25 -4
  31. package/dist/serve-entry.js +2940 -1219
  32. package/dist/serve-entry.js.map +44 -29
  33. package/dist/worker-cf-entry.d.ts +5 -0
  34. package/dist/worker-cf-entry.js +2928 -1223
  35. package/dist/worker-cf-entry.js.map +47 -31
  36. package/package.json +5 -4
  37. package/src/functions/storage-blobs.ts +654 -0
  38. package/src/functions/storage-cf-do.ts +24 -0
  39. package/src/functions/storage.ts +54 -5
  40. package/src/functions/table-buffering.ts +14 -4
  41. package/src/functions/table.ts +8 -4
  42. package/src/generated/vgi-client.ts +9 -2
  43. package/src/generated/vgi-protocol-schemas.ts +115 -107
  44. package/src/generated/vgi-protocol-types.ts +640 -3
  45. package/src/generated/vgi-service.ts +2 -2
  46. package/src/hosted.ts +254 -0
  47. package/src/http/blob-vendor.ts +80 -0
  48. package/src/http/fetch.ts +170 -8
  49. package/src/http/hosted-auth.ts +326 -0
  50. package/src/index.core.ts +64 -1
  51. package/src/protocol/arguments-ref.ts +260 -0
  52. package/src/protocol/dispatch.ts +3 -2
  53. package/src/protocol/handlers/function.ts +109 -60
  54. package/src/protocol/handlers/table-buffering.ts +5 -0
  55. package/src/protocol/serialize.ts +3 -0
  56. package/src/protocol/serializers/bind.ts +96 -69
  57. package/src/protocol/serializers/cardinality.ts +4 -7
  58. package/src/protocol/serializers/init.ts +5 -11
  59. package/src/protocol/serializers/splits.ts +31 -4
  60. package/src/protocol/state-serializer.ts +27 -39
  61. package/src/protocol/stream-init.ts +87 -0
  62. package/src/protocol/types.ts +25 -0
  63. package/src/secrets/lookups.ts +53 -0
  64. package/src/serve-entry.ts +105 -8
  65. package/src/worker-cf-entry.ts +33 -0
  66. package/src/worker.ts +25 -0
  67. package/dist/protocol/carried-init-request.d.ts +0 -28
  68. package/dist/util/zstd-sync.d.ts +0 -7
  69. package/src/protocol/carried-init-request.ts +0 -139
  70. package/src/util/zstd-sync.ts +0 -50
@@ -2,7 +2,7 @@
2
2
  // GENERATED by vgi.codegen.ts_types. DO NOT EDIT BY HAND.
3
3
  //
4
4
  // Generator: python -m vgi.codegen.ts_types v1
5
- // Content hash: 50667b91293f
5
+ // Content hash: cd0d6ca37f7c
6
6
  //
7
7
  // To regenerate:
8
8
  // uv run --project ~/Development/vgi-python python scripts/regen_generated.py
@@ -10,6 +10,8 @@
10
10
 
11
11
  import { encodeASD, decodeASD } from "../codec/asd.js";
12
12
  import {
13
+ ArgumentsLocationSchema,
14
+ BindRequestSchema,
13
15
  CatalogAttachResultSchema,
14
16
  CatalogCapabilitiesSchema,
15
17
  CatalogContentsResultSchema,
@@ -23,11 +25,14 @@ import {
23
25
  ConstraintInfoSchema,
24
26
  ConstraintSnapshotSchema,
25
27
  ConstraintsApplyRequestSchema,
28
+ CopyFromContextSchema,
29
+ CopyToContextSchema,
26
30
  DependencySnapshotSchema,
27
31
  FieldPathSchema,
28
32
  ForeignKeyDefinitionSchema,
29
33
  IndexDefinitionSchema,
30
34
  IndexKeySchema,
35
+ InitRequestSchema,
31
36
  KeyGroupingSchema,
32
37
  MacroOverloadSchema,
33
38
  MacroParameterSchema,
@@ -45,12 +50,129 @@ import {
45
50
  SortKeySchema,
46
51
  SqlExpressionSchema,
47
52
  SqlStatementSchema,
53
+ TableFunctionCardinalityRequestSchema,
54
+ TableFunctionDynamicToStringRequestSchema,
55
+ TableFunctionPlanRequestSchema,
56
+ TableFunctionProjectionRequestSchema,
57
+ TableFunctionStatisticsRequestSchema,
48
58
  TableLayoutChangeSchema,
49
59
  TableLayoutSchema,
50
60
  TransformSpecSchema,
51
61
  } from "./vgi-protocol-schemas.js";
52
- import type { CatalogAttachResult, CatalogCapabilities, CatalogContentsResponse, CatalogObjectRef, CatalogQueryPrepareRequest, CatalogQueryPrepareResult, ClientQueryCapabilities, ConstraintSnapshot, ConstraintsApplyRequest, DependencySnapshot, IndexDefinition, MacroOverload, MacroParameter, OptionDefinitions, OptionState, QueryCapabilities, QueryEvaluationContext, QueryObjectReference, SqlExpression, TableLayout } from "./vgi-client.js";
53
- export type { CatalogAttachResult, CatalogCapabilities, CatalogContentsResponse, CatalogObjectRef, CatalogQueryPrepareRequest, CatalogQueryPrepareResult, ClientQueryCapabilities, ConstraintSnapshot, ConstraintsApplyRequest, DependencySnapshot, IndexDefinition, MacroOverload, MacroParameter, OptionDefinitions, OptionState, QueryCapabilities, QueryEvaluationContext, QueryObjectReference, SqlExpression, TableLayout };
62
+ import type { ArgumentsLocation, BindRequest, CatalogAttachResult, CatalogCapabilities, CatalogContentsResponse, CatalogObjectRef, CatalogQueryPrepareRequest, CatalogQueryPrepareResult, ClientQueryCapabilities, ConstraintSnapshot, ConstraintsApplyRequest, CopyFromContext, CopyToContext, DependencySnapshot, IndexDefinition, MacroOverload, MacroParameter, OptionDefinitions, OptionState, QueryCapabilities, QueryEvaluationContext, QueryObjectReference, SqlExpression, TableLayout } from "./vgi-client.js";
63
+ export type { ArgumentsLocation, BindRequest, CatalogAttachResult, CatalogCapabilities, CatalogContentsResponse, CatalogObjectRef, CatalogQueryPrepareRequest, CatalogQueryPrepareResult, ClientQueryCapabilities, ConstraintSnapshot, ConstraintsApplyRequest, CopyFromContext, CopyToContext, DependencySnapshot, IndexDefinition, MacroOverload, MacroParameter, OptionDefinitions, OptionState, QueryCapabilities, QueryEvaluationContext, QueryObjectReference, SqlExpression, TableLayout };
64
+
65
+ // ----------------------------------------------------------------------------
66
+ // Nested<T>: a record carried as a complete Arrow IPC stream in a binary column
67
+ // ----------------------------------------------------------------------------
68
+
69
+ function deepFreeze<T>(value: T): T {
70
+ if (value !== null && typeof value === "object" && !ArrayBuffer.isView(value) && !Object.isFrozen(value)) {
71
+ for (const key of Object.keys(value as object)) deepFreeze((value as any)[key]);
72
+ Object.freeze(value);
73
+ }
74
+ return value;
75
+ }
76
+
77
+ function sameBytes(a: Uint8Array, b: Uint8Array): boolean {
78
+ if (a.byteLength !== b.byteLength) return false;
79
+ for (let i = 0; i < a.byteLength; i++) if (a[i] !== b[i]) return false;
80
+ return true;
81
+ }
82
+
83
+ /**
84
+ * The raw-preserving lazy wrapper for a nested record carried as binary
85
+ * (vgi docs/large-values-3.4.md §3.3). It holds the bytes exactly as received
86
+ * (a private copy), decodes them only when `get()` / `value` is first read,
87
+ * and the embedding record's encoder writes the held bytes verbatim, so a
88
+ * decoded-then-re-encoded request is byte-identical to what the peer sent.
89
+ *
90
+ * The decoded value is frozen, and is decoded from a private copy of the bytes,
91
+ * so nothing done to it can change the held bytes. To change a field, build a
92
+ * new record and wrap it with `Nested.of` (or the generated `nested<Record>`).
93
+ * Printing (`toJSON`, `toString`, Node's inspect) never decodes or re-encodes.
94
+ */
95
+ export class Nested<T> {
96
+ readonly #bytes: Uint8Array;
97
+ readonly #decode: (bytes: Uint8Array) => T;
98
+ readonly #path: string;
99
+ #state: { ok: true; value: Readonly<T> } | { ok: false; error: Error } | undefined;
100
+
101
+ private constructor(bytes: Uint8Array, decode: (bytes: Uint8Array) => T, path: string) {
102
+ this.#bytes = bytes;
103
+ this.#decode = decode;
104
+ this.#path = path;
105
+ }
106
+
107
+ /** Wrap bytes received elsewhere (rule 7). The bytes are copied, not decoded. */
108
+ static fromBytes<T>(bytes: Uint8Array, decode: (bytes: Uint8Array) => T, path = "nested record"): Nested<T> {
109
+ return new Nested(bytes.slice(), decode, path);
110
+ }
111
+
112
+ /** Serialize a typed record once and hold those bytes (rule 6). */
113
+ static of<T>(
114
+ record: T,
115
+ encode: (value: T) => Uint8Array,
116
+ decode: (bytes: Uint8Array) => T,
117
+ path = "nested record",
118
+ ): Nested<T> {
119
+ return new Nested(encode(record).slice(), decode, path);
120
+ }
121
+
122
+ /** The held bytes, exactly as received. Read-only by contract: do not mutate. */
123
+ get bytes(): Uint8Array {
124
+ return this.#bytes;
125
+ }
126
+
127
+ get byteLength(): number {
128
+ return this.#bytes.byteLength;
129
+ }
130
+
131
+ /** The field path decode errors name, e.g. `InitRequest.bind_call`. */
132
+ get path(): string {
133
+ return this.#path;
134
+ }
135
+
136
+ /**
137
+ * The decoded record, decoded on first access and cached (rule 2). A
138
+ * malformed or empty value throws here, naming the field path (rules 3, 9).
139
+ */
140
+ get(): Readonly<T> {
141
+ if (this.#state === undefined) {
142
+ try {
143
+ if (this.#bytes.byteLength === 0) throw new Error("empty nested record");
144
+ this.#state = { ok: true, value: deepFreeze(this.#decode(this.#bytes.slice())) };
145
+ } catch (cause) {
146
+ const message = cause instanceof Error ? cause.message : String(cause);
147
+ this.#state = { ok: false, error: new Error(`${this.#path}: ${message}`, { cause }) };
148
+ }
149
+ }
150
+ if (!this.#state.ok) throw this.#state.error;
151
+ return this.#state.value;
152
+ }
153
+
154
+ /** Same as `get()`. */
155
+ get value(): Readonly<T> {
156
+ return this.get();
157
+ }
158
+
159
+ /** Equality is over the held bytes (rule 8). */
160
+ equals(other: Nested<T> | null | undefined): boolean {
161
+ return other != null && sameBytes(this.#bytes, other.#bytes);
162
+ }
163
+
164
+ toJSON(): { nested: string; byteLength: number } {
165
+ return { nested: this.#path, byteLength: this.#bytes.byteLength };
166
+ }
167
+
168
+ toString(): string {
169
+ return `Nested(${this.#path}, ${this.#bytes.byteLength} bytes)`;
170
+ }
171
+
172
+ [Symbol.for("nodejs.util.inspect.custom")](): string {
173
+ return this.toString();
174
+ }
175
+ }
54
176
 
55
177
  // ----------------------------------------------------------------------------
56
178
  // FieldPath (schema: FieldPathSchema)
@@ -1014,6 +1136,521 @@ export function buildRequiredFilterPaths(init: RequiredFilterPathsInit): Require
1014
1136
  export const encodeRequiredFilterPaths = (v: RequiredFilterPaths): Uint8Array => encodeASD(RequiredFilterPathsSchema, v);
1015
1137
  export const decodeRequiredFilterPaths = (b: Uint8Array): RequiredFilterPaths => decodeASD<RequiredFilterPaths>(RequiredFilterPathsSchema, b);
1016
1138
 
1139
+ // ----------------------------------------------------------------------------
1140
+ // CopyFromContext (schema: CopyFromContextSchema)
1141
+ // ----------------------------------------------------------------------------
1142
+
1143
+ /** `CopyFromContext` has no defaulted fields, so its init is the record itself. */
1144
+ export type CopyFromContextInit = CopyFromContext;
1145
+
1146
+ /** Build a complete `CopyFromContext`, filling the protocol defaults, in wire order. */
1147
+ export function buildCopyFromContext(init: CopyFromContextInit): CopyFromContext {
1148
+ return {
1149
+ format: init.format,
1150
+ file_path: init.file_path,
1151
+ expected_schema: init.expected_schema,
1152
+ };
1153
+ }
1154
+
1155
+ export const encodeCopyFromContext = (v: CopyFromContext): Uint8Array => encodeASD(CopyFromContextSchema, v);
1156
+ export const decodeCopyFromContext = (b: Uint8Array): CopyFromContext => decodeASD<CopyFromContext>(CopyFromContextSchema, b);
1157
+
1158
+ // ----------------------------------------------------------------------------
1159
+ // CopyToContext (schema: CopyToContextSchema)
1160
+ // ----------------------------------------------------------------------------
1161
+
1162
+ /** `CopyToContext` has no defaulted fields, so its init is the record itself. */
1163
+ export type CopyToContextInit = CopyToContext;
1164
+
1165
+ /** Build a complete `CopyToContext`, filling the protocol defaults, in wire order. */
1166
+ export function buildCopyToContext(init: CopyToContextInit): CopyToContext {
1167
+ return {
1168
+ format: init.format,
1169
+ file_path: init.file_path,
1170
+ };
1171
+ }
1172
+
1173
+ export const encodeCopyToContext = (v: CopyToContext): Uint8Array => encodeASD(CopyToContextSchema, v);
1174
+ export const decodeCopyToContext = (b: Uint8Array): CopyToContext => decodeASD<CopyToContext>(CopyToContextSchema, b);
1175
+
1176
+ // ----------------------------------------------------------------------------
1177
+ // ArgumentsLocation (schema: ArgumentsLocationSchema)
1178
+ // ----------------------------------------------------------------------------
1179
+
1180
+ /** `ArgumentsLocation` has no defaulted fields, so its init is the record itself. */
1181
+ export type ArgumentsLocationInit = ArgumentsLocation;
1182
+
1183
+ /** Build a complete `ArgumentsLocation`, filling the protocol defaults, in wire order. */
1184
+ export function buildArgumentsLocation(init: ArgumentsLocationInit): ArgumentsLocation {
1185
+ return {
1186
+ ref: init.ref,
1187
+ size: init.size,
1188
+ sha256: init.sha256,
1189
+ };
1190
+ }
1191
+
1192
+ export const encodeArgumentsLocation = (v: ArgumentsLocation): Uint8Array => encodeASD(ArgumentsLocationSchema, v);
1193
+ export const decodeArgumentsLocation = (b: Uint8Array): ArgumentsLocation => decodeASD<ArgumentsLocation>(ArgumentsLocationSchema, b);
1194
+
1195
+ // ----------------------------------------------------------------------------
1196
+ // BindRequest (schema: BindRequestSchema)
1197
+ // ----------------------------------------------------------------------------
1198
+
1199
+ /** Fields of `BindRequest` that have a protocol default. */
1200
+ export type BindRequestDefaultedField =
1201
+ | "input_schema"
1202
+ | "settings"
1203
+ | "secrets"
1204
+ | "attach_opaque_data"
1205
+ | "transaction_opaque_data"
1206
+ | "resolved_secrets_provided"
1207
+ | "at_unit"
1208
+ | "at_value"
1209
+ | "copy_from"
1210
+ | "copy_to"
1211
+ | "schema_path"
1212
+ | "argument_names"
1213
+ | "arguments_location";
1214
+ /** `BindRequest` with every field that has a protocol default optional. */
1215
+ export type BindRequestInit = Omit<BindRequest, BindRequestDefaultedField> & Partial<Pick<BindRequest, BindRequestDefaultedField>>;
1216
+
1217
+ /** Build a complete `BindRequest`, filling the protocol defaults, in wire order. */
1218
+ export function buildBindRequest(init: BindRequestInit): BindRequest {
1219
+ return {
1220
+ function_name: init.function_name,
1221
+ arguments: init.arguments ?? null,
1222
+ function_type: init.function_type,
1223
+ input_schema: init.input_schema ?? null,
1224
+ settings: init.settings ?? null,
1225
+ secrets: init.secrets ?? null,
1226
+ attach_opaque_data: init.attach_opaque_data ?? null,
1227
+ transaction_opaque_data: init.transaction_opaque_data ?? null,
1228
+ resolved_secrets_provided: init.resolved_secrets_provided ?? false,
1229
+ at_unit: init.at_unit ?? null,
1230
+ at_value: init.at_value ?? null,
1231
+ copy_from: init.copy_from ?? null,
1232
+ copy_to: init.copy_to ?? null,
1233
+ schema_path: init.schema_path ?? null,
1234
+ argument_names: init.argument_names ?? null,
1235
+ arguments_location: init.arguments_location ?? null,
1236
+ };
1237
+ }
1238
+
1239
+ export const encodeBindRequest = (v: BindRequest): Uint8Array => encodeASD(BindRequestSchema, v);
1240
+ export const decodeBindRequest = (b: Uint8Array): BindRequest => decodeASD<BindRequest>(BindRequestSchema, b);
1241
+
1242
+ /**
1243
+ * Wrap a `BindRequest` for a field that carries it as a nested record: a typed
1244
+ * record is serialized once (spec §3.3 rule 6); bytes are held as given (rule 7).
1245
+ */
1246
+ export function nestedBindRequest(
1247
+ source: BindRequest | Uint8Array,
1248
+ path = "BindRequest",
1249
+ ): Nested<BindRequest> {
1250
+ return source instanceof Uint8Array
1251
+ ? Nested.fromBytes(source, decodeBindRequest, path)
1252
+ : Nested.of(source, encodeBindRequest, decodeBindRequest, path);
1253
+ }
1254
+
1255
+ // ----------------------------------------------------------------------------
1256
+ // InitRequest (schema: InitRequestSchema)
1257
+ // ----------------------------------------------------------------------------
1258
+
1259
+ /** Consolidated init request for all function types. For secondary init requests, `execution_id` and `init_opaque_data` are set; use :attr:`is_secondary` to distinguish. */
1260
+ export interface InitRequest {
1261
+ /** The originating `BindRequest` (function name, arguments, schemas). */
1262
+ bind_call: Nested<BindRequest>;
1263
+ /** Serialized Arrow schema of the rows the function produces. */
1264
+ output_schema: Uint8Array;
1265
+ /** Opaque per-bind state the worker returned from bind(), threaded back into later calls. Wire-facing bytes the framework produced from the typed `BindResult.opaque_data`; consumers reconstruct via `MyConcreteDataclass.deserialize_from_bytes(raw)`. See `BindResponse.opaque_data` in vgi/invocation.py for the full contract rationale. */
1266
+ bind_opaque_data?: Uint8Array | null;
1267
+ /** Column indices DuckDB wants projected from the function's output; `None` for scalar functions or when no projection pushdown. */
1268
+ projection_ids?: number[] | null;
1269
+ /** Serialized filter predicates DuckDB pushed down to the scan; `None` when no filters apply. */
1270
+ pushdown_filters?: Uint8Array | null;
1271
+ /** Serialized join-key batches pushed down for join filtering; `None` when not applicable. */
1272
+ join_keys?: Uint8Array[] | null;
1273
+ /** Split tokens to redeem in this init, or None for an ordinary whole-scan init. Usually one; a client that bin-packs sends a whole group and expects them concatenated in the order given. */
1274
+ split_tokens?: Uint8Array[] | null;
1275
+ /** Plain fetch limit, or None. NOT `order_by_limit`, which is a field of the Top-N hint. DuckDB cannot supply this; DataFusion can. */
1276
+ row_limit?: number | null;
1277
+ /** For table-in-out functions, which init phase (INPUT / FINALIZE / buffering) this request opens; `None` for other function types. */
1278
+ phase?: string | null;
1279
+ /** For a buffered-table finalize stream, which state_id this stream serves. Required when `phase=TABLE_BUFFERING_FINALIZE`, `None` otherwise. Opaque bytes — the worker chose the encoding when its combine() returned the finalize_state_ids list. */
1280
+ finalize_state_id?: Uint8Array | null;
1281
+ /** Identifier for one query execution, stable across the coordinator and any secondary workers; keys worker-owned state. `None` for global init, set for secondary init. */
1282
+ execution_id?: Uint8Array | null;
1283
+ /** Opaque per-init state threaded back into the stream; same producer/wire/consumer contract as `bind_opaque_data`. */
1284
+ init_opaque_data?: Uint8Array | null;
1285
+ /** Stable, client-owned identity of the streaming table-in-out substream this request opens (per DuckDB PipelineExecutor). Rides every InitRequest a substream's worker builds — INPUT and FINALIZE — so a worker can locate that substream's accumulated state even when an HTTP load balancer routes its init / process / finalize to different backends. `None` for non-substream function types. */
1286
+ substream_id?: Uint8Array | null;
1287
+ /** Column name of the order-pushdown hint from DuckDB's RowGroupPruner optimizer; `None` when no hint. */
1288
+ order_by_column_name?: string | null;
1289
+ /** Sort direction of the order-pushdown hint; `None` when no hint. */
1290
+ order_by_direction?: string | null;
1291
+ /** Null-ordering of the order-pushdown hint; `None` when no hint. */
1292
+ order_by_null_order?: string | null;
1293
+ /** Row limit of the order-pushdown hint; `None` when no hint. */
1294
+ order_by_limit?: number | null;
1295
+ /** Sample percentage of the TABLESAMPLE pushdown hint from DuckDB's SamplingPushdown optimizer; `None` when no hint. */
1296
+ tablesample_percentage?: number | null;
1297
+ /** Sample seed of the TABLESAMPLE pushdown hint; `None` when no hint. */
1298
+ tablesample_seed?: number | null;
1299
+ }
1300
+
1301
+ /** Fields of `InitRequest` that have a protocol default. */
1302
+ export type InitRequestDefaultedField =
1303
+ | "bind_opaque_data"
1304
+ | "projection_ids"
1305
+ | "pushdown_filters"
1306
+ | "join_keys"
1307
+ | "split_tokens"
1308
+ | "row_limit"
1309
+ | "phase"
1310
+ | "finalize_state_id"
1311
+ | "execution_id"
1312
+ | "init_opaque_data"
1313
+ | "substream_id"
1314
+ | "order_by_column_name"
1315
+ | "order_by_direction"
1316
+ | "order_by_null_order"
1317
+ | "order_by_limit"
1318
+ | "tablesample_percentage"
1319
+ | "tablesample_seed";
1320
+ /** `InitRequest` with every field that has a protocol default optional. */
1321
+ export type InitRequestInit = Omit<InitRequest, InitRequestDefaultedField> & Partial<Pick<InitRequest, InitRequestDefaultedField>>;
1322
+
1323
+ /** Build a complete `InitRequest`, filling the protocol defaults, in wire order. */
1324
+ export function buildInitRequest(init: InitRequestInit): InitRequest {
1325
+ return {
1326
+ bind_call: init.bind_call,
1327
+ output_schema: init.output_schema,
1328
+ bind_opaque_data: init.bind_opaque_data ?? null,
1329
+ projection_ids: init.projection_ids ?? null,
1330
+ pushdown_filters: init.pushdown_filters ?? null,
1331
+ join_keys: init.join_keys ?? null,
1332
+ split_tokens: init.split_tokens ?? null,
1333
+ row_limit: init.row_limit ?? null,
1334
+ phase: init.phase ?? null,
1335
+ finalize_state_id: init.finalize_state_id ?? null,
1336
+ execution_id: init.execution_id ?? null,
1337
+ init_opaque_data: init.init_opaque_data ?? null,
1338
+ substream_id: init.substream_id ?? null,
1339
+ order_by_column_name: init.order_by_column_name ?? null,
1340
+ order_by_direction: init.order_by_direction ?? null,
1341
+ order_by_null_order: init.order_by_null_order ?? null,
1342
+ order_by_limit: init.order_by_limit ?? null,
1343
+ tablesample_percentage: init.tablesample_percentage ?? null,
1344
+ tablesample_seed: init.tablesample_seed ?? null,
1345
+ };
1346
+ }
1347
+
1348
+ /** Encode a `InitRequest`; each nested record is written as its wrapper's held bytes, never re-serialized. */
1349
+ export function encodeInitRequest(v: InitRequest): Uint8Array {
1350
+ return encodeASD(InitRequestSchema, {
1351
+ ...v,
1352
+ bind_call: v.bind_call.bytes,
1353
+ });
1354
+ }
1355
+
1356
+ /** Decode a `InitRequest`; each nested record is held as received and decoded only when accessed. */
1357
+ export function decodeInitRequest(b: Uint8Array): InitRequest {
1358
+ const raw = decodeASD<Record<string, any>>(InitRequestSchema, b);
1359
+ return {
1360
+ ...raw,
1361
+ bind_call: Nested.fromBytes(raw.bind_call, decodeBindRequest, "InitRequest.bind_call"),
1362
+ } as InitRequest;
1363
+ }
1364
+
1365
+ // ----------------------------------------------------------------------------
1366
+ // TableFunctionCardinalityRequest (schema: TableFunctionCardinalityRequestSchema)
1367
+ // ----------------------------------------------------------------------------
1368
+
1369
+ /** Consolidated request for table function cardinality. */
1370
+ export interface TableFunctionCardinalityRequest {
1371
+ /** The originating `BindRequest` (function name, arguments, schemas). */
1372
+ bind_call: Nested<BindRequest>;
1373
+ /** Opaque per-bind state the worker returned from bind(), threaded back into later calls (same contract as `InitRequest.bind_opaque_data`). */
1374
+ bind_opaque_data?: Uint8Array | null;
1375
+ }
1376
+
1377
+ /** Fields of `TableFunctionCardinalityRequest` that have a protocol default. */
1378
+ export type TableFunctionCardinalityRequestDefaultedField =
1379
+ | "bind_opaque_data";
1380
+ /** `TableFunctionCardinalityRequest` with every field that has a protocol default optional. */
1381
+ export type TableFunctionCardinalityRequestInit = Omit<TableFunctionCardinalityRequest, TableFunctionCardinalityRequestDefaultedField> & Partial<Pick<TableFunctionCardinalityRequest, TableFunctionCardinalityRequestDefaultedField>>;
1382
+
1383
+ /** Build a complete `TableFunctionCardinalityRequest`, filling the protocol defaults, in wire order. */
1384
+ export function buildTableFunctionCardinalityRequest(init: TableFunctionCardinalityRequestInit): TableFunctionCardinalityRequest {
1385
+ return {
1386
+ bind_call: init.bind_call,
1387
+ bind_opaque_data: init.bind_opaque_data ?? null,
1388
+ };
1389
+ }
1390
+
1391
+ /** Encode a `TableFunctionCardinalityRequest`; each nested record is written as its wrapper's held bytes, never re-serialized. */
1392
+ export function encodeTableFunctionCardinalityRequest(v: TableFunctionCardinalityRequest): Uint8Array {
1393
+ return encodeASD(TableFunctionCardinalityRequestSchema, {
1394
+ ...v,
1395
+ bind_call: v.bind_call.bytes,
1396
+ });
1397
+ }
1398
+
1399
+ /** Decode a `TableFunctionCardinalityRequest`; each nested record is held as received and decoded only when accessed. */
1400
+ export function decodeTableFunctionCardinalityRequest(b: Uint8Array): TableFunctionCardinalityRequest {
1401
+ const raw = decodeASD<Record<string, any>>(TableFunctionCardinalityRequestSchema, b);
1402
+ return {
1403
+ ...raw,
1404
+ bind_call: Nested.fromBytes(raw.bind_call, decodeBindRequest, "TableFunctionCardinalityRequest.bind_call"),
1405
+ } as TableFunctionCardinalityRequest;
1406
+ }
1407
+
1408
+ // ----------------------------------------------------------------------------
1409
+ // TableFunctionStatisticsRequest (schema: TableFunctionStatisticsRequestSchema)
1410
+ // ----------------------------------------------------------------------------
1411
+
1412
+ /** Consolidated request for table function per-column statistics. Mirrors `TableFunctionCardinalityRequest`: the worker receives a full copy of the original `BindRequest` (including parsed `Arguments`), so it can derive per-column stats from the user-supplied args. */
1413
+ export interface TableFunctionStatisticsRequest {
1414
+ /** The originating `BindRequest` (function name, arguments, schemas). */
1415
+ bind_call: Nested<BindRequest>;
1416
+ /** Opaque per-bind state the worker returned from bind(), threaded back into later calls (same contract as `InitRequest.bind_opaque_data`). */
1417
+ bind_opaque_data?: Uint8Array | null;
1418
+ }
1419
+
1420
+ /** Fields of `TableFunctionStatisticsRequest` that have a protocol default. */
1421
+ export type TableFunctionStatisticsRequestDefaultedField =
1422
+ | "bind_opaque_data";
1423
+ /** `TableFunctionStatisticsRequest` with every field that has a protocol default optional. */
1424
+ export type TableFunctionStatisticsRequestInit = Omit<TableFunctionStatisticsRequest, TableFunctionStatisticsRequestDefaultedField> & Partial<Pick<TableFunctionStatisticsRequest, TableFunctionStatisticsRequestDefaultedField>>;
1425
+
1426
+ /** Build a complete `TableFunctionStatisticsRequest`, filling the protocol defaults, in wire order. */
1427
+ export function buildTableFunctionStatisticsRequest(init: TableFunctionStatisticsRequestInit): TableFunctionStatisticsRequest {
1428
+ return {
1429
+ bind_call: init.bind_call,
1430
+ bind_opaque_data: init.bind_opaque_data ?? null,
1431
+ };
1432
+ }
1433
+
1434
+ /** Encode a `TableFunctionStatisticsRequest`; each nested record is written as its wrapper's held bytes, never re-serialized. */
1435
+ export function encodeTableFunctionStatisticsRequest(v: TableFunctionStatisticsRequest): Uint8Array {
1436
+ return encodeASD(TableFunctionStatisticsRequestSchema, {
1437
+ ...v,
1438
+ bind_call: v.bind_call.bytes,
1439
+ });
1440
+ }
1441
+
1442
+ /** Decode a `TableFunctionStatisticsRequest`; each nested record is held as received and decoded only when accessed. */
1443
+ export function decodeTableFunctionStatisticsRequest(b: Uint8Array): TableFunctionStatisticsRequest {
1444
+ const raw = decodeASD<Record<string, any>>(TableFunctionStatisticsRequestSchema, b);
1445
+ return {
1446
+ ...raw,
1447
+ bind_call: Nested.fromBytes(raw.bind_call, decodeBindRequest, "TableFunctionStatisticsRequest.bind_call"),
1448
+ } as TableFunctionStatisticsRequest;
1449
+ }
1450
+
1451
+ // ----------------------------------------------------------------------------
1452
+ // TableFunctionDynamicToStringRequest (schema: TableFunctionDynamicToStringRequestSchema)
1453
+ // ----------------------------------------------------------------------------
1454
+
1455
+ /** Post-execution profile-info request, fired once per scan thread. Carries `global_execution_id` so the function class can retrieve whatever diagnostics it persisted during `process()` (shared storage, external service, in-memory class state for single-worker setups, etc.). VGI does not serialize per-thread `_user_state` across the boundary — the user owns persistence. */
1456
+ export interface TableFunctionDynamicToStringRequest {
1457
+ /** The originating `BindRequest` (function name, arguments, schemas). */
1458
+ bind_call: Nested<BindRequest>;
1459
+ /** Opaque per-bind state the worker returned from bind(), threaded back into later calls (same contract as `InitRequest.bind_opaque_data`). */
1460
+ bind_opaque_data?: Uint8Array | null;
1461
+ /** Query-wide execution id under which the function persisted the diagnostics this RPC retrieves. */
1462
+ global_execution_id: Uint8Array;
1463
+ }
1464
+
1465
+ /** Fields of `TableFunctionDynamicToStringRequest` that have a protocol default. */
1466
+ export type TableFunctionDynamicToStringRequestDefaultedField =
1467
+ | "bind_opaque_data";
1468
+ /** `TableFunctionDynamicToStringRequest` with every field that has a protocol default optional. */
1469
+ export type TableFunctionDynamicToStringRequestInit = Omit<TableFunctionDynamicToStringRequest, TableFunctionDynamicToStringRequestDefaultedField> & Partial<Pick<TableFunctionDynamicToStringRequest, TableFunctionDynamicToStringRequestDefaultedField>>;
1470
+
1471
+ /** Build a complete `TableFunctionDynamicToStringRequest`, filling the protocol defaults, in wire order. */
1472
+ export function buildTableFunctionDynamicToStringRequest(init: TableFunctionDynamicToStringRequestInit): TableFunctionDynamicToStringRequest {
1473
+ return {
1474
+ bind_call: init.bind_call,
1475
+ bind_opaque_data: init.bind_opaque_data ?? null,
1476
+ global_execution_id: init.global_execution_id,
1477
+ };
1478
+ }
1479
+
1480
+ /** Encode a `TableFunctionDynamicToStringRequest`; each nested record is written as its wrapper's held bytes, never re-serialized. */
1481
+ export function encodeTableFunctionDynamicToStringRequest(v: TableFunctionDynamicToStringRequest): Uint8Array {
1482
+ return encodeASD(TableFunctionDynamicToStringRequestSchema, {
1483
+ ...v,
1484
+ bind_call: v.bind_call.bytes,
1485
+ });
1486
+ }
1487
+
1488
+ /** Decode a `TableFunctionDynamicToStringRequest`; each nested record is held as received and decoded only when accessed. */
1489
+ export function decodeTableFunctionDynamicToStringRequest(b: Uint8Array): TableFunctionDynamicToStringRequest {
1490
+ const raw = decodeASD<Record<string, any>>(TableFunctionDynamicToStringRequestSchema, b);
1491
+ return {
1492
+ ...raw,
1493
+ bind_call: Nested.fromBytes(raw.bind_call, decodeBindRequest, "TableFunctionDynamicToStringRequest.bind_call"),
1494
+ } as TableFunctionDynamicToStringRequest;
1495
+ }
1496
+
1497
+ // ----------------------------------------------------------------------------
1498
+ // TableFunctionPlanRequest (schema: TableFunctionPlanRequestSchema)
1499
+ // ----------------------------------------------------------------------------
1500
+
1501
+ /** Request for the scan-planning phase that precedes per-split `init()`. `plan()` runs once with the pushdown filters and returns named splits; each split is then redeemed by `init()` from any process or host. This is what makes the scan sound in a distributed engine, where a retried task must be able to re-request exactly the work it was given. */
1502
+ export interface TableFunctionPlanRequest {
1503
+ /** The originating `BindRequest`. */
1504
+ bind_call: Nested<BindRequest>;
1505
+ /** Opaque per-bind state the worker returned from bind(). */
1506
+ bind_opaque_data?: Uint8Array | null;
1507
+ /** Column indices the client wants projected. */
1508
+ projection_ids?: number[] | null;
1509
+ /** Serialized filter predicates. */
1510
+ pushdown_filters?: Uint8Array | null;
1511
+ /** Serialized join-key batches pushed down for join filtering. */
1512
+ join_keys?: Uint8Array[] | null;
1513
+ /** Plain fetch limit. NOT `order_by_limit` (which is a field of the Top-N hint). DuckDB cannot supply this — `TableFunctionInitInput` has no limit field — so it is always `None` from DuckDB; DataFusion supplies it from `TableProvider::scan(limit)`. */
1514
+ row_limit?: number | null;
1515
+ /** Requested split size. The primary sizing lever: a worker should emit splits of comparable cost, because the client cannot see per-split cost and will claim them as interchangeable units. */
1516
+ target_split_bytes?: number | null;
1517
+ /** Parallelism floor — a small but expensive table still needs enough splits to occupy the client's readers. */
1518
+ min_splits?: number | null;
1519
+ /** Pagination cap (Trino `getNextBatch(maxSize)`), NOT a sizing hint. */
1520
+ max_splits_per_response?: number | null;
1521
+ /** Resume point in the *enumeration of splits*. Distinct from `start_position`, which names a place in the *data*. */
1522
+ cursor?: Uint8Array | null;
1523
+ /** Conjunctive narrowing on a continuation. Narrows future splits only; splits already emitted under a looser filter stay valid. */
1524
+ refined_filters?: Uint8Array | null;
1525
+ /** False means more refinement may arrive, so the worker may hold back splits; True says stop waiting. */
1526
+ filters_complete: boolean;
1527
+ /** Exclusive lower bound in the data; `None` = from the start. */
1528
+ start_position?: Uint8Array | null;
1529
+ /** Inclusive upper bound; `None` = "as of now", and the worker reports the frontier it resolved in `PlanResponse.end_position`. */
1530
+ end_position?: Uint8Array | null;
1531
+ /** Column of the order-pushdown hint. */
1532
+ order_by_column_name?: string | null;
1533
+ /** Direction of the order-pushdown hint. */
1534
+ order_by_direction?: string | null;
1535
+ /** Null ordering of the order-pushdown hint. */
1536
+ order_by_null_order?: string | null;
1537
+ /** Row limit of the Top-N order-pushdown hint. */
1538
+ order_by_limit?: number | null;
1539
+ /** TABLESAMPLE percentage hint. */
1540
+ tablesample_percentage?: number | null;
1541
+ /** TABLESAMPLE seed hint. */
1542
+ tablesample_seed?: number | null;
1543
+ }
1544
+
1545
+ /** Fields of `TableFunctionPlanRequest` that have a protocol default. */
1546
+ export type TableFunctionPlanRequestDefaultedField =
1547
+ | "bind_opaque_data"
1548
+ | "projection_ids"
1549
+ | "pushdown_filters"
1550
+ | "join_keys"
1551
+ | "row_limit"
1552
+ | "target_split_bytes"
1553
+ | "min_splits"
1554
+ | "max_splits_per_response"
1555
+ | "cursor"
1556
+ | "refined_filters"
1557
+ | "filters_complete"
1558
+ | "start_position"
1559
+ | "end_position"
1560
+ | "order_by_column_name"
1561
+ | "order_by_direction"
1562
+ | "order_by_null_order"
1563
+ | "order_by_limit"
1564
+ | "tablesample_percentage"
1565
+ | "tablesample_seed";
1566
+ /** `TableFunctionPlanRequest` with every field that has a protocol default optional. */
1567
+ export type TableFunctionPlanRequestInit = Omit<TableFunctionPlanRequest, TableFunctionPlanRequestDefaultedField> & Partial<Pick<TableFunctionPlanRequest, TableFunctionPlanRequestDefaultedField>>;
1568
+
1569
+ /** Build a complete `TableFunctionPlanRequest`, filling the protocol defaults, in wire order. */
1570
+ export function buildTableFunctionPlanRequest(init: TableFunctionPlanRequestInit): TableFunctionPlanRequest {
1571
+ return {
1572
+ bind_call: init.bind_call,
1573
+ bind_opaque_data: init.bind_opaque_data ?? null,
1574
+ projection_ids: init.projection_ids ?? null,
1575
+ pushdown_filters: init.pushdown_filters ?? null,
1576
+ join_keys: init.join_keys ?? null,
1577
+ row_limit: init.row_limit ?? null,
1578
+ target_split_bytes: init.target_split_bytes ?? null,
1579
+ min_splits: init.min_splits ?? null,
1580
+ max_splits_per_response: init.max_splits_per_response ?? null,
1581
+ cursor: init.cursor ?? null,
1582
+ refined_filters: init.refined_filters ?? null,
1583
+ filters_complete: init.filters_complete ?? true,
1584
+ start_position: init.start_position ?? null,
1585
+ end_position: init.end_position ?? null,
1586
+ order_by_column_name: init.order_by_column_name ?? null,
1587
+ order_by_direction: init.order_by_direction ?? null,
1588
+ order_by_null_order: init.order_by_null_order ?? null,
1589
+ order_by_limit: init.order_by_limit ?? null,
1590
+ tablesample_percentage: init.tablesample_percentage ?? null,
1591
+ tablesample_seed: init.tablesample_seed ?? null,
1592
+ };
1593
+ }
1594
+
1595
+ /** Encode a `TableFunctionPlanRequest`; each nested record is written as its wrapper's held bytes, never re-serialized. */
1596
+ export function encodeTableFunctionPlanRequest(v: TableFunctionPlanRequest): Uint8Array {
1597
+ return encodeASD(TableFunctionPlanRequestSchema, {
1598
+ ...v,
1599
+ bind_call: v.bind_call.bytes,
1600
+ });
1601
+ }
1602
+
1603
+ /** Decode a `TableFunctionPlanRequest`; each nested record is held as received and decoded only when accessed. */
1604
+ export function decodeTableFunctionPlanRequest(b: Uint8Array): TableFunctionPlanRequest {
1605
+ const raw = decodeASD<Record<string, any>>(TableFunctionPlanRequestSchema, b);
1606
+ return {
1607
+ ...raw,
1608
+ bind_call: Nested.fromBytes(raw.bind_call, decodeBindRequest, "TableFunctionPlanRequest.bind_call"),
1609
+ } as TableFunctionPlanRequest;
1610
+ }
1611
+
1612
+ // ----------------------------------------------------------------------------
1613
+ // TableFunctionProjectionRequest (schema: TableFunctionProjectionRequestSchema)
1614
+ // ----------------------------------------------------------------------------
1615
+
1616
+ /** Propose pure scalar outputs after bind, before modifying an execution plan. Expressions address the complete original worker output schema. Their result fields are parallel by index; accepted fields append to that schema. Planning allocates no execution resources and cannot consume rows or produce effects. */
1617
+ export interface TableFunctionProjectionRequest {
1618
+ bind_call: Nested<BindRequest>;
1619
+ bind_result: Uint8Array;
1620
+ expressions: Uint8Array[];
1621
+ result_schema: Uint8Array;
1622
+ }
1623
+
1624
+ /** `TableFunctionProjectionRequest` has no defaulted fields, so its init is the record itself. */
1625
+ export type TableFunctionProjectionRequestInit = TableFunctionProjectionRequest;
1626
+
1627
+ /** Build a complete `TableFunctionProjectionRequest`, filling the protocol defaults, in wire order. */
1628
+ export function buildTableFunctionProjectionRequest(init: TableFunctionProjectionRequestInit): TableFunctionProjectionRequest {
1629
+ return {
1630
+ bind_call: init.bind_call,
1631
+ bind_result: init.bind_result,
1632
+ expressions: init.expressions,
1633
+ result_schema: init.result_schema,
1634
+ };
1635
+ }
1636
+
1637
+ /** Encode a `TableFunctionProjectionRequest`; each nested record is written as its wrapper's held bytes, never re-serialized. */
1638
+ export function encodeTableFunctionProjectionRequest(v: TableFunctionProjectionRequest): Uint8Array {
1639
+ return encodeASD(TableFunctionProjectionRequestSchema, {
1640
+ ...v,
1641
+ bind_call: v.bind_call.bytes,
1642
+ });
1643
+ }
1644
+
1645
+ /** Decode a `TableFunctionProjectionRequest`; each nested record is held as received and decoded only when accessed. */
1646
+ export function decodeTableFunctionProjectionRequest(b: Uint8Array): TableFunctionProjectionRequest {
1647
+ const raw = decodeASD<Record<string, any>>(TableFunctionProjectionRequestSchema, b);
1648
+ return {
1649
+ ...raw,
1650
+ bind_call: Nested.fromBytes(raw.bind_call, decodeBindRequest, "TableFunctionProjectionRequest.bind_call"),
1651
+ } as TableFunctionProjectionRequest;
1652
+ }
1653
+
1017
1654
  // ----------------------------------------------------------------------------
1018
1655
  // CatalogAttachResult (schema: CatalogAttachResultSchema)
1019
1656
  // ----------------------------------------------------------------------------