@query-farm/vgi 0.6.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/LICENSE +134 -0
- package/README.md +494 -0
- package/dist/__dbg.test-d.d.ts +1 -0
- package/dist/arguments/argument-spec.d.ts +51 -0
- package/dist/arguments/arguments.d.ts +13 -0
- package/dist/arrow/codec/branded.d.ts +83 -0
- package/dist/arrow/codec/registry.d.ts +29 -0
- package/dist/arrow/codec/repr.d.ts +23 -0
- package/dist/arrow/codec/type-descriptors.d.ts +109 -0
- package/dist/arrow/impl-arrowjs/build.d.ts +19 -0
- package/dist/arrow/impl-arrowjs/canonical.d.ts +15 -0
- package/dist/arrow/impl-arrowjs/empty.d.ts +7 -0
- package/dist/arrow/impl-arrowjs/filter.d.ts +11 -0
- package/dist/arrow/impl-arrowjs/index.d.ts +11 -0
- package/dist/arrow/impl-arrowjs/ipc.d.ts +24 -0
- package/dist/arrow/impl-arrowjs/iterate.d.ts +39 -0
- package/dist/arrow/impl-arrowjs/project.d.ts +10 -0
- package/dist/arrow/impl-arrowjs/schema.d.ts +62 -0
- package/dist/arrow/impl-arrowjs/statistics.d.ts +13 -0
- package/dist/arrow/impl-flechette/build.d.ts +14 -0
- package/dist/arrow/impl-flechette/canonical.d.ts +18 -0
- package/dist/arrow/impl-flechette/empty.d.ts +9 -0
- package/dist/arrow/impl-flechette/filter.d.ts +10 -0
- package/dist/arrow/impl-flechette/index.d.ts +11 -0
- package/dist/arrow/impl-flechette/ipc.d.ts +33 -0
- package/dist/arrow/impl-flechette/iterate.d.ts +29 -0
- package/dist/arrow/impl-flechette/message-meta.d.ts +10 -0
- package/dist/arrow/impl-flechette/normalize-type.d.ts +11 -0
- package/dist/arrow/impl-flechette/project.d.ts +3 -0
- package/dist/arrow/impl-flechette/schema.d.ts +47 -0
- package/dist/arrow/impl-flechette/statistics.d.ts +13 -0
- package/dist/arrow/index.d.ts +11 -0
- package/dist/arrow/predicates.d.ts +47 -0
- package/dist/arrow/repr.test-d.d.ts +52 -0
- package/dist/arrow/schema-types.d.ts +71 -0
- package/dist/arrow/types.d.ts +57 -0
- package/dist/catalog/attach-option.d.ts +33 -0
- package/dist/catalog/attach-options.d.ts +30 -0
- package/dist/catalog/composite.d.ts +33 -0
- package/dist/catalog/descriptors.d.ts +154 -0
- package/dist/catalog/interface.d.ts +239 -0
- package/dist/catalog/read-only.d.ts +33 -0
- package/dist/client/client.d.ts +189 -0
- package/dist/client/errors.d.ts +26 -0
- package/dist/client/helpers.d.ts +12 -0
- package/dist/client/protocol.d.ts +16 -0
- package/dist/client/types.d.ts +125 -0
- package/dist/client-entry.d.ts +11 -0
- package/dist/client-entry.js +48 -0
- package/dist/client-entry.js.map +9 -0
- package/dist/codec/asd.d.ts +25 -0
- package/dist/crypto.d.ts +36 -0
- package/dist/errors.d.ts +24 -0
- package/dist/filter-pushdown/collector.d.ts +32 -0
- package/dist/filter-pushdown/deserialize.d.ts +16 -0
- package/dist/filter-pushdown/evaluate.d.ts +51 -0
- package/dist/filter-pushdown/index.d.ts +4 -0
- package/dist/filter-pushdown/types.d.ts +84 -0
- package/dist/functions/aggregate.d.ts +129 -0
- package/dist/functions/copy-from.d.ts +81 -0
- package/dist/functions/copy-to.d.ts +121 -0
- package/dist/functions/registry.d.ts +16 -0
- package/dist/functions/scalar.d.ts +98 -0
- package/dist/functions/storage-cf-do.d.ts +47 -0
- package/dist/functions/storage.d.ts +86 -0
- package/dist/functions/table-buffering.d.ts +99 -0
- package/dist/functions/table-in-out.d.ts +64 -0
- package/dist/functions/table.d.ts +118 -0
- package/dist/functions/types.d.ts +157 -0
- package/dist/generated/vgi-client.d.ts +466 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +115 -0
- package/dist/index.core.d.ts +42 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10888 -0
- package/dist/index.js.map +85 -0
- package/dist/metadata/resolve.d.ts +3 -0
- package/dist/metadata/serialize.d.ts +12 -0
- package/dist/metadata/types.d.ts +47 -0
- package/dist/protocol/dispatch.d.ts +23 -0
- package/dist/protocol/handlers/aggregate.d.ts +3 -0
- package/dist/protocol/handlers/catalog/admin.d.ts +3 -0
- package/dist/protocol/handlers/catalog/index.d.ts +3 -0
- package/dist/protocol/handlers/catalog/index_methods.d.ts +3 -0
- package/dist/protocol/handlers/catalog/macro.d.ts +3 -0
- package/dist/protocol/handlers/catalog/shared.d.ts +70 -0
- package/dist/protocol/handlers/catalog/table.d.ts +3 -0
- package/dist/protocol/handlers/catalog/view.d.ts +3 -0
- package/dist/protocol/handlers/function.d.ts +8 -0
- package/dist/protocol/handlers/shared.d.ts +31 -0
- package/dist/protocol/handlers/table-buffering.d.ts +3 -0
- package/dist/protocol/serialize.d.ts +4 -0
- package/dist/protocol/serializers/arguments.d.ts +3 -0
- package/dist/protocol/serializers/bind.d.ts +9 -0
- package/dist/protocol/serializers/cardinality.d.ts +7 -0
- package/dist/protocol/serializers/init.d.ts +9 -0
- package/dist/protocol/serializers/shared.d.ts +12 -0
- package/dist/protocol/state-serializer.d.ts +23 -0
- package/dist/protocol/types.d.ts +129 -0
- package/dist/secrets/helpers.d.ts +15 -0
- package/dist/types.d.ts +52 -0
- package/dist/util/arrow/index.d.ts +1 -0
- package/dist/util/bytes.d.ts +2 -0
- package/dist/util/statistics.d.ts +7 -0
- package/dist/worker-cf-entry.d.ts +30 -0
- package/dist/worker-cf-entry.js +8767 -0
- package/dist/worker-cf-entry.js.map +74 -0
- package/dist/worker.d.ts +36 -0
- package/package.json +96 -0
- package/src/arguments/argument-spec.ts +200 -0
- package/src/arguments/arguments.ts +81 -0
- package/src/arrow/codec/branded.ts +206 -0
- package/src/arrow/codec/registry.ts +674 -0
- package/src/arrow/codec/repr.ts +181 -0
- package/src/arrow/codec/type-descriptors.ts +137 -0
- package/src/arrow/impl-arrowjs/build.ts +88 -0
- package/src/arrow/impl-arrowjs/canonical.ts +509 -0
- package/src/arrow/impl-arrowjs/empty.ts +72 -0
- package/src/arrow/impl-arrowjs/filter.ts +53 -0
- package/src/arrow/impl-arrowjs/index.ts +54 -0
- package/src/arrow/impl-arrowjs/ipc.ts +67 -0
- package/src/arrow/impl-arrowjs/iterate.ts +159 -0
- package/src/arrow/impl-arrowjs/project.ts +73 -0
- package/src/arrow/impl-arrowjs/schema.ts +256 -0
- package/src/arrow/impl-arrowjs/statistics.ts +185 -0
- package/src/arrow/impl-flechette/build.ts +65 -0
- package/src/arrow/impl-flechette/canonical.ts +289 -0
- package/src/arrow/impl-flechette/empty.ts +20 -0
- package/src/arrow/impl-flechette/filter.ts +42 -0
- package/src/arrow/impl-flechette/index.ts +54 -0
- package/src/arrow/impl-flechette/ipc.ts +110 -0
- package/src/arrow/impl-flechette/iterate.ts +121 -0
- package/src/arrow/impl-flechette/message-meta.ts +175 -0
- package/src/arrow/impl-flechette/normalize-type.ts +99 -0
- package/src/arrow/impl-flechette/project.ts +64 -0
- package/src/arrow/impl-flechette/schema.ts +202 -0
- package/src/arrow/impl-flechette/statistics.ts +198 -0
- package/src/arrow/index.ts +129 -0
- package/src/arrow/predicates.ts +66 -0
- package/src/arrow/repr.test-d.ts +189 -0
- package/src/arrow/schema-types.ts +213 -0
- package/src/arrow/types.ts +74 -0
- package/src/catalog/attach-option.ts +107 -0
- package/src/catalog/attach-options.ts +79 -0
- package/src/catalog/composite.ts +180 -0
- package/src/catalog/descriptors.ts +164 -0
- package/src/catalog/interface.ts +721 -0
- package/src/catalog/read-only.ts +909 -0
- package/src/client/client.ts +1348 -0
- package/src/client/errors.ts +69 -0
- package/src/client/helpers.ts +56 -0
- package/src/client/protocol.ts +33 -0
- package/src/client/types.ts +140 -0
- package/src/client-entry.ts +112 -0
- package/src/codec/asd.ts +147 -0
- package/src/crypto.ts +143 -0
- package/src/errors.ts +61 -0
- package/src/filter-pushdown/collector.ts +147 -0
- package/src/filter-pushdown/deserialize.ts +253 -0
- package/src/filter-pushdown/evaluate.ts +591 -0
- package/src/filter-pushdown/index.ts +28 -0
- package/src/filter-pushdown/types.ts +91 -0
- package/src/functions/aggregate.ts +384 -0
- package/src/functions/copy-from.ts +282 -0
- package/src/functions/copy-to.ts +319 -0
- package/src/functions/registry.ts +258 -0
- package/src/functions/scalar.ts +356 -0
- package/src/functions/storage-cf-do.ts +303 -0
- package/src/functions/storage.ts +521 -0
- package/src/functions/table-buffering.ts +562 -0
- package/src/functions/table-in-out.ts +373 -0
- package/src/functions/table.ts +521 -0
- package/src/functions/types.ts +192 -0
- package/src/generated/vgi-client.ts +560 -0
- package/src/generated/vgi-protocol-schemas.ts +864 -0
- package/src/index.core.ts +267 -0
- package/src/index.ts +11 -0
- package/src/metadata/resolve.ts +109 -0
- package/src/metadata/serialize.ts +242 -0
- package/src/metadata/types.ts +60 -0
- package/src/protocol/dispatch.ts +52 -0
- package/src/protocol/handlers/aggregate.ts +355 -0
- package/src/protocol/handlers/catalog/admin.ts +368 -0
- package/src/protocol/handlers/catalog/index.ts +25 -0
- package/src/protocol/handlers/catalog/index_methods.ts +65 -0
- package/src/protocol/handlers/catalog/macro.ts +114 -0
- package/src/protocol/handlers/catalog/shared.ts +291 -0
- package/src/protocol/handlers/catalog/table.ts +401 -0
- package/src/protocol/handlers/catalog/view.ts +119 -0
- package/src/protocol/handlers/function.ts +302 -0
- package/src/protocol/handlers/shared.ts +80 -0
- package/src/protocol/handlers/table-buffering.ts +207 -0
- package/src/protocol/serialize.ts +23 -0
- package/src/protocol/serializers/arguments.ts +160 -0
- package/src/protocol/serializers/bind.ts +212 -0
- package/src/protocol/serializers/cardinality.ts +45 -0
- package/src/protocol/serializers/init.ts +247 -0
- package/src/protocol/serializers/shared.ts +46 -0
- package/src/protocol/state-serializer.ts +181 -0
- package/src/protocol/types.ts +153 -0
- package/src/secrets/helpers.ts +70 -0
- package/src/types.ts +71 -0
- package/src/util/arrow/index.ts +23 -0
- package/src/util/bytes.ts +14 -0
- package/src/util/statistics.ts +40 -0
- package/src/worker-cf-entry.ts +172 -0
- package/src/worker.ts +212 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
// Function config interfaces and VgiFunction base type.
|
|
3
|
+
|
|
4
|
+
import type { VgiSchema, VgiBatch, VgiDataType } from "../arrow/index.js";
|
|
5
|
+
import type { OutputCollector } from "@query-farm/vgi-rpc";
|
|
6
|
+
import type {
|
|
7
|
+
FunctionStability,
|
|
8
|
+
NullHandling,
|
|
9
|
+
OrderPreservation,
|
|
10
|
+
OrderDependence,
|
|
11
|
+
DistinctDependence,
|
|
12
|
+
TableCardinality,
|
|
13
|
+
} from "../types.js";
|
|
14
|
+
import type {
|
|
15
|
+
BindRequest,
|
|
16
|
+
BindResponse,
|
|
17
|
+
InitRequest,
|
|
18
|
+
GlobalInitResponse,
|
|
19
|
+
TableFunctionCardinalityRequest,
|
|
20
|
+
} from "../protocol/types.js";
|
|
21
|
+
import type { Arguments } from "../arguments/arguments.js";
|
|
22
|
+
import type { ArgumentSpec } from "../arguments/argument-spec.js";
|
|
23
|
+
|
|
24
|
+
/** Convention for handler state: mutable user state lives in `.state`. */
|
|
25
|
+
export interface HandlerState<T = any> {
|
|
26
|
+
/** Serializable user state for HTTP exchange round-trips. */
|
|
27
|
+
state: T;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface FunctionExample {
|
|
32
|
+
sql: string;
|
|
33
|
+
description: string;
|
|
34
|
+
expectedOutput?: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface FunctionMeta {
|
|
38
|
+
name: string;
|
|
39
|
+
description?: string;
|
|
40
|
+
stability?: FunctionStability;
|
|
41
|
+
nullHandling?: NullHandling;
|
|
42
|
+
examples?: FunctionExample[];
|
|
43
|
+
categories?: string[];
|
|
44
|
+
tags?: Record<string, string>;
|
|
45
|
+
projectionPushdown?: boolean;
|
|
46
|
+
filterPushdown?: boolean;
|
|
47
|
+
samplingPushdown?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* table (generator): opt in to DuckDB's late-materialization rewrite. A
|
|
50
|
+
* TOP_N/LIMIT/SAMPLE over a rowid-bearing table is rewritten into a SEMI
|
|
51
|
+
* join — a narrow ordering scan selects survivors, then the wide scan
|
|
52
|
+
* re-fetches their columns with the surviving rowids pushed down. Surfaces
|
|
53
|
+
* as FunctionInfo `late_materialization`. Only honoured by the C++ extension
|
|
54
|
+
* for tables whose worker also guarantees a UNIQUE, snapshot-stable rowid.
|
|
55
|
+
*/
|
|
56
|
+
lateMaterialization?: boolean;
|
|
57
|
+
supportedExpressionFilters?: string[];
|
|
58
|
+
autoApplyFilters?: boolean;
|
|
59
|
+
preservesOrder?: OrderPreservation;
|
|
60
|
+
maxWorkers?: number;
|
|
61
|
+
requiredSettings?: string[];
|
|
62
|
+
requiredSecrets?: string[];
|
|
63
|
+
orderDependent?: OrderDependence;
|
|
64
|
+
distinctDependent?: DistinctDependence;
|
|
65
|
+
/**
|
|
66
|
+
* For table_in_out functions: whether the user defined a finalize callback.
|
|
67
|
+
* DuckDB issues a separate FINALIZE init() phase only when this is true;
|
|
68
|
+
* otherwise calling FinalExecute is unsupported and crashes the C++ side.
|
|
69
|
+
*/
|
|
70
|
+
hasFinalize?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* table_buffering: force ParallelSink=false in the C++ operator
|
|
73
|
+
* (single-thread, source-ordered ingest).
|
|
74
|
+
*/
|
|
75
|
+
sinkOrderDependent?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* table_buffering: force serial Source drain in finalize_queue order
|
|
78
|
+
* (ParallelSource=false, SourceOrder=FIXED_ORDER).
|
|
79
|
+
*/
|
|
80
|
+
sourceOrderDependent?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* table_buffering: thread DuckDB's per-chunk batch_index into every
|
|
83
|
+
* process() call (RequiredPartitionInfo=BatchIndex).
|
|
84
|
+
*/
|
|
85
|
+
requiresInputBatchIndex?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* table (generator): the function tags every emitted Arrow batch with a
|
|
88
|
+
* per-partition `vgi_batch_index` so DuckDB's ordered sinks reassemble
|
|
89
|
+
* parallel output in partition order. Surfaces as FunctionInfo
|
|
90
|
+
* `supports_batch_index`.
|
|
91
|
+
*/
|
|
92
|
+
supportsBatchIndex?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* table (generator): Hive-style partition-columns mode. Functions declare
|
|
95
|
+
* a PartitionKind and annotate bind-schema fields; emitted batches carry
|
|
96
|
+
* `vgi_partition_values#b64` metadata. Surfaces as FunctionInfo
|
|
97
|
+
* `partition_kind`.
|
|
98
|
+
*/
|
|
99
|
+
partitionKind?: "NOT_PARTITIONED" | "SINGLE_VALUE_PARTITIONS" | "OVERLAPPING_PARTITIONS" | "DISJOINT_PARTITIONS";
|
|
100
|
+
/**
|
|
101
|
+
* COPY ... FROM custom format reader: the SQL `FORMAT` identifier this
|
|
102
|
+
* function backs (e.g. `example_lines`). Set by {@link defineCopyFromFunction}.
|
|
103
|
+
* When present, the catalog advertises this function via
|
|
104
|
+
* `copyFromFormats()` / the `catalog_copy_from_formats` RPC so the VGI
|
|
105
|
+
* extension registers a DuckDB CopyFunction for it. Mirrors vgi-python's
|
|
106
|
+
* `CopyFromFunction.COPY_FROM_FORMAT`.
|
|
107
|
+
*/
|
|
108
|
+
copyFromFormat?: string;
|
|
109
|
+
/** COPY direction; only `"from"` is supported today. Default `"from"`. */
|
|
110
|
+
copyFromDirection?: string;
|
|
111
|
+
/** Optional free-text comment surfaced by `vgi_copy_formats()`. */
|
|
112
|
+
copyFromComment?: string | null;
|
|
113
|
+
/**
|
|
114
|
+
* COPY ... TO custom format writer: the SQL `FORMAT` identifier this function
|
|
115
|
+
* backs (e.g. `example_lines_out`). Set by {@link defineCopyToFunction}. When
|
|
116
|
+
* present, the catalog advertises this function via `copyFromFormats()` (the
|
|
117
|
+
* `catalog_copy_from_formats` RPC returns all directions) so the VGI
|
|
118
|
+
* extension registers a DuckDB CopyFunction for it. The writer is a
|
|
119
|
+
* `table_buffering` function under the hood, reusing the
|
|
120
|
+
* `table_buffering_process` / `table_buffering_combine` RPCs. Mirrors
|
|
121
|
+
* vgi-python's `CopyToFunction.COPY_TO_FORMAT`.
|
|
122
|
+
*/
|
|
123
|
+
copyToFormat?: string;
|
|
124
|
+
/** COPY direction for a TO writer; always `"to"`. Default `"to"`. */
|
|
125
|
+
copyToDirection?: string;
|
|
126
|
+
/** Optional free-text comment surfaced by `vgi_copy_formats()`. */
|
|
127
|
+
copyToComment?: string | null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface StreamHandlers {
|
|
131
|
+
// For producer streams (table functions, finalize phase)
|
|
132
|
+
producerInit?: () => any;
|
|
133
|
+
producerFn?: (state: any, out: OutputCollector) => void | Promise<void>;
|
|
134
|
+
// For exchange streams (scalar, table-in-out input phase)
|
|
135
|
+
exchangeInit?: () => any;
|
|
136
|
+
exchangeFn?: (
|
|
137
|
+
state: any,
|
|
138
|
+
input: VgiBatch,
|
|
139
|
+
out: OutputCollector
|
|
140
|
+
) => void | Promise<void>;
|
|
141
|
+
// Output schema for the stream
|
|
142
|
+
outputSchema: VgiSchema;
|
|
143
|
+
// Input schema for exchange (empty for producer)
|
|
144
|
+
inputSchema?: VgiSchema;
|
|
145
|
+
/**
|
|
146
|
+
* Fires once per tick batch on the producer path, before `producerFn`.
|
|
147
|
+
* Receives the tick's Arrow custom metadata so the handler can pick up
|
|
148
|
+
* per-tick signals like `vgi_pushdown_filters` (dynamic filter updates
|
|
149
|
+
* from DuckDB's Top-N optimizer).
|
|
150
|
+
*/
|
|
151
|
+
onTick?: (state: any, tickMetadata: Map<string, string> | undefined) => void | Promise<void>;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* A resolved, registered VGI function definition.
|
|
156
|
+
*/
|
|
157
|
+
export interface VgiFunction {
|
|
158
|
+
kind: "scalar" | "table" | "table_in_out" | "table_buffering";
|
|
159
|
+
meta: FunctionMeta;
|
|
160
|
+
argumentSpecs: ArgumentSpec[];
|
|
161
|
+
/** Default output schema (for catalog registration). May be overridden at bind time. */
|
|
162
|
+
defaultOutputSchema?: VgiSchema;
|
|
163
|
+
bind(request: BindRequest): BindResponse | Promise<BindResponse>;
|
|
164
|
+
globalInit(request: InitRequest): GlobalInitResponse | Promise<GlobalInitResponse>;
|
|
165
|
+
createStreamHandlers(
|
|
166
|
+
request: InitRequest,
|
|
167
|
+
response: GlobalInitResponse,
|
|
168
|
+
accumulatedState?: any,
|
|
169
|
+
): StreamHandlers;
|
|
170
|
+
cardinality?(request: TableFunctionCardinalityRequest): TableCardinality | Promise<TableCardinality>;
|
|
171
|
+
/**
|
|
172
|
+
* Per-column statistics for this table function's output given the user's
|
|
173
|
+
* bind-time arguments. Returns null/[] when stats are unknown. Wired to the
|
|
174
|
+
* `table_function_statistics` RPC; DuckDB uses the bounds for plan-time
|
|
175
|
+
* filter elimination.
|
|
176
|
+
*/
|
|
177
|
+
statistics?(request: TableFunctionCardinalityRequest): import("../util/statistics.js").ColumnStatistics[] | null;
|
|
178
|
+
/**
|
|
179
|
+
* Per-execution diagnostics for EXPLAIN ANALYZE. DuckDB calls this at
|
|
180
|
+
* pipeline FinishSource via the `table_function_dynamic_to_string` RPC.
|
|
181
|
+
* Returns ordered key→value strings; the C++ extension merges these with
|
|
182
|
+
* the intrinsic keys (Function, Rows Read, Threads).
|
|
183
|
+
*/
|
|
184
|
+
dynamicToString?(request: DynamicToStringRequest): Record<string, string> | Promise<Record<string, string>>;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** Request bundle for the `table_function_dynamic_to_string` RPC. */
|
|
188
|
+
export interface DynamicToStringRequest {
|
|
189
|
+
bindCall: BindRequest;
|
|
190
|
+
bindOpaqueData: Uint8Array | null;
|
|
191
|
+
globalExecutionId: Uint8Array;
|
|
192
|
+
}
|