@query-farm/vgi 0.45.0 → 0.46.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.
@@ -0,0 +1,69 @@
1
+ import type { OutputCollector } from "@query-farm/vgi-rpc";
2
+ import type { VgiBatch } from "../arrow/index.js";
3
+ /** Metadata key carrying a table-in-out exchange status, on the batch itself. */
4
+ export declare const STATUS_KEY = "vgi.status";
5
+ /** Reply status: this input has more output; ask for it with a tick. */
6
+ export declare const HAVE_MORE_OUTPUT = "HAVE_MORE_OUTPUT";
7
+ /** Input status: a continuation tick, asking for the last input's next reply. */
8
+ export declare const CONTINUE = "CONTINUE";
9
+ /**
10
+ * Mark an emitted table-in-out reply as one of several for the same input
11
+ * batch when `more` is true: the client asks for the next one with a
12
+ * continuation tick, which the framework answers through the function's
13
+ * `resume()`. `false` adds nothing, so the last reply can pass its own
14
+ * condition. Composes with {@link parentRowsMetadata} and
15
+ * `cacheControlMetadata` via `extra`:
16
+ *
17
+ * ```ts
18
+ * out.emit(batch, moreOutputMetadata(state.row < state.counts.length,
19
+ * parentRowsMetadata(parents, batch.numRows)));
20
+ * ```
21
+ *
22
+ * Valid only from the `process()` or `resume()` of a table-in-out function
23
+ * that implements `resume()`; the framework reads it off the emitted reply.
24
+ */
25
+ export declare function moreOutputMetadata(more: boolean, extra?: Map<string, string>): Map<string, string>;
26
+ /**
27
+ * Refuse "more" on a stream that cannot continue: anything but a table-in-out
28
+ * exchange, where the client would never send the tick. Run by the dispatcher
29
+ * after every non-table-in-out turn.
30
+ */
31
+ export declare function refuseMoreOutput(name: string, out: OutputCollector): void;
32
+ /** The exchange state a continuable table-in-out turn reads and updates. */
33
+ export interface ContinuationState {
34
+ /**
35
+ * Whether the last reply said HAVE_MORE_OUTPUT, so the next input must be a
36
+ * tick. Carried in the HTTP state token (see protocol/state-serializer.ts).
37
+ */
38
+ morePending?: boolean;
39
+ }
40
+ /**
41
+ * Run one table-in-out exchange turn under the continued-output rules.
42
+ *
43
+ * Classifies the input (a tick or real input), refuses the inputs the protocol
44
+ * forbids, calls `run(tick)` -- which calls `process()` for real input and
45
+ * `resume()` for a tick -- and records from the emitted reply whether output is
46
+ * now pending.
47
+ *
48
+ * `resumable` is whether the function implements `resume()`: one that does not
49
+ * may not say more.
50
+ */
51
+ export declare function continuationTurn(name: string, eState: ContinuationState, input: VgiBatch, out: OutputCollector, resumable: boolean, run: (tick: boolean) => Promise<void>): Promise<void>;
52
+ /**
53
+ * Refuse, at definition, a continuable function the client cannot drive.
54
+ *
55
+ * `resume()` continues from the function's state alone, so it needs an
56
+ * `initialState` (the state is what the HTTP token carries between turns).
57
+ * `maxWorkers: 1` runs the function on one connection shared by every
58
+ * pipeline, which cannot leave output pending while another's input waits.
59
+ */
60
+ export declare function checkResumeContract(name: string, config: {
61
+ resume?: unknown;
62
+ initialState?: unknown;
63
+ maxWorkers?: number;
64
+ }): void;
65
+ /**
66
+ * Check `inputRowsPerCall`: a positive integer, on a blended row-transform
67
+ * function only (the extension refuses it at bind too).
68
+ */
69
+ export declare function checkInputRowsPerCall(name: string, value: unknown, blended: boolean): number | undefined;
@@ -6,6 +6,7 @@ import type { ArgumentConstraints } from "../arguments/argument-spec.js";
6
6
  import { type PushdownFilters } from "../filter-pushdown/index.js";
7
7
  import { FunctionStability } from "../types.js";
8
8
  import { BoundStorage } from "./storage.js";
