@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.
- package/README.md +8 -1
- package/dist/arrow/impl-flechette/canonical.d.ts +1 -1
- package/dist/arrow/impl-flechette/schema.d.ts +19 -5
- package/dist/client/client.d.ts +20 -1
- package/dist/client-entry.js +54 -13
- package/dist/client-entry.js.map +8 -6
- package/dist/functions/continuation.d.ts +69 -0
- package/dist/functions/table-in-out.d.ts +51 -7
- package/dist/functions/types.d.ts +20 -0
- package/dist/generated/vgi-client.d.ts +1 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +1 -1
- package/dist/index.core.d.ts +1 -0
- package/dist/index.js +244 -59
- package/dist/index.js.map +14 -12
- package/dist/serve-entry.js +35 -5
- package/dist/serve-entry.js.map +8 -7
- package/dist/util/parent-rows.d.ts +8 -0
- package/dist/worker-cf-entry.d.ts +1 -1
- package/dist/worker-cf-entry.js +197 -47
- package/dist/worker-cf-entry.js.map +14 -12
- package/package.json +4 -4
- package/src/arrow/impl-flechette/canonical.ts +7 -5
- package/src/catalog/read-only.ts +6 -0
- package/src/client/client.ts +80 -11
- package/src/filter-pushdown/collector.ts +17 -1
- package/src/functions/continuation.ts +202 -0
- package/src/functions/table-in-out.ts +131 -56
- package/src/functions/types.ts +20 -0
- package/src/generated/vgi-client.ts +2 -1
- package/src/generated/vgi-protocol-schemas.ts +3 -2
- package/src/index.core.ts +6 -0
- package/src/protocol/handlers/function.ts +12 -0
- package/src/protocol/state-serializer.ts +7 -1
- package/src/util/parent-rows.ts +41 -0
- package/src/worker-cf-entry.ts +3 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Metadata key carrying per-output-row provenance: base64 of a raw
|
|
2
|
+
* little-endian int32[] mapping each output row to the input row that
|
|
3
|
+
* produced it. Shared by string with the C++ extension and vgi-python. */
|
|
4
|
+
export declare const PARENT_ROW_METADATA_KEY = "vgi_rpc.parent_row#b64";
|
|
5
|
+
/** Encode parent-row indices as the wire's base64 little-endian int32[]. */
|
|
6
|
+
export declare function encodeParentRows(parentRows: ArrayLike<number>): string;
|
|
7
|
+
/** Decode the wire's base64 little-endian int32[] back into parent-row indices. */
|
|
8
|
+
export declare function decodeParentRows(encoded: string): Int32Array;
|
|
@@ -3,7 +3,7 @@ export type { VgiFetchOptions } from "./http/fetch.js";
|
|
|
3
3
|
export type { HostingOptions } from "./rpc-server.js";
|
|
4
4
|
export { AuthUnavailableError, GrantKeys, GrantRefusedError, IdentityUnavailableError, StatusError, } from "@query-farm/vgi-rpc";
|
|
5
5
|
export type { GrantMinter, IssuedGrant, TokenIdentity, TokenResolver } from "@query-farm/vgi-rpc";
|
|
6
|
-
export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, } from "./index.core.js";
|
|
6
|
+
export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, } from "./index.core.js";
|
|
7
7
|
export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, } from "./index.core.js";
|
|
8
8
|
export type { ProtocolConfig } from "./protocol/dispatch.js";
|
|
9
9
|
export type { LandingInfo } from "./http/landing.js";
|
package/dist/worker-cf-entry.js
CHANGED
|
@@ -4676,7 +4676,8 @@ var EXCHANGE_STATE_SCHEMA = schema2([
|
|
|
4676
4676
|
field2("opaque_data", binary2(), true),
|
|
4677
4677
|
field2("is_producer", bool2(), false),
|
|
4678
4678
|
field2("user_state", binary2(), true),
|
|
4679
|
-
field2("filter_history", binary2(), true)
|
|
4679
|
+
field2("filter_history", binary2(), true),
|
|
4680
|
+
field2("more_pending", bool2(), false)
|
|
4680
4681
|
]);
|
|
4681
4682
|
var TEXT_ENCODER = new TextEncoder;
|
|
4682
4683
|
var TEXT_DECODER = new TextDecoder;
|
|
@@ -4685,6 +4686,7 @@ var FLAG_PRODUCER = 1;
|
|
|
4685
4686
|
var FLAG_OPAQUE_DATA = 2;
|
|
4686
4687
|
var FLAG_USER_STATE = 4;
|
|
4687
4688
|
var FLAG_FILTER_HISTORY = 8;
|
|
4689
|
+
var FLAG_MORE_PENDING = 16;
|
|
4688
4690
|
var LIST_CHILD_NAME = "item";
|
|
4689
4691
|
var emptyListElementType = () => utf82();
|
|
4690
4692
|
function inferElementType(values) {
|
|
@@ -4790,7 +4792,7 @@ var arrowStateSerializer = {
|
|
|
4790
4792
|
const opaqueData = state.opaqueData != null ? toUint8Array(state.opaqueData) : null;
|
|
4791
4793
|
const userState = serializeUserState(state.userState);
|
|
4792
4794
|
const filterHistory = encodeFilterHistory(state.filterHistory);
|
|
4793
|
-
const flags = (state.isProducer ? FLAG_PRODUCER : 0) | (opaqueData ? FLAG_OPAQUE_DATA : 0) | (userState ? FLAG_USER_STATE : 0) | (filterHistory ? FLAG_FILTER_HISTORY : 0);
|
|
4795
|
+
const flags = (state.isProducer ? FLAG_PRODUCER : 0) | (opaqueData ? FLAG_OPAQUE_DATA : 0) | (userState ? FLAG_USER_STATE : 0) | (filterHistory ? FLAG_FILTER_HISTORY : 0) | (state.morePending ? FLAG_MORE_PENDING : 0);
|
|
4794
4796
|
const chunks = [functionName, initRequest, executionId];
|
|
4795
4797
|
if (opaqueData)
|
|
4796
4798
|
chunks.push(opaqueData);
|
|
@@ -4851,7 +4853,8 @@ var arrowStateSerializer = {
|
|
|
4851
4853
|
isProducer,
|
|
4852
4854
|
__isProducer: isProducer,
|
|
4853
4855
|
userState: deserializeUserState(userStateBytes),
|
|
4854
|
-
filterHistory: decodeFilterHistory(filterHistoryBytes)
|
|
4856
|
+
filterHistory: decodeFilterHistory(filterHistoryBytes),
|
|
4857
|
+
morePending: (flags & FLAG_MORE_PENDING) !== 0
|
|
4855
4858
|
};
|
|
4856
4859
|
}
|
|
4857
4860
|
};
|
|
@@ -6114,6 +6117,87 @@ function createVgiProtocol(service) {
|
|
|
6114
6117
|
// src/protocol/handlers/function.ts
|
|
6115
6118
|
init_arrow();
|
|
6116
6119
|
|
|
6120
|
+
// src/functions/continuation.ts
|
|
6121
|
+
var STATUS_KEY = "vgi.status";
|
|
6122
|
+
var HAVE_MORE_OUTPUT = "HAVE_MORE_OUTPUT";
|
|
6123
|
+
var CONTINUE = "CONTINUE";
|
|
6124
|
+
var CACHE_KEY_PREFIX = "vgi.cache.";
|
|
6125
|
+
function moreOutputMetadata(more, extra) {
|
|
6126
|
+
const md = new Map(extra ?? []);
|
|
6127
|
+
if (more)
|
|
6128
|
+
md.set(STATUS_KEY, HAVE_MORE_OUTPUT);
|
|
6129
|
+
return md;
|
|
6130
|
+
}
|
|
6131
|
+
function replyMetadata(out) {
|
|
6132
|
+
const idx = out.dataBatchIdx;
|
|
6133
|
+
if (idx == null)
|
|
6134
|
+
return null;
|
|
6135
|
+
const emitted = out.batches[idx];
|
|
6136
|
+
const md = new Map(emitted.batch.metadata ?? []);
|
|
6137
|
+
for (const [k, v] of emitted.metadata ?? [])
|
|
6138
|
+
md.set(k, v);
|
|
6139
|
+
return md;
|
|
6140
|
+
}
|
|
6141
|
+
function refuseMoreOutput(name, out) {
|
|
6142
|
+
if (replyMetadata(out)?.get(STATUS_KEY) === HAVE_MORE_OUTPUT) {
|
|
6143
|
+
throw new Error(`${name}: HAVE_MORE_OUTPUT (moreOutputMetadata) is only valid in a table-in-out ` + `function's process() or resume()`);
|
|
6144
|
+
}
|
|
6145
|
+
}
|
|
6146
|
+
async function continuationTurn(name, eState, input, out, resumable, run) {
|
|
6147
|
+
const inputStatus = input?.metadata?.get(STATUS_KEY) ?? out.inputMetadata?.get(STATUS_KEY);
|
|
6148
|
+
const tick = inputStatus === CONTINUE;
|
|
6149
|
+
if (tick && !eState.morePending) {
|
|
6150
|
+
throw new Error(`${name}: continuation tick received, but no output is pending`);
|
|
6151
|
+
}
|
|
6152
|
+
if (tick && input.numRows !== 0) {
|
|
6153
|
+
throw new Error(`${name}: a continuation tick must have no rows, got ${input.numRows}`);
|
|
6154
|
+
}
|
|
6155
|
+
if (!tick && eState.morePending) {
|
|
6156
|
+
throw new Error(`${name}: input received while output is pending; expected a continuation tick`);
|
|
6157
|
+
}
|
|
6158
|
+
await run(tick);
|
|
6159
|
+
const md = replyMetadata(out);
|
|
6160
|
+
if (md == null) {
|
|
6161
|
+
throw new Error(tick ? `${name}: resume() must emit a batch for every continuation tick` : `${name}: process() must emit a batch for every input batch (No data batch was emitted)`);
|
|
6162
|
+
}
|
|
6163
|
+
const more = md.get(STATUS_KEY) === HAVE_MORE_OUTPUT;
|
|
6164
|
+
if (more && !resumable) {
|
|
6165
|
+
throw new Error(`${name}: emitted HAVE_MORE_OUTPUT but does not implement resume()`);
|
|
6166
|
+
}
|
|
6167
|
+
if (tick) {
|
|
6168
|
+
for (const key of md.keys()) {
|
|
6169
|
+
if (key.startsWith(CACHE_KEY_PREFIX)) {
|
|
6170
|
+
throw new Error(`${name}: cache control is only valid on an input's first reply, ` + `not on one answering a continuation tick (${key})`);
|
|
6171
|
+
}
|
|
6172
|
+
}
|
|
6173
|
+
}
|
|
6174
|
+
eState.morePending = more;
|
|
6175
|
+
}
|
|
6176
|
+
function checkResumeContract(name, config) {
|
|
6177
|
+
if (config.resume == null)
|
|
6178
|
+
return;
|
|
6179
|
+
if (typeof config.resume !== "function") {
|
|
6180
|
+
throw new Error(`${name}: resume must be a function`);
|
|
6181
|
+
}
|
|
6182
|
+
if (config.maxWorkers === 1) {
|
|
6183
|
+
throw new Error(`${name}: resume() (continued output) is not supported with maxWorkers: 1; ` + `the client runs such a function on one shared connection.`);
|
|
6184
|
+
}
|
|
6185
|
+
if (config.initialState == null) {
|
|
6186
|
+
throw new Error(`${name}: resume() continues from its state alone, so the function must ` + `declare an initialState holding where to resume.`);
|
|
6187
|
+
}
|
|
6188
|
+
}
|
|
6189
|
+
function checkInputRowsPerCall(name, value, blended) {
|
|
6190
|
+
if (value == null)
|
|
6191
|
+
return;
|
|
6192
|
+
if (!blended) {
|
|
6193
|
+
throw new Error(`${name}: inputRowsPerCall applies only to a blended row-transform function, ` + `whose per-row input the client can split into calls`);
|
|
6194
|
+
}
|
|
6195
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 1) {
|
|
6196
|
+
throw new Error(`${name}: inputRowsPerCall must be a positive integer, got ${String(value)}`);
|
|
6197
|
+
}
|
|
6198
|
+
return value;
|
|
6199
|
+
}
|
|
6200
|
+
|
|
6117
6201
|
// src/util/statistics.ts
|
|
6118
6202
|
init_arrow();
|
|
6119
6203
|
function serializeColumnStatistics(stats, _cacheMaxAgeSeconds) {
|
|
@@ -6122,7 +6206,7 @@ function serializeColumnStatistics(stats, _cacheMaxAgeSeconds) {
|
|
|
6122
6206
|
|
|
6123
6207
|
// src/generated/vgi-protocol-schemas.ts
|
|
6124
6208
|
init_arrow();
|
|
6125
|
-
var VGI_CATALOG_CONTRACT_HASH = "
|
|
6209
|
+
var VGI_CATALOG_CONTRACT_HASH = "0aa39285365f5f4326ce85c4d41d2705ea992dee41cf98d07640a2767b6ac3fb";
|
|
6126
6210
|
var CatalogInfoSchema = schema2([
|
|
6127
6211
|
field2("name", utf82(), false),
|
|
6128
6212
|
field2("implementation_version", utf82(), true),
|
|
@@ -6208,6 +6292,7 @@ var FunctionInfoSchema = schema2([
|
|
|
6208
6292
|
field2("sink_order_dependent", bool2(), false),
|
|
6209
6293
|
field2("requires_input_batch_index", bool2(), false),
|
|
6210
6294
|
field2("input_from_args", bool2(), false),
|
|
6295
|
+
field2("input_rows_per_call", int642(), true),
|
|
6211
6296
|
field2("required_settings", list2(field2("item", utf82(), true)), false),
|
|
6212
6297
|
field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false)
|
|
6213
6298
|
]);
|
|
@@ -8406,6 +8491,9 @@ function functionHandlers(config) {
|
|
|
8406
8491
|
if (state.userState != null && handlerState?.state !== undefined) {
|
|
8407
8492
|
handlerState.state = state.userState;
|
|
8408
8493
|
}
|
|
8494
|
+
if (handlers.continuesOutput) {
|
|
8495
|
+
handlerState.morePending = state.morePending === true;
|
|
8496
|
+
}
|
|
8409
8497
|
}
|
|
8410
8498
|
if (state.isProducer && handlers.producerFn) {
|
|
8411
8499
|
out.finish = () => {
|
|
@@ -8418,10 +8506,14 @@ function functionHandlers(config) {
|
|
|
8418
8506
|
} else if (handlers.exchangeFn) {
|
|
8419
8507
|
await handlers.exchangeFn(handlerState, input, out);
|
|
8420
8508
|
}
|
|
8509
|
+
if (!handlers.continuesOutput) {
|
|
8510
|
+
refuseMoreOutput(state.functionName, out);
|
|
8511
|
+
}
|
|
8421
8512
|
if (handlerState?.state !== undefined) {
|
|
8422
8513
|
state.userState = handlerState.state;
|
|
8423
8514
|
}
|
|
8424
8515
|
state.filterHistory = handlerState?.filterHistory ?? null;
|
|
8516
|
+
state.morePending = handlerState?.morePending === true;
|
|
8425
8517
|
},
|
|
8426
8518
|
headerInit: (params, state, ctx) => {
|
|
8427
8519
|
if (!state._initResponse) {
|
|
@@ -9123,6 +9215,41 @@ init_arrow();
|
|
|
9123
9215
|
init_storage();
|
|
9124
9216
|
// src/filter-pushdown/collector.ts
|
|
9125
9217
|
init_arrow();
|
|
9218
|
+
|
|
9219
|
+
// src/util/parent-rows.ts
|
|
9220
|
+
var PARENT_ROW_METADATA_KEY = "vgi_rpc.parent_row#b64";
|
|
9221
|
+
function encodeParentRows(parentRows) {
|
|
9222
|
+
const raw = new Uint8Array(parentRows.length * 4);
|
|
9223
|
+
const dv = new DataView(raw.buffer);
|
|
9224
|
+
for (let i = 0;i < parentRows.length; i++) {
|
|
9225
|
+
dv.setInt32(i * 4, parentRows[i], true);
|
|
9226
|
+
}
|
|
9227
|
+
if (typeof globalThis.Buffer !== "undefined") {
|
|
9228
|
+
return globalThis.Buffer.from(raw).toString("base64");
|
|
9229
|
+
}
|
|
9230
|
+
let bin = "";
|
|
9231
|
+
for (let i = 0;i < raw.length; i++)
|
|
9232
|
+
bin += String.fromCharCode(raw[i]);
|
|
9233
|
+
return globalThis.btoa(bin);
|
|
9234
|
+
}
|
|
9235
|
+
function decodeParentRows(encoded) {
|
|
9236
|
+
let raw;
|
|
9237
|
+
if (typeof globalThis.Buffer !== "undefined") {
|
|
9238
|
+
raw = new Uint8Array(globalThis.Buffer.from(encoded, "base64"));
|
|
9239
|
+
} else {
|
|
9240
|
+
const bin = globalThis.atob(encoded);
|
|
9241
|
+
raw = new Uint8Array(bin.length);
|
|
9242
|
+
for (let i = 0;i < bin.length; i++)
|
|
9243
|
+
raw[i] = bin.charCodeAt(i);
|
|
9244
|
+
}
|
|
9245
|
+
const dv = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
|
|
9246
|
+
const out = new Int32Array(raw.byteLength >> 2);
|
|
9247
|
+
for (let i = 0;i < out.length; i++)
|
|
9248
|
+
out[i] = dv.getInt32(i * 4, true);
|
|
9249
|
+
return out;
|
|
9250
|
+
}
|
|
9251
|
+
|
|
9252
|
+
// src/filter-pushdown/collector.ts
|
|
9126
9253
|
class FilteringOutputCollector {
|
|
9127
9254
|
inner;
|
|
9128
9255
|
filters;
|
|
@@ -9143,6 +9270,22 @@ class FilteringOutputCollector {
|
|
|
9143
9270
|
} else {
|
|
9144
9271
|
batch = batchFromColumns(batchOrColumns, this.inner.outputSchema);
|
|
9145
9272
|
}
|
|
9273
|
+
const encoded = metadata?.get(PARENT_ROW_METADATA_KEY);
|
|
9274
|
+
if (encoded !== undefined && batch.numRows > 0 && this.filters.filters.length > 0) {
|
|
9275
|
+
const mask = this.filters.evaluate(batch);
|
|
9276
|
+
const parents = decodeParentRows(encoded);
|
|
9277
|
+
const kept = [];
|
|
9278
|
+
for (let i = 0;i < parents.length; i++)
|
|
9279
|
+
if (mask[i])
|
|
9280
|
+
kept.push(parents[i]);
|
|
9281
|
+
const md = new Map(metadata);
|
|
9282
|
+
if (kept.length > 0)
|
|
9283
|
+
md.set(PARENT_ROW_METADATA_KEY, encodeParentRows(kept));
|
|
9284
|
+
else
|
|
9285
|
+
md.delete(PARENT_ROW_METADATA_KEY);
|
|
9286
|
+
this.inner.emit(filterBatch(batch, mask), md);
|
|
9287
|
+
return;
|
|
9288
|
+
}
|
|
9146
9289
|
const filtered = this.filters.apply(batch);
|
|
9147
9290
|
this.inner.emit(filtered, metadata);
|
|
9148
9291
|
}
|
|
@@ -12061,6 +12204,8 @@ init_storage();
|
|
|
12061
12204
|
var STREAMING_FINALIZE_KEY = new Uint8Array(0);
|
|
12062
12205
|
function defineTableInOutFunction(config) {
|
|
12063
12206
|
assertArrowTypes(config.args, `defineTableInOutFunction("${config.name}"): args`);
|
|
12207
|
+
checkResumeContract(config.name, config);
|
|
12208
|
+
checkInputRowsPerCall(config.name, config.inputRowsPerCall, false);
|
|
12064
12209
|
const specs = [];
|
|
12065
12210
|
let posIdx = 0;
|
|
12066
12211
|
if (config.args) {
|
|
@@ -12242,20 +12387,27 @@ function defineTableInOutFunction(config) {
|
|
|
12242
12387
|
return {
|
|
12243
12388
|
outputSchema,
|
|
12244
12389
|
inputSchema: request.bind_call.input_schema,
|
|
12245
|
-
|
|
12390
|
+
continuesOutput: true,
|
|
12391
|
+
exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
|
|
12246
12392
|
exchangeFn: async (eState, input, out) => {
|
|
12247
|
-
|
|
12248
|
-
|
|
12249
|
-
|
|
12250
|
-
|
|
12251
|
-
|
|
12252
|
-
|
|
12253
|
-
|
|
12254
|
-
|
|
12255
|
-
|
|
12256
|
-
|
|
12257
|
-
|
|
12258
|
-
|
|
12393
|
+
await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
|
|
12394
|
+
applyRevalidationValidators(eState.processParams, input);
|
|
12395
|
+
applyDynamicFilterUpdate(eState, input);
|
|
12396
|
+
let wrappedOut = makeMetadataBakingCollector(out);
|
|
12397
|
+
if (projIds) {
|
|
12398
|
+
wrappedOut = makeSchemaReconcilingCollector(wrappedOut, outputSchema);
|
|
12399
|
+
}
|
|
12400
|
+
const currentFilters = eState.processParams.pushdownFilters;
|
|
12401
|
+
if (config.autoApplyFilters && currentFilters) {
|
|
12402
|
+
wrappedOut = new FilteringOutputCollector(wrappedOut, currentFilters);
|
|
12403
|
+
}
|
|
12404
|
+
if (tick) {
|
|
12405
|
+
await config.resume(eState.processParams, eState.state, wrappedOut);
|
|
12406
|
+
} else {
|
|
12407
|
+
await processFn(eState.processParams, eState.state, input, wrappedOut);
|
|
12408
|
+
}
|
|
12409
|
+
});
|
|
12410
|
+
if (config.finalize && eState.state != null) {
|
|
12259
12411
|
const serialized = serializeUserState(eState.state);
|
|
12260
12412
|
if (serialized != null) {
|
|
12261
12413
|
await boundStorage.put(serialized);
|
|
@@ -12333,7 +12485,6 @@ function makeSchemaReconcilingCollector(inner, targetSchema) {
|
|
|
12333
12485
|
}
|
|
12334
12486
|
});
|
|
12335
12487
|
}
|
|
12336
|
-
var PARENT_ROW_METADATA_KEY = "vgi_rpc.parent_row#b64";
|
|
12337
12488
|
function parentRowsMetadata(parentRows, outputRows, extra) {
|
|
12338
12489
|
if (parentRows.length !== outputRows) {
|
|
12339
12490
|
throw new Error(`parentRowsMetadata: length ${parentRows.length} != output rows ${outputRows}; ` + `parentRows must carry exactly one input-row index per emitted output row`);
|
|
@@ -12342,28 +12493,16 @@ function parentRowsMetadata(parentRows, outputRows, extra) {
|
|
|
12342
12493
|
if (outputRows === 0) {
|
|
12343
12494
|
return md;
|
|
12344
12495
|
}
|
|
12345
|
-
|
|
12346
|
-
const dv = new DataView(raw.buffer);
|
|
12347
|
-
for (let i = 0;i < parentRows.length; i++) {
|
|
12348
|
-
dv.setInt32(i * 4, parentRows[i], true);
|
|
12349
|
-
}
|
|
12350
|
-
md.set(PARENT_ROW_METADATA_KEY, base64Encode(raw));
|
|
12496
|
+
md.set(PARENT_ROW_METADATA_KEY, encodeParentRows(parentRows));
|
|
12351
12497
|
return md;
|
|
12352
12498
|
}
|
|
12353
|
-
function base64Encode(bytes) {
|
|
12354
|
-
if (typeof globalThis.Buffer !== "undefined") {
|
|
12355
|
-
return globalThis.Buffer.from(bytes).toString("base64");
|
|
12356
|
-
}
|
|
12357
|
-
let bin = "";
|
|
12358
|
-
for (let i = 0;i < bytes.length; i++)
|
|
12359
|
-
bin += String.fromCharCode(bytes[i]);
|
|
12360
|
-
return globalThis.btoa(bin);
|
|
12361
|
-
}
|
|
12362
12499
|
function defineRowTransformFunction(config) {
|
|
12363
12500
|
const numPositional = Object.keys(config.args ?? {}).length + (config.varargs ? 1 : 0);
|
|
12364
12501
|
if (numPositional === 0) {
|
|
12365
12502
|
throw new Error(`${config.name}: a blended row-transform function needs at least one ` + `positional arg (its per-row input column); found none.`);
|
|
12366
12503
|
}
|
|
12504
|
+
checkResumeContract(config.name, config);
|
|
12505
|
+
const inputRowsPerCall = checkInputRowsPerCall(config.name, config.inputRowsPerCall, true);
|
|
12367
12506
|
const specs = [];
|
|
12368
12507
|
let posIdx = 0;
|
|
12369
12508
|
if (config.args) {
|
|
@@ -12417,7 +12556,8 @@ function defineRowTransformFunction(config) {
|
|
|
12417
12556
|
requiredSettings: config.requiredSettings,
|
|
12418
12557
|
requiredSecrets: config.requiredSecrets,
|
|
12419
12558
|
hasFinalize: false,
|
|
12420
|
-
inputFromArgs: true
|
|
12559
|
+
inputFromArgs: true,
|
|
12560
|
+
inputRowsPerCall
|
|
12421
12561
|
};
|
|
12422
12562
|
function extractArgs(request) {
|
|
12423
12563
|
const args = {};
|
|
@@ -12502,22 +12642,30 @@ function defineRowTransformFunction(config) {
|
|
|
12502
12642
|
if (request.bind_call.input_schema == null) {
|
|
12503
12643
|
throw new Error(`${config.name}: is a table-in-out function (its positional args are ` + `per-row input columns) but no input schema was supplied -- call it ` + `via table_in_out_function(input=...), not table_function().`);
|
|
12504
12644
|
}
|
|
12645
|
+
const state = config.initialState ? config.initialState(processParams) : null;
|
|
12505
12646
|
return {
|
|
12506
12647
|
outputSchema,
|
|
12507
12648
|
inputSchema: request.bind_call.input_schema,
|
|
12508
|
-
|
|
12649
|
+
continuesOutput: true,
|
|
12650
|
+
exchangeInit: () => ({ state, processParams, filterHistory: carriedFilterHistory, morePending: false }),
|
|
12509
12651
|
exchangeFn: async (eState, input, out) => {
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12652
|
+
await continuationTurn(config.name, eState, input, out, config.resume != null, async (tick) => {
|
|
12653
|
+
applyRevalidationValidators(eState.processParams, input);
|
|
12654
|
+
applyDynamicFilterUpdate(eState, input);
|
|
12655
|
+
let wrappedOut = makeMetadataBakingCollector(out);
|
|
12656
|
+
if (projIds) {
|
|
12657
|
+
wrappedOut = makeSchemaReconcilingCollector(wrappedOut, outputSchema);
|
|
12658
|
+
}
|
|
12659
|
+
const currentFilters = eState.processParams.pushdownFilters;
|
|
12660
|
+
if (config.autoApplyFilters && currentFilters) {
|
|
12661
|
+
wrappedOut = new FilteringOutputCollector(wrappedOut, currentFilters);
|
|
12662
|
+
}
|
|
12663
|
+
if (tick) {
|
|
12664
|
+
await config.resume(eState.processParams, eState.state, wrappedOut);
|
|
12665
|
+
} else {
|
|
12666
|
+
await config.process(eState.processParams, input, wrappedOut, eState.state);
|
|
12667
|
+
}
|
|
12668
|
+
});
|
|
12521
12669
|
}
|
|
12522
12670
|
};
|
|
12523
12671
|
}
|
|
@@ -13031,6 +13179,7 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
13031
13179
|
sink_order_dependent: f.kind === "table_buffering" && f.meta.sinkOrderDependent === true,
|
|
13032
13180
|
requires_input_batch_index: f.kind === "table_buffering" && f.meta.requiresInputBatchIndex === true,
|
|
13033
13181
|
input_from_args: f.kind === "table_in_out" && f.meta.inputFromArgs === true,
|
|
13182
|
+
input_rows_per_call: f.kind === "table_in_out" && f.meta.inputFromArgs === true ? f.meta.inputRowsPerCall ?? null : null,
|
|
13034
13183
|
required_settings: meta.requiredSettings,
|
|
13035
13184
|
required_secrets: requiredSecrets.map((s) => ({
|
|
13036
13185
|
secret_type: s.secret_type,
|
|
@@ -13961,6 +14110,7 @@ export {
|
|
|
13961
14110
|
iterRows,
|
|
13962
14111
|
list2 as list,
|
|
13963
14112
|
map2 as map,
|
|
14113
|
+
moreOutputMetadata,
|
|
13964
14114
|
nullType2 as nullType,
|
|
13965
14115
|
parentRowsMetadata,
|
|
13966
14116
|
projectBatch,
|
|
@@ -13988,4 +14138,4 @@ export {
|
|
|
13988
14138
|
utf82 as utf8
|
|
13989
14139
|
};
|
|
13990
14140
|
|
|
13991
|
-
//# debugId=
|
|
14141
|
+
//# debugId=DF2D9EC97DFECF8764756E2164756E21
|