@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,11 @@
|
|
|
1
|
+
export { VgiClient, VgiClientError } from "./client/client.js";
|
|
2
|
+
export type { VgiClientOptions, TableFunctionOptions, ScalarFunctionOptions, TableInOutFunctionOptions, OnCreateConflict, CatalogFunctionType, } from "./client/types.js";
|
|
3
|
+
export { Arguments } from "./arguments/arguments.js";
|
|
4
|
+
export { type ArgumentSpec, argumentSpecsToSchema, schemaToArgumentSpecs, } from "./arguments/argument-spec.js";
|
|
5
|
+
export { FunctionType, FunctionStability, NullHandling, OrderPreservation, OrderDependence, DistinctDependence, TableInOutPhase, } from "./types.js";
|
|
6
|
+
export type { BindRequest, BindResponse, InitRequest, GlobalInitResponse, TableCardinality, } from "./protocol/types.js";
|
|
7
|
+
export { type SchemaInfo, encodeSchemaInfo, decodeSchemaInfo, type TableInfo, encodeTableInfo, decodeTableInfo, type ViewInfo, encodeViewInfo, decodeViewInfo, type FunctionInfo, encodeFunctionInfo, decodeFunctionInfo, type MacroInfo, encodeMacroInfo, decodeMacroInfo, type CatalogAttachResult, type AttachOpaqueData, type TransactionOpaqueData, } from "./catalog/interface.js";
|
|
8
|
+
export { VgiError, RowCountMismatchError, FunctionNotFoundError, CatalogReadOnlyError, CatalogNotFoundError, CatalogAlreadyExistsError, ArgumentValidationError, NoCatalogError, } from "./errors.js";
|
|
9
|
+
export { iterRows, batchFromRows, batchFromColumns, emptyBatch, filterBatch, projectSchema, projectBatch, batchToScalarDict, safeNumber, serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, } from "./util/arrow/index.js";
|
|
10
|
+
export { toUint8Array } from "./util/bytes.js";
|
|
11
|
+
export type { RpcClient, StreamSession, LogMessage } from "@query-farm/vgi-rpc";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export {
|
|
2
|
+
toUint8Array,
|
|
3
|
+
serializeSchema,
|
|
4
|
+
serializeBatch,
|
|
5
|
+
schemaToArgumentSpecs,
|
|
6
|
+
safeNumber,
|
|
7
|
+
projectSchema,
|
|
8
|
+
projectBatch,
|
|
9
|
+
iterRows,
|
|
10
|
+
filterBatch,
|
|
11
|
+
encodeViewInfo,
|
|
12
|
+
encodeTableInfo,
|
|
13
|
+
encodeSchemaInfo,
|
|
14
|
+
encodeMacroInfo,
|
|
15
|
+
encodeFunctionInfo,
|
|
16
|
+
emptyBatch,
|
|
17
|
+
deserializeSchema,
|
|
18
|
+
deserializeBatch,
|
|
19
|
+
decodeViewInfo,
|
|
20
|
+
decodeTableInfo,
|
|
21
|
+
decodeSchemaInfo,
|
|
22
|
+
decodeMacroInfo,
|
|
23
|
+
decodeFunctionInfo,
|
|
24
|
+
batchToScalarDict,
|
|
25
|
+
batchFromRows,
|
|
26
|
+
batchFromColumns,
|
|
27
|
+
argumentSpecsToSchema,
|
|
28
|
+
VgiError,
|
|
29
|
+
VgiClientError,
|
|
30
|
+
VgiClient,
|
|
31
|
+
TableInOutPhase,
|
|
32
|
+
RowCountMismatchError,
|
|
33
|
+
OrderPreservation,
|
|
34
|
+
OrderDependence,
|
|
35
|
+
NullHandling,
|
|
36
|
+
NoCatalogError,
|
|
37
|
+
FunctionType,
|
|
38
|
+
FunctionStability,
|
|
39
|
+
FunctionNotFoundError,
|
|
40
|
+
DistinctDependence,
|
|
41
|
+
CatalogReadOnlyError,
|
|
42
|
+
CatalogNotFoundError,
|
|
43
|
+
CatalogAlreadyExistsError,
|
|
44
|
+
Arguments,
|
|
45
|
+
ArgumentValidationError
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
//# debugId=C4422E46DEACD50764756E2164756E21
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic ArrowSerializableDataclass (ASD) codec.
|
|
3
|
+
*
|
|
4
|
+
* Bridges between typed TS objects (snake_case, matching vgi-python dataclass
|
|
5
|
+
* field names) and Arrow IPC bytes (single-row batch with the dataclass'
|
|
6
|
+
* ARROW_SCHEMA). Used by the generated vgi-client.ts encode<X>/decode<X>
|
|
7
|
+
* wrappers to make the typed client interfaces honest at the wire boundary.
|
|
8
|
+
*
|
|
9
|
+
* Encoding delegates to the facade's `batchFromRows` (which handles the
|
|
10
|
+
* complex types — Decimal/BigInt/List/Map/Struct/Dictionary — uniformly
|
|
11
|
+
* across both arrow-js and flechette backends). Decoding pulls each field's
|
|
12
|
+
* value with `batchToScalarDict`, then runs `normalizeValue` to convert
|
|
13
|
+
* Arrow representations (MapRow, BigInt, etc.) back into plain JS shapes.
|
|
14
|
+
*/
|
|
15
|
+
import { type VgiSchema } from "../arrow/index.js";
|
|
16
|
+
/**
|
|
17
|
+
* Encode a typed object as a single-row Arrow IPC stream using `schema`.
|
|
18
|
+
* Matches Python's `ArrowSerializableDataclass.serialize_to_bytes()`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function encodeASD(schema: VgiSchema, obj: Record<string, any>): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Decode a single-row Arrow IPC stream into a typed object using `schema`.
|
|
23
|
+
* Matches Python's `ArrowSerializableDataclass.deserialize_from_bytes()`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function decodeASD<T>(schema: VgiSchema, bytes: Uint8Array): T;
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AuthContext } from "@query-farm/vgi-rpc";
|
|
2
|
+
export declare const ATTACH_ENVELOPE_VERSION = 2;
|
|
3
|
+
export declare const TRANSACTION_ENVELOPE_VERSION = 2;
|
|
4
|
+
/** Width of the framework UUID prepended to every attach plaintext. */
|
|
5
|
+
export declare const ATTACH_UUID_LEN = 16;
|
|
6
|
+
/**
|
|
7
|
+
* Thrown when an envelope cannot be opened — wrong principal, wrong parent
|
|
8
|
+
* attach, tampered, malformed, or simply unknown. Every failure mode maps to
|
|
9
|
+
* this single error so a probing caller cannot distinguish them.
|
|
10
|
+
*/
|
|
11
|
+
export declare class OpaqueDataRejectedError extends Error {
|
|
12
|
+
constructor(field?: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Build the identity portion of an opaque-data AAD. Unauthenticated requests
|
|
16
|
+
* get a fixed anonymous tail, so an anonymous caller cannot open an envelope
|
|
17
|
+
* sealed for a real principal.
|
|
18
|
+
*/
|
|
19
|
+
export declare function identityTail(auth: AuthContext | undefined): Uint8Array;
|
|
20
|
+
/** AAD for an `attach_opaque_data` envelope: prefix + caller identity. */
|
|
21
|
+
export declare function attachAad(auth: AuthContext | undefined): Uint8Array;
|
|
22
|
+
/**
|
|
23
|
+
* AAD for a `transaction_opaque_data` envelope. Binds both the caller identity
|
|
24
|
+
* and the parent attach envelope, so a transaction value minted under one
|
|
25
|
+
* attach cannot be replayed against a different attach even by the same
|
|
26
|
+
* principal.
|
|
27
|
+
*/
|
|
28
|
+
export declare function transactionAad(auth: AuthContext | undefined, attachEnvelope: Uint8Array): Uint8Array;
|
|
29
|
+
/** Seal `payload` into an AEAD envelope: version || nonce || ciphertext+tag. */
|
|
30
|
+
export declare function sealBytes(payload: Uint8Array, key: Uint8Array, aad: Uint8Array, version: number): Promise<Uint8Array>;
|
|
31
|
+
/**
|
|
32
|
+
* Open and verify an envelope produced by {@link sealBytes}. Every failure
|
|
33
|
+
* mode — malformed, wrong version, tampered, wrong key, wrong AAD
|
|
34
|
+
* (cross-principal / cross-attach replay) — throws {@link OpaqueDataRejectedError}.
|
|
35
|
+
*/
|
|
36
|
+
export declare function openBytes(token: Uint8Array, key: Uint8Array, aad: Uint8Array, version: number, field?: string): Promise<Uint8Array>;
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare class VgiError extends Error {
|
|
2
|
+
constructor(message: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class RowCountMismatchError extends VgiError {
|
|
5
|
+
constructor(expected: number, actual: number);
|
|
6
|
+
}
|
|
7
|
+
export declare class FunctionNotFoundError extends VgiError {
|
|
8
|
+
constructor(name: string, available?: string[]);
|
|
9
|
+
}
|
|
10
|
+
export declare class CatalogReadOnlyError extends VgiError {
|
|
11
|
+
constructor(operation: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class CatalogNotFoundError extends VgiError {
|
|
14
|
+
constructor(entity: string, name: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class CatalogAlreadyExistsError extends VgiError {
|
|
17
|
+
constructor(entity: string, name: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class ArgumentValidationError extends VgiError {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class NoCatalogError extends VgiError {
|
|
23
|
+
constructor();
|
|
24
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type VgiBatch, type VgiSchema } from "../arrow/index.js";
|
|
2
|
+
import type { OutputCollector } from "@query-farm/vgi-rpc";
|
|
3
|
+
import { PushdownFilters } from "./evaluate.js";
|
|
4
|
+
/**
|
|
5
|
+
* Format pushdown filters as a human-readable SQL-like string.
|
|
6
|
+
* Returns "(none)" when no filters exist.
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatPushedFilters(filters: PushdownFilters | undefined): string;
|
|
9
|
+
/**
|
|
10
|
+
* Format pushdown filters using Python-style `repr()` — e.g.
|
|
11
|
+
* `PushdownFilters([ConstantFilter(n < 4999)])`. Matches vgi-python's
|
|
12
|
+
* `_format_pushed_filters_safe` output so tests that pattern-match the
|
|
13
|
+
* repr (e.g. `dynamic_filter` checking for `ConstantFilter(n <`) work
|
|
14
|
+
* identically across workers.
|
|
15
|
+
*/
|
|
16
|
+
export declare function reprPushedFilters(filters: PushdownFilters | undefined): string;
|
|
17
|
+
/**
|
|
18
|
+
* Wraps an OutputCollector to automatically apply pushdown filters
|
|
19
|
+
* to every emitted batch.
|
|
20
|
+
*/
|
|
21
|
+
export declare class FilteringOutputCollector {
|
|
22
|
+
private inner;
|
|
23
|
+
private filters;
|
|
24
|
+
constructor(inner: OutputCollector, filters: PushdownFilters);
|
|
25
|
+
get outputSchema(): VgiSchema;
|
|
26
|
+
get finished(): boolean;
|
|
27
|
+
emit(batch: VgiBatch, metadata?: Map<string, string>): void;
|
|
28
|
+
emit(columns: Record<string, any[]>): void;
|
|
29
|
+
emitRow(values: Record<string, any>): void;
|
|
30
|
+
finish(): void;
|
|
31
|
+
clientLog(level: string, message: string, extra?: Record<string, string>): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type VgiBatch } from "../arrow/index.js";
|
|
2
|
+
import { PushdownFilters } from "./evaluate.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build a getJoinKeysColumn lookup from an InitRequest's `joinKeys` batches.
|
|
5
|
+
* Each batch typically has a single column whose name is the join-keys column
|
|
6
|
+
* referenced by `spec.keys_column` on a join_keys filter.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildJoinKeysLookup(joinKeyBatches: VgiBatch[]): (columnName: string) => any[] | null;
|
|
9
|
+
/**
|
|
10
|
+
* Deserialize pushdown filters from an Arrow RecordBatch.
|
|
11
|
+
*
|
|
12
|
+
* Wire format:
|
|
13
|
+
* - Column 0: UTF8 — JSON array of filter specs. Field metadata: vgi_filter_version: "1"
|
|
14
|
+
* - Columns 1+: Scalar values referenced by value_ref → column N+1
|
|
15
|
+
*/
|
|
16
|
+
export declare function deserializeFilters(batch: VgiBatch, getJoinKeysColumn?: (columnName: string) => any[] | null): PushdownFilters;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type VgiBatch } from "../arrow/index.js";
|
|
2
|
+
import { type Filter } from "./types.js";
|
|
3
|
+
export declare class PushdownFilters {
|
|
4
|
+
readonly filters: Filter[];
|
|
5
|
+
readonly version: string;
|
|
6
|
+
constructor(filters: Filter[], version: string);
|
|
7
|
+
/** Convert filters to a human-readable SQL-like string. */
|
|
8
|
+
toSql(): string;
|
|
9
|
+
/** Evaluate filters against a batch, returning a Uint8Array mask (0=fail, 1=pass). */
|
|
10
|
+
evaluate(batch: VgiBatch): Uint8Array;
|
|
11
|
+
/** Apply filters to a batch, returning only passing rows. */
|
|
12
|
+
apply(batch: VgiBatch): VgiBatch;
|
|
13
|
+
/**
|
|
14
|
+
* The set of column names referenced by the pushed-down filters, sorted
|
|
15
|
+
* ascending. Descends one level into AndFilter children (DuckDB pushes
|
|
16
|
+
* `col IN (...) AND col>=min` as a single AndFilter), consistent with
|
|
17
|
+
* `getColumnValues` / `hasFilterForColumn`. Mirrors the cross-language
|
|
18
|
+
* `filtered_columns` accessor (vgi-python / vgi-go / vgi-rust).
|
|
19
|
+
*/
|
|
20
|
+
filteredColumns(): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Whether any pushed-down filter references `columnName`. Mirrors the
|
|
23
|
+
* cross-language `has_filter_for_column` accessor.
|
|
24
|
+
*/
|
|
25
|
+
hasFilterForColumn(columnName: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Discrete values a column could take, from equality (`=`) or `IN` filters.
|
|
28
|
+
* Useful for partition pruning (resolve the key set up front, fetch only
|
|
29
|
+
* those keys). Returns null when the predicate is not enumerable — no
|
|
30
|
+
* filter, a bare range, or an OR with a non-discrete branch.
|
|
31
|
+
*
|
|
32
|
+
* Mirrors vgi-python's `PushdownFilters.get_column_values`: descends one
|
|
33
|
+
* level into an AndFilter (DuckDB pushes `col IN (...) AND col>=min AND
|
|
34
|
+
* col<=max` as a single AndFilter from a semi-join), and unions OR branches
|
|
35
|
+
* only when every branch pins the column to discrete values.
|
|
36
|
+
*/
|
|
37
|
+
getColumnValues(columnName: string): any[] | null;
|
|
38
|
+
/**
|
|
39
|
+
* Union of discrete values for `columnName` across all OR branches, iff every
|
|
40
|
+
* child constrains it to discrete values (`=` or `IN`); otherwise null (the
|
|
41
|
+
* column could take any value through a non-discrete branch). Returning one
|
|
42
|
+
* branch's values would be an unsafe subset.
|
|
43
|
+
*/
|
|
44
|
+
private orDiscreteValues;
|
|
45
|
+
/**
|
|
46
|
+
* Collect filters for a column from the top level and direct AND children
|
|
47
|
+
* (one level of descent, consistent with the Python accessor). Deeply nested
|
|
48
|
+
* AND/AND is not traversed.
|
|
49
|
+
*/
|
|
50
|
+
private collectColumnFilters;
|
|
51
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ComparisonOp, type AndFilter, type ConstantFilter, type ExpressionFilter, type ExprNode, type Filter, type InFilter, type IsNotNullFilter, type IsNullFilter, type OrFilter, type StructFilter, } from "./types.js";
|
|
2
|
+
export { PushdownFilters } from "./evaluate.js";
|
|
3
|
+
export { buildJoinKeysLookup, deserializeFilters } from "./deserialize.js";
|
|
4
|
+
export { FilteringOutputCollector, formatPushedFilters, reprPushedFilters, } from "./collector.js";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare enum ComparisonOp {
|
|
2
|
+
EQ = "eq",
|
|
3
|
+
NE = "ne",
|
|
4
|
+
GT = "gt",
|
|
5
|
+
GE = "ge",
|
|
6
|
+
LT = "lt",
|
|
7
|
+
LE = "le"
|
|
8
|
+
}
|
|
9
|
+
export interface ConstantFilter {
|
|
10
|
+
type: "constant";
|
|
11
|
+
columnName: string;
|
|
12
|
+
columnIndex: number;
|
|
13
|
+
op: ComparisonOp;
|
|
14
|
+
value: any;
|
|
15
|
+
}
|
|
16
|
+
export interface IsNullFilter {
|
|
17
|
+
type: "is_null";
|
|
18
|
+
columnName: string;
|
|
19
|
+
columnIndex: number;
|
|
20
|
+
}
|
|
21
|
+
export interface IsNotNullFilter {
|
|
22
|
+
type: "is_not_null";
|
|
23
|
+
columnName: string;
|
|
24
|
+
columnIndex: number;
|
|
25
|
+
}
|
|
26
|
+
export interface InFilter {
|
|
27
|
+
type: "in";
|
|
28
|
+
columnName: string;
|
|
29
|
+
columnIndex: number;
|
|
30
|
+
values: Set<any>;
|
|
31
|
+
}
|
|
32
|
+
export interface AndFilter {
|
|
33
|
+
type: "and";
|
|
34
|
+
columnName: string;
|
|
35
|
+
columnIndex: number;
|
|
36
|
+
children: Filter[];
|
|
37
|
+
}
|
|
38
|
+
export interface OrFilter {
|
|
39
|
+
type: "or";
|
|
40
|
+
columnName: string;
|
|
41
|
+
columnIndex: number;
|
|
42
|
+
children: Filter[];
|
|
43
|
+
}
|
|
44
|
+
export interface StructFilter {
|
|
45
|
+
type: "struct";
|
|
46
|
+
columnName: string;
|
|
47
|
+
columnIndex: number;
|
|
48
|
+
childIndex: number;
|
|
49
|
+
childName: string;
|
|
50
|
+
childFilter: Filter;
|
|
51
|
+
}
|
|
52
|
+
export type Filter = ConstantFilter | IsNullFilter | IsNotNullFilter | InFilter | AndFilter | OrFilter | StructFilter | ExpressionFilter;
|
|
53
|
+
/**
|
|
54
|
+
* Expression-tree filter. The expr is a parsed AST; evaluation matches
|
|
55
|
+
* DuckDB's semantics for the function names the table function advertises in
|
|
56
|
+
* `supportedExpressionFilters` (e.g. list_contains, starts_with, contains,
|
|
57
|
+
* &&/st_intersects_extent for spatial).
|
|
58
|
+
*/
|
|
59
|
+
export interface ExpressionFilter {
|
|
60
|
+
type: "expression";
|
|
61
|
+
columnName: string;
|
|
62
|
+
columnIndex: number;
|
|
63
|
+
expr: ExprNode;
|
|
64
|
+
}
|
|
65
|
+
export type ExprNode = {
|
|
66
|
+
expr_type: "column_ref";
|
|
67
|
+
index: number;
|
|
68
|
+
} | {
|
|
69
|
+
expr_type: "constant";
|
|
70
|
+
value: any;
|
|
71
|
+
} | {
|
|
72
|
+
expr_type: "function";
|
|
73
|
+
function_name: string;
|
|
74
|
+
children: ExprNode[];
|
|
75
|
+
} | {
|
|
76
|
+
expr_type: "comparison";
|
|
77
|
+
op: ComparisonOp;
|
|
78
|
+
left: ExprNode;
|
|
79
|
+
right: ExprNode;
|
|
80
|
+
} | {
|
|
81
|
+
expr_type: "conjunction";
|
|
82
|
+
conjunction_type: "and" | "or";
|
|
83
|
+
children: ExprNode[];
|
|
84
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { type VgiSchema, type VgiBatch, type VgiDataType } from "../arrow/index.js";
|
|
2
|
+
import type { Arguments } from "../arguments/arguments.js";
|
|
3
|
+
import type { VgiFunction } from "./types.js";
|
|
4
|
+
import type { FunctionExample } from "./types.js";
|
|
5
|
+
export declare const GROUP_COLUMN_NAME = "__vgi_group_id";
|
|
6
|
+
export interface AggregateBindParams<TArgs = Record<string, any>> {
|
|
7
|
+
args: TArgs;
|
|
8
|
+
arguments: Arguments;
|
|
9
|
+
inputSchema: VgiSchema | null;
|
|
10
|
+
settings: Record<string, any>;
|
|
11
|
+
secrets: Record<string, Record<string, any>>;
|
|
12
|
+
}
|
|
13
|
+
export interface AggregateUpdateParams<TArgs = Record<string, any>, TState = any> {
|
|
14
|
+
states: Map<bigint, TState>;
|
|
15
|
+
groupIds: bigint[];
|
|
16
|
+
columns: any[];
|
|
17
|
+
args: TArgs;
|
|
18
|
+
/**
|
|
19
|
+
* Get-or-initialize accessor for per-group state. Call this inside the loop
|
|
20
|
+
* only when the row actually contributes to the aggregate — skipping it
|
|
21
|
+
* (e.g. on NULL input under NullHandling.DEFAULT) leaves `states` without
|
|
22
|
+
* an entry for the group, so finalize() can return SQL NULL for that
|
|
23
|
+
* group (matches vgi-python's "state absent = NULL" semantics for
|
|
24
|
+
* SUM/AVG/MIN/MAX over zero non-null rows).
|
|
25
|
+
*/
|
|
26
|
+
ensureState: (gid: bigint) => TState;
|
|
27
|
+
}
|
|
28
|
+
export interface AggregateFinalizeParams<TArgs = Record<string, any>, TState = any> {
|
|
29
|
+
groupIds: bigint[];
|
|
30
|
+
states: Map<bigint, TState | null>;
|
|
31
|
+
outputSchema: VgiSchema;
|
|
32
|
+
args: TArgs;
|
|
33
|
+
}
|
|
34
|
+
export interface AggregateFunctionConfig<TArgs = Record<string, any>, TState = any> {
|
|
35
|
+
name: string;
|
|
36
|
+
description?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Map of positional argument name → Arrow type. Passed through to DuckDB
|
|
39
|
+
* function registration. Use `null` (untyped) for varargs placeholders.
|
|
40
|
+
*/
|
|
41
|
+
args?: Record<string, VgiDataType>;
|
|
42
|
+
/**
|
|
43
|
+
* Names of args that accept a variable number of column arguments. DuckDB
|
|
44
|
+
* treats these as varargs of the declared Arrow type; at call time the
|
|
45
|
+
* function may receive 1..N columns of that type. update() sees all of
|
|
46
|
+
* them as consecutive entries in `columns`.
|
|
47
|
+
*/
|
|
48
|
+
varargs?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Names of args whose value is constant (known at bind time) and must be
|
|
51
|
+
* folded away by DuckDB before reaching update(). The value arrives in
|
|
52
|
+
* `bindParams.args[name]`; it is NOT passed as an input column in the
|
|
53
|
+
* update batch. Use for aggregates parameterized by a literal (e.g.
|
|
54
|
+
* percentile=0.5 in vgi_percentile).
|
|
55
|
+
*/
|
|
56
|
+
constParams?: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Arrow type of the aggregate's output (one value per group). DuckDB uses
|
|
59
|
+
* this to build the result column type at bind time. May be overridden
|
|
60
|
+
* at bind time by `onBind` (returning a different Arrow type) for
|
|
61
|
+
* aggregates whose return type depends on the input column type
|
|
62
|
+
* (e.g. vgi_generic_sum: BIGINT input → BIGINT output, DOUBLE → DOUBLE).
|
|
63
|
+
*/
|
|
64
|
+
outputType: VgiDataType;
|
|
65
|
+
/**
|
|
66
|
+
* Optional bind-time hook for dynamic output types. Receives the bind
|
|
67
|
+
* parameters (including input_schema) and returns the Arrow type to
|
|
68
|
+
* advertise for this invocation. Defaults to returning `config.outputType`.
|
|
69
|
+
*/
|
|
70
|
+
onBind?: (params: AggregateBindParams<TArgs>) => VgiDataType | Promise<VgiDataType>;
|
|
71
|
+
/** Optional per-arg default values (positional only here). */
|
|
72
|
+
argDefaults?: Record<string, any>;
|
|
73
|
+
initialState: (params: AggregateBindParams<TArgs>) => TState;
|
|
74
|
+
/**
|
|
75
|
+
* Fold a batch of input rows into the provided per-group state map.
|
|
76
|
+
* Implementations mutate `states` in place. `groupIds[i]` identifies which
|
|
77
|
+
* group row i belongs to; `columns[k][i]` is the value for the kth declared
|
|
78
|
+
* column argument at row i.
|
|
79
|
+
*/
|
|
80
|
+
update: (params: AggregateUpdateParams<TArgs, TState>) => void;
|
|
81
|
+
combine: (source: TState, target: TState, params: AggregateBindParams<TArgs>) => TState;
|
|
82
|
+
/** Must return a single-column RecordBatch with `groupIds.length` rows. */
|
|
83
|
+
finalize: (params: AggregateFinalizeParams<TArgs, TState>) => VgiBatch;
|
|
84
|
+
examples?: FunctionExample[];
|
|
85
|
+
categories?: string[];
|
|
86
|
+
/** Arbitrary function-level tags surfaced into duckdb_functions().tags. */
|
|
87
|
+
tags?: Record<string, string>;
|
|
88
|
+
nullHandling?: "DEFAULT" | "SPECIAL";
|
|
89
|
+
/**
|
|
90
|
+
* DuckDB secret types this aggregate needs. Advertised on the catalog's
|
|
91
|
+
* `required_secrets` so the C++ extension pre-resolves matching secrets and
|
|
92
|
+
* delivers their VALUES on the aggregate_bind request (keyed by secret name).
|
|
93
|
+
* The secret is read at bind time only — update/combine/finalize receive an
|
|
94
|
+
* empty ResolvedSecrets. Mirrors vgi-python's `Secret()` annotation on an
|
|
95
|
+
* aggregate `on_bind`.
|
|
96
|
+
*/
|
|
97
|
+
requiredSecrets?: string[];
|
|
98
|
+
}
|
|
99
|
+
type StateMap = Map<bigint, any>;
|
|
100
|
+
interface ExecEntry {
|
|
101
|
+
states: StateMap;
|
|
102
|
+
bindArgs: Arguments;
|
|
103
|
+
bindParams: AggregateBindParams<any>;
|
|
104
|
+
loaded: Set<bigint>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Fetch the execution context — bind args/params + states for requested gids.
|
|
108
|
+
* On cache miss, tries to reconstruct from on-disk files written by a
|
|
109
|
+
* sibling worker. Returns undefined if the exec never existed anywhere.
|
|
110
|
+
* `requestedGids` (optional) tells us which group states to pre-load.
|
|
111
|
+
*/
|
|
112
|
+
export declare function getExecutionState(executionId: Uint8Array, requestedGids?: Iterable<bigint>): ExecEntry | undefined;
|
|
113
|
+
export declare function setExecutionState(executionId: Uint8Array, entry: Omit<ExecEntry, "loaded">): void;
|
|
114
|
+
/**
|
|
115
|
+
* Persist the given group states to disk so sibling workers can pick them up.
|
|
116
|
+
* Deletes the on-disk entry when the in-memory state was removed (gid no
|
|
117
|
+
* longer present in states map).
|
|
118
|
+
*/
|
|
119
|
+
export declare function persistGroupStates(executionId: Uint8Array, gids: Iterable<bigint>): void;
|
|
120
|
+
export declare function deleteExecutionState(executionId: Uint8Array): void;
|
|
121
|
+
/**
|
|
122
|
+
* Declare an aggregate function. The returned VgiFunction has `kind:
|
|
123
|
+
* "aggregate"` plus a `config` handle the dispatch layer uses to drive the
|
|
124
|
+
* aggregate_* RPCs; the scalar/table-function code paths ignore it.
|
|
125
|
+
*/
|
|
126
|
+
export declare function defineAggregate<TArgs = Record<string, any>, TState = any>(config: AggregateFunctionConfig<TArgs, TState>): VgiFunction & {
|
|
127
|
+
aggregateConfig: AggregateFunctionConfig<TArgs, TState>;
|
|
128
|
+
};
|
|
129
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type VgiSchema, type VgiDataType } from "../arrow/index.js";
|
|
2
|
+
import type { OutputCollector } from "@query-farm/vgi-rpc";
|
|
3
|
+
import type { BindRequest } from "../protocol/types.js";
|
|
4
|
+
import type { VgiFunction, FunctionExample } from "./types.js";
|
|
5
|
+
import type { CopySecretLookup } from "./copy-to.js";
|
|
6
|
+
import type { TableProcessParams } from "./table.js";
|
|
7
|
+
/** Declaration of a single COPY option (a named function argument). */
|
|
8
|
+
export interface CopyFromOption {
|
|
9
|
+
/** Arrow type of the option value (e.g. `utf8()`, `int64()`). */
|
|
10
|
+
type: VgiDataType;
|
|
11
|
+
/** Per-option description, surfaced by `vgi_copy_formats()`. */
|
|
12
|
+
doc?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Default value. When omitted the option is REQUIRED — the worker throws a
|
|
15
|
+
* clear error at COPY bind if the user does not supply it. Mirrors
|
|
16
|
+
* vgi-python's `Arg(..., default=...)` (no default => required).
|
|
17
|
+
*/
|
|
18
|
+
default?: unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Optional allowed value set, validated worker-side at bind. Mirrors
|
|
21
|
+
* vgi-python's `Arg(..., choices=[...])`.
|
|
22
|
+
*/
|
|
23
|
+
choices?: unknown[];
|
|
24
|
+
}
|
|
25
|
+
export interface CopyFromReadParams<TArgs = Record<string, unknown>> {
|
|
26
|
+
/** Source path from the `COPY ... FROM 'path'` statement. */
|
|
27
|
+
path: string;
|
|
28
|
+
/** Parsed COPY options (defaults applied). */
|
|
29
|
+
options: TArgs;
|
|
30
|
+
/**
|
|
31
|
+
* The COPY target's schema. Every emitted batch must have this exact schema
|
|
32
|
+
* (names + types, in order) — DuckDB inserts no cast before the INSERT.
|
|
33
|
+
*/
|
|
34
|
+
expectedSchema: VgiSchema;
|
|
35
|
+
/** Full process parameters (settings, secrets, storage). */
|
|
36
|
+
processParams: TableProcessParams<TArgs>;
|
|
37
|
+
/** Collector to emit batches / log. `finish()` is called for you. */
|
|
38
|
+
out: OutputCollector;
|
|
39
|
+
}
|
|
40
|
+
export interface CopyFromFunctionConfig<TArgs = Record<string, unknown>> {
|
|
41
|
+
/** Handler name (the function's registered name; `Meta.name`). */
|
|
42
|
+
name: string;
|
|
43
|
+
/** SQL `FORMAT` identifier users type, e.g. `COPY t FROM 'x' (FORMAT myfmt)`. */
|
|
44
|
+
format: string;
|
|
45
|
+
/** Function description (intrinsic documentation; `Meta.description`). */
|
|
46
|
+
description?: string;
|
|
47
|
+
/** Optional free-text comment surfaced by `vgi_copy_formats()`. */
|
|
48
|
+
comment?: string | null;
|
|
49
|
+
/** Reserved for a future `COPY ... TO`; only `"from"` is supported today. */
|
|
50
|
+
direction?: string;
|
|
51
|
+
/** COPY options, keyed by option name. The `file_path` is NOT an option. */
|
|
52
|
+
options?: Record<string, CopyFromOption>;
|
|
53
|
+
categories?: string[];
|
|
54
|
+
tags?: Record<string, string>;
|
|
55
|
+
examples?: FunctionExample[];
|
|
56
|
+
requiredSettings?: string[];
|
|
57
|
+
requiredSecrets?: string[];
|
|
58
|
+
/**
|
|
59
|
+
* Optional secret-bind hook: forward CREATE SECRET credentials for
|
|
60
|
+
* secret-backed cloud sources (S3/GCS/HTTP/…). Called during bind (only on the
|
|
61
|
+
* first pass); return the secrets to resolve — typically scoped by the source
|
|
62
|
+
* `path`. The framework's two-phase secret bind resolves each lookup from the
|
|
63
|
+
* caller's SecretManager and surfaces the resolved values on
|
|
64
|
+
* `processParams.secrets` at `read` time. Mirrors vgi-python's
|
|
65
|
+
* `CopyFromFunction.on_secrets`.
|
|
66
|
+
*/
|
|
67
|
+
onSecrets?: (params: {
|
|
68
|
+
options: TArgs;
|
|
69
|
+
path: string;
|
|
70
|
+
bindCall: BindRequest;
|
|
71
|
+
}) => CopySecretLookup[] | void;
|
|
72
|
+
/** Parse `path` and emit Arrow batches matching `expectedSchema`. */
|
|
73
|
+
read: (params: CopyFromReadParams<TArgs>) => void | Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Define a custom `COPY ... FROM` format reader, returned as a `VgiFunction`
|
|
77
|
+
* (kind `"table"`) carrying the `copyFromFormat` metadata marker. Register it in
|
|
78
|
+
* the catalog's function list like any table function; the catalog's
|
|
79
|
+
* `copyFromFormats()` introspection picks it up and advertises the format.
|
|
80
|
+
*/
|
|
81
|
+
export declare function defineCopyFromFunction<TArgs = Record<string, unknown>>(config: CopyFromFunctionConfig<TArgs>): VgiFunction;
|