9
+ import { PARENT_ROW_METADATA_KEY } from "../util/parent-rows.js";
9
10
  export interface TableInOutBindParams<TArgs = Record<string, any>> {
10
11
  args: TArgs;
11
12
  bindCall: BindRequest;
@@ -80,6 +81,22 @@ export interface TableInOutConfig<TArgs = Record<string, any>, TState = null> {
80
81
  initialState?: (params: TableInOutProcessParams<TArgs>) => TState;
81
82
  /** Process: transform input batch, emit output via out */
82
83
  process?: (params: TableInOutProcessParams<TArgs>, state: TState, batch: VgiBatch, out: OutputCollector) => void | Promise<void>;
84
+ /**
85
+ * Resume: emit the next reply for the last input batch (continued output).
86
+ *
87
+ * One input batch can produce several replies: `process()` emits the first
88
+ * with {@link moreOutputMetadata}`(true)`, and the framework then calls
89
+ * `resume()`, with no input, for each next reply until one is emitted
90
+ * without it. Like `process()`, each call emits exactly one batch.
91
+ *
92
+ * `resume()` continues from `state` alone, so a function that defines it
93
+ * must define `initialState`. Mutate the state in place: it survives between
94
+ * calls on every transport -- over HTTP inside the stream's state token -- so
95
+ * keep it small (positions to resume from, never buffered output). Not
96
+ * allowed with `maxWorkers: 1`, which runs on one connection shared by every
97
+ * pipeline and so cannot leave output pending.
98
+ */
99
+ resume?: (params: TableInOutProcessParams<TArgs>, state: TState, out: OutputCollector) => void | Promise<void>;
83
100
  /** Finalize: emit final batches after all input processed.
84
101
  * Receives all worker states collected from storage (matches Python's finish(params, states)). */
85
102
  finalize?: (params: TableInOutProcessParams<TArgs>, states: TState[]) => VgiBatch[] | Promise<VgiBatch[]>;
@@ -95,10 +112,7 @@ export interface TableInOutConfig<TArgs = Record<string, any>, TState = null> {
95
112
  requiredSecrets?: string[];
96
113
  }
97
114
  export declare function defineTableInOutFunction<TArgs = Record<string, any>, TState = null>(config: TableInOutConfig<TArgs, TState>): VgiFunction;
98
- /** Metadata key carrying per-output-row provenance: base64 of a raw
99
- * little-endian int32[] mapping each output row to the input row that
100
- * produced it. Shared by string with the C++ extension and vgi-python. */
101
- export declare const PARENT_ROW_METADATA_KEY = "vgi_rpc.parent_row#b64";
115
+ export { PARENT_ROW_METADATA_KEY };
102
116
  /**
103
117
  * Fold per-output-row provenance into an emit metadata map.
104
118
  *
@@ -128,7 +142,7 @@ export declare function parentRowsMetadata(parentRows: number[], outputRows: num
128
142
  * positionally for varargs).
129
143
  */
130
144
  export type RowTransformProcessParams<TArgs = Record<string, any>> = TableInOutProcessParams<TArgs>;
131
- export interface RowTransformConfig<TArgs = Record<string, any>> {
145
+ export interface RowTransformConfig<TArgs = Record<string, any>, TState = null> {
132
146
  name: string;
133
147
  description?: string;
134
148
  /**
@@ -176,8 +190,38 @@ export interface RowTransformConfig<TArgs = Record<string, any>> {
176
190
  * per-row map (DuckDB forbids FinalExecute under correlated LATERAL, one of
177
191
  * the call shapes blended must serve). Accumulating functions use a classic
178
192
  * TableInput table-in-out or a TableBufferingFunction.
193
+ *
194
+ * `state` is the stream's state from {@link initialState} (`null` without
195
+ * one); a function that continues its output keeps its resume position there.
196
+ */
197
+ process: (params: RowTransformProcessParams<TArgs>, batch: VgiBatch, out: OutputCollector, state: TState) => void | Promise<void>;
198
+ /**
199
+ * The stream's initial state, needed only by a function with {@link resume}:
200
+ * where the next reply resumes. Mutate it in place; it survives between
201
+ * calls on every transport (over HTTP inside the stream's state token), so
202
+ * keep it small: positions to resume from, never buffered output rows.
203
+ */
204
+ initialState?: (params: RowTransformProcessParams<TArgs>) => TState;
205
+ /**
206
+ * Continued output: emit the next reply for the last input batch.
207
+ *
208
+ * Large output for one input batch (an upstream API paged across many
209
+ * requests) need not be built into one batch: `process()` emits the first
210
+ * reply with {@link moreOutputMetadata}`(true)`, and the framework calls
211
+ * `resume()`, with no input, for each next reply until one is emitted
212
+ * without it. Each call emits exactly one batch, whose parent rows index the
213
+ * input batch `process()` received. Requires {@link initialState}; not
214
+ * allowed with `maxWorkers: 1`.
215
+ */
216
+ resume?: (params: RowTransformProcessParams<TArgs>, state: TState, out: OutputCollector) => void | Promise<void>;
217
+ /**
218
+ * The most input rows one worker call receives: the client's batched-LATERAL
219
+ * operator splits each input chunk (after dedup) into calls of at most this
220
+ * many rows, in order. Unset sends a whole chunk per call. A positive
221
+ * integer. Surfaces as `FunctionInfo.input_rows_per_call`; mirrors
222
+ * vgi-python's `Meta.input_rows_per_call`.
179
223
  */
180
- process: (params: RowTransformProcessParams<TArgs>, batch: VgiBatch, out: OutputCollector) => void | Promise<void>;
224
+ inputRowsPerCall?: number;
181
225
  projectionPushdown?: boolean;
182
226
  filterPushdown?: boolean;
183
227
  autoApplyFilters?: boolean;
@@ -200,4 +244,4 @@ export interface RowTransformConfig<TArgs = Record<string, any>> {
200
244
  * the worker's overload resolution matches blended overloads by INPUT-COLUMN
201
245
  * count (the positional args are not on the wire). Map-shaped, no finalize.
202
246
  */
203
- export declare function defineRowTransformFunction<TArgs = Record<string, any>>(config: RowTransformConfig<TArgs>): VgiFunction;
247
+ export declare function defineRowTransformFunction<TArgs = Record<string, any>, TState = null>(config: RowTransformConfig<TArgs, TState>): VgiFunction;
@@ -13,6 +13,12 @@ export interface HandlerState<T = any> {
13
13
  * rebuilds the filters this one left.
14
14
  */
15
15
  filterHistory?: import("../filter-pushdown/history.js").FilterDeltaHistory;
16
+ /**
17
+ * A table-in-out exchange's continued-output flag: the last reply said
18
+ * HAVE_MORE_OUTPUT, so the next input must be a continuation tick. Carried
19
+ * in the HTTP cursor like `filterHistory`.
20
+ */
21
+ morePending?: boolean;
16
22
  [key: string]: any;
17
23
  }
18
24
  export interface FunctionExample {
@@ -86,6 +92,13 @@ export interface FunctionMeta {
86
92
  * ResolvedMetadata.input_from_args.
87
93
  */
88
94
  inputFromArgs?: boolean;
95
+ /**
96
+ * Blended only: the most input rows one worker call receives; the client
97
+ * splits each input chunk into calls of at most this many rows. Unset sends
98
+ * a whole chunk per call. Set by {@link defineRowTransformFunction}'s
99
+ * `inputRowsPerCall`; surfaces as FunctionInfo.input_rows_per_call.
100
+ */
101
+ inputRowsPerCall?: number;
89
102
  /**
90
103
  * table_buffering: force ParallelSink=false in the C++ operator
91
104
  * (single-thread, source-ordered ingest).
@@ -190,6 +203,13 @@ export interface StreamHandlers {
190
203
  * from DuckDB's Top-N optimizer).
191
204
  */
192
205
  onTick?: (state: any, tickMetadata: Map<string, string> | undefined) => void | Promise<void>;
206
+ /**
207
+ * A table-in-out exchange, which may continue one input's output across
208
+ * replies (see functions/continuation.ts). It keeps `morePending` on its
209
+ * handler state, which the dispatcher carries in the HTTP state token. Every
210
+ * other stream's reply is refused if it says HAVE_MORE_OUTPUT.
211
+ */
212
+ continuesOutput?: boolean;
193
213
  }
194
214
  /**
195
215
  * A resolved, registered VGI function definition.
@@ -129,6 +129,7 @@ export interface FunctionInfo {
129
129
  sink_order_dependent: boolean;
130
130
  requires_input_batch_index: boolean;
131
131
  input_from_args: boolean;
132
+ input_rows_per_call?: number | null;
132
133
  required_settings: string[];
133
134
  required_secrets: SecretLookupEntry[];
134
135
  }
@@ -1,5 +1,5 @@
1
1
  /** Canonical fingerprint of the nested catalog wire schemas. */
2
- export declare const VGI_CATALOG_CONTRACT_HASH = "121e8fe1c074bce00a6d0fcec49d7a90f05e45498cd9ca8a5a3b4a9ae2377a2d";
2
+ export declare const VGI_CATALOG_CONTRACT_HASH = "0aa39285365f5f4326ce85c4d41d2705ea992dee41cf98d07640a2767b6ac3fb";
3
3
  export declare const CatalogInfoSchema: import("../index.core.js").VgiSchema;
4
4
  export declare const SchemaInfoSchema: import("../index.core.js").VgiSchema;
5
5
  export declare const TableInfoSchema: import("../index.core.js").VgiSchema;
@@ -3,6 +3,7 @@ export { defineScalarFunction, type ScalarFunctionConfig, type ScalarBindParamet
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";
5
5
  export { defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, type TableInOutConfig, type TableInOutBindParams, type TableInOutProcessParams, type RowTransformConfig, type RowTransformProcessParams, } from "./functions/table-in-out.js";
6
+ export { moreOutputMetadata, STATUS_KEY, HAVE_MORE_OUTPUT, CONTINUE, } from "./functions/continuation.js";
6
7
  export { defineTableBufferingFunction, type TableBufferingConfig, type TableBufferingBindParams, type TableBufferingParams, type TableBufferingVgiFunction, } from "./functions/table-buffering.js";
7
8
  export { defineCopyFromFunction, type CopyFromFunctionConfig, type CopyFromOption, type CopyFromReadParams, } from "./functions/copy-from.js";
8
9
  export { defineCopyToFunction, type CopyToFunctionConfig, type CopyToOption, type CopyToWriteParams, type CopyToCloseParams, } from "./functions/copy-to.js";