@query-farm/vgi 0.48.4 → 0.49.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 +52 -1
- package/dist/attach-secret-keyfile.d.ts +11 -0
- package/dist/attach-secret-options.d.ts +96 -0
- package/dist/catalog/attach-option.d.ts +6 -0
- package/dist/catalog/composite.d.ts +2 -0
- package/dist/catalog/descriptors.d.ts +11 -0
- package/dist/catalog/interface.d.ts +54 -2
- package/dist/catalog/scan-planning.d.ts +76 -0
- package/dist/client-entry.js +32 -4
- package/dist/client-entry.js.map +9 -8
- package/dist/generated/vgi-client.d.ts +1 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +1 -1
- package/dist/generated/vgi-service.d.ts +5 -1
- package/dist/index.core.d.ts +3 -0
- package/dist/index.js +3245 -2538
- package/dist/index.js.map +32 -29
- package/dist/protocol/dispatch.d.ts +13 -2
- package/dist/protocol/handlers/catalog/admin.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index.d.ts +1 -1
- package/dist/protocol/handlers/catalog/index_methods.d.ts +1 -1
- package/dist/protocol/handlers/catalog/macro.d.ts +1 -1
- package/dist/protocol/handlers/catalog/shared.d.ts +28 -3
- package/dist/protocol/handlers/catalog/table.d.ts +1 -1
- package/dist/protocol/handlers/catalog/view.d.ts +1 -1
- package/dist/protocol/handlers/function.d.ts +2 -0
- package/dist/protocol/handlers/table-buffering.d.ts +1 -1
- package/dist/serve-entry.d.ts +5 -0
- package/dist/serve-entry.js +2026 -101
- package/dist/serve-entry.js.map +27 -20
- package/dist/worker-cf-entry.d.ts +2 -2
- package/dist/worker-cf-entry.js +823 -103
- package/dist/worker-cf-entry.js.map +27 -24
- package/dist/worker.d.ts +10 -0
- package/package.json +1 -1
- package/src/attach-secret-keyfile.ts +185 -0
- package/src/attach-secret-options.ts +418 -0
- package/src/catalog/attach-option.ts +6 -0
- package/src/catalog/column-metadata.ts +7 -0
- package/src/catalog/composite.ts +5 -0
- package/src/catalog/descriptors.ts +11 -0
- package/src/catalog/interface.ts +97 -2
- package/src/catalog/read-only.ts +14 -1
- package/src/catalog/scan-planning.ts +314 -0
- package/src/generated/vgi-client.ts +2 -1
- package/src/generated/vgi-protocol-schemas.ts +6 -2
- package/src/generated/vgi-service.ts +7 -2
- package/src/index.core.ts +21 -0
- package/src/protocol/dispatch.ts +16 -4
- package/src/protocol/handlers/catalog/admin.ts +33 -18
- package/src/protocol/handlers/catalog/index.ts +6 -5
- package/src/protocol/handlers/catalog/index_methods.ts +5 -3
- package/src/protocol/handlers/catalog/macro.ts +7 -5
- package/src/protocol/handlers/catalog/shared.ts +52 -6
- package/src/protocol/handlers/catalog/table.ts +43 -30
- package/src/protocol/handlers/catalog/view.ts +9 -7
- package/src/protocol/handlers/function.ts +11 -5
- package/src/protocol/handlers/table-buffering.ts +2 -1
- package/src/serve-entry.ts +6 -1
- package/src/worker-cf-entry.ts +9 -0
- package/src/worker.ts +12 -0
package/README.md
CHANGED
|
@@ -60,7 +60,7 @@ npm install @query-farm/vgi
|
|
|
60
60
|
|
|
61
61
|
Requires **Node.js ≥ 22.15** or **Bun**.
|
|
62
62
|
|
|
63
|
-
This branch uses **`vgi.v3` / `3.
|
|
63
|
+
This branch uses **`vgi.v3` / `3.2.0`** and requires a matching VGI
|
|
64
64
|
extension. Existing `vgi.v2` extensions need SDK 0.46.x; upgrade the engine-side
|
|
65
65
|
extension and workers together. This release prepares the shared protocol for
|
|
66
66
|
DuckDB 2.0; it does not require upgrading DuckDB itself. See
|
|
@@ -709,6 +709,57 @@ $ VGI_RPC_GRANT_KEYS="$(openssl rand -base64 32)" bun run scripts/serve.ts
|
|
|
709
709
|
- Sealed grants are not individually revocable: keep the lifetime short; removing a
|
|
710
710
|
key revokes every grant it minted.
|
|
711
711
|
|
|
712
|
+
### ATTACH options in functions and transaction hooks (secret ones included)
|
|
713
|
+
|
|
714
|
+
A catalog declares its ATTACH options (`attachOptions` on the descriptor, or
|
|
715
|
+
`attachOptionSpecs()`); a credential is declared `secret: true`. Every function call
|
|
716
|
+
and transaction hook of an attach reads the options with **`attachOptions()`**, secret
|
|
717
|
+
values included. The framework carries them for you, so you never pack options (and
|
|
718
|
+
never a credential) into your own `attach_opaque_data`:
|
|
719
|
+
|
|
720
|
+
```ts
|
|
721
|
+
import { attachOptions, ReadOnlyCatalogInterface, type CatalogAttachResult } from "@query-farm/vgi";
|
|
722
|
+
|
|
723
|
+
// In any function (bind, or init/process via params.initCall.bind_call):
|
|
724
|
+
const { api_key, region } = attachOptions(params.bindCall.attach_opaque_data);
|
|
725
|
+
|
|
726
|
+
// In a catalog method or transaction hook:
|
|
727
|
+
class MyCatalog extends ReadOnlyCatalogInterface {
|
|
728
|
+
override async attach(name: string, options?: Record<string, unknown>): Promise<CatalogAttachResult> {
|
|
729
|
+
const result = await super.attach(name, options);
|
|
730
|
+
return { ...result, supports_transactions: options?.transactional === true }; // no options in the bytes
|
|
731
|
+
}
|
|
732
|
+
override async transactionCommit(attach: Uint8Array, tx: Uint8Array) {
|
|
733
|
+
const { api_key } = this.attachOptions(attach);
|
|
734
|
+
// ...
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
```
|
|
738
|
+
|
|
739
|
+
How it works: `catalog_attach` appends the options to the catalog's attach bytes and
|
|
740
|
+
encrypts the secret ones (XChaCha20-Poly1305, a fresh random nonce each time) under
|
|
741
|
+
`HKDF-SHA256(root, info "vgi.attach_secret_options.v1")`, with the attach's
|
|
742
|
+
framework UUID as associated data — a blob copied into another attach value does not
|
|
743
|
+
open (`attach_opaque_data not recognized`). The framework strips all of it before
|
|
744
|
+
your code sees the attach bytes. A secret value is never in plaintext in any opaque
|
|
745
|
+
value, on any transport (the sealing spec's rule 5).
|
|
746
|
+
|
|
747
|
+
The root key is, in order:
|
|
748
|
+
|
|
749
|
+
1. `attachSecretKey` (`Worker`, `serveVgiWorker`, or `protocol` on `createVgiFetch`),
|
|
750
|
+
2. the HTTP signing key (`VGI_SIGNING_KEY`, or the one the worker minted at startup),
|
|
751
|
+
3. on stdio / AF_UNIX / launcher pools, the **host-local key file**, shared by every
|
|
752
|
+
VGI worker of the user on the host whatever its SDK:
|
|
753
|
+
`$VGI_ATTACH_SECRET_KEY_FILE`, else `$XDG_RUNTIME_DIR/vgi/attach-secret-options.key`,
|
|
754
|
+
else `<tmpdir>/vgi-<user>/attach-secret-options.key` — 32 random bytes, created
|
|
755
|
+
atomically on first use with mode 0600 in a 0700 directory, refused if anyone else
|
|
756
|
+
can read it. It is read only when a secret option actually has a value.
|
|
757
|
+
|
|
758
|
+
Every process that may receive a given attach must have the same root key (a
|
|
759
|
+
multi-instance HTTP deployment sets `VGI_SIGNING_KEY`). A runtime with no filesystem
|
|
760
|
+
(browser, Workers) and no signing key cannot accept a secret option: the ATTACH fails
|
|
761
|
+
and says so. Secret values, the key and the blob are never logged.
|
|
762
|
+
|
|
712
763
|
### Attach tickets: reattach as a user without their options (`vgi.attach_tickets.v1`)
|
|
713
764
|
|
|
714
765
|
A grant says *who* attaches; an **attach ticket** says *what*. While a user is
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const ATTACH_SECRET_KEY_FILE_ENV = "VGI_ATTACH_SECRET_KEY_FILE";
|
|
2
|
+
/** The key file path this process uses, per the cross-SDK rules above. */
|
|
3
|
+
export declare function hostLocalAttachSecretKeyPath(env?: Record<string, string | undefined>): string;
|
|
4
|
+
/**
|
|
5
|
+
* Read (creating on first use) the host-local key file at `path`
|
|
6
|
+
* (default {@link hostLocalAttachSecretKeyPath}). Synchronous and uncached;
|
|
7
|
+
* see {@link hostLocalAttachSecretKey} for the cached form the framework uses.
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadHostLocalAttachSecretKey(path?: string): Uint8Array;
|
|
10
|
+
/** The host-local root key, read once per process (per resolved path). */
|
|
11
|
+
export declare function hostLocalAttachSecretKey(): Promise<Uint8Array>;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/** HKDF `info`, and the AAD prefix (before the 0x00 and the attach uuid). */
|
|
2
|
+
export declare const ATTACH_SECRET_OPTIONS_INFO = "vgi.attach_secret_options.v1";
|
|
3
|
+
/** First byte of the secret blob: XChaCha20-Poly1305 with a 24-byte nonce. */
|
|
4
|
+
export declare const ATTACH_SECRET_OPTIONS_VERSION = 1;
|
|
5
|
+
/** A decoded ATTACH options record: option name → value, as `attach()` got it. */
|
|
6
|
+
export type AttachOptionValues = Readonly<Record<string, unknown>>;
|
|
7
|
+
/**
|
|
8
|
+
* Where the secret-options root key comes from. `explicit` is the optional
|
|
9
|
+
* `attachSecretKey` configuration; `signingKey` the HTTP sealing key.
|
|
10
|
+
* `hostLocal` is resolved lazily, and only when a secret option has a value.
|
|
11
|
+
*/
|
|
12
|
+
export interface AttachSecretKeySource {
|
|
13
|
+
explicit?: Uint8Array | undefined;
|
|
14
|
+
signingKey?: Uint8Array | undefined;
|
|
15
|
+
/** Override for tests; defaults to the host-local key file. */
|
|
16
|
+
hostLocal?: (() => Promise<Uint8Array>) | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** Raised when a secret option has a value but no key can be obtained. */
|
|
19
|
+
export declare class AttachSecretKeyUnavailableError extends Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
/** Raised by {@link attachOptions} for bytes the framework did not hand out. */
|
|
23
|
+
export declare class AttachOptionsUnavailableError extends Error {
|
|
24
|
+
constructor();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The AEAD key for secret ATTACH options derived from `root`:
|
|
28
|
+
* HKDF-SHA256(ikm = root, salt = empty, info = "vgi.attach_secret_options.v1", L = 32).
|
|
29
|
+
* The root itself is never used as the cipher key.
|
|
30
|
+
*/
|
|
31
|
+
export declare function deriveAttachSecretKey(root: Uint8Array): Promise<Uint8Array>;
|
|
32
|
+
/**
|
|
33
|
+
* The trailer the framework appends to `uuid || catalog_bytes` for an attach
|
|
34
|
+
* with options, or an empty array when there are none. Encrypts the secret
|
|
35
|
+
* options (obtaining the key only if there is one); never logs anything.
|
|
36
|
+
*
|
|
37
|
+
* @throws {AttachSecretKeyUnavailableError} A secret option has a value and no key can be obtained.
|
|
38
|
+
*/
|
|
39
|
+
export declare function packAttachOptionsTrailer(uuid: Uint8Array, optionsIpc: Uint8Array | null | undefined, secretNames: ReadonlySet<string>, keys: AttachSecretKeySource, fixedNonce?: Uint8Array): Promise<Uint8Array>;
|
|
40
|
+
/**
|
|
41
|
+
* Turn a FULL framework attach plaintext (`uuid || catalog_bytes [|| trailer]`,
|
|
42
|
+
* already unsealed on HTTP) into the catalog's own bytes, decrypting any
|
|
43
|
+
* secret options and recording all options for {@link attachOptions}.
|
|
44
|
+
*
|
|
45
|
+
* Returns a view of a private copy, so the record cannot be confused with
|
|
46
|
+
* other bytes of the request. A value shorter than a UUID passes through
|
|
47
|
+
* as-is (with no options), as before.
|
|
48
|
+
*
|
|
49
|
+
* @throws {OpaqueDataRejectedError} The trailer is malformed or the secret blob
|
|
50
|
+
* does not open (wrong key, tampered, or moved from another attach).
|
|
51
|
+
*/
|
|
52
|
+
export declare function openFrameworkAttach(full: Uint8Array, keys: AttachSecretKeySource): Promise<Uint8Array>;
|
|
53
|
+
/**
|
|
54
|
+
* The ATTACH options of the attach a call belongs to — every supplied option,
|
|
55
|
+
* secret ones included, decoded exactly as `CatalogInterface.attach()`
|
|
56
|
+
* received them.
|
|
57
|
+
*
|
|
58
|
+
* Pass the attach value the framework handed the call: `bindCall.attach_opaque_data`
|
|
59
|
+
* (bind, and `initCall.bind_call` at init/process, for every function kind), a
|
|
60
|
+
* table-buffering function's `attachId`, or the `attachOpaqueData` argument of
|
|
61
|
+
* a catalog method or transaction hook (`transactionBegin` / `transactionCommit`
|
|
62
|
+
* / `transactionRollback`). Any subarray of those bytes works too; a copy does
|
|
63
|
+
* not.
|
|
64
|
+
*
|
|
65
|
+
* Secret options (declared `secret: true`) reach this accessor on every
|
|
66
|
+
* transport without ever being in plaintext in `attach_opaque_data`: the
|
|
67
|
+
* framework encrypts them inside the attach value with a worker-held key. A
|
|
68
|
+
* catalog therefore never needs to pack options into its own attach bytes,
|
|
69
|
+
* and must not put a secret there.
|
|
70
|
+
*
|
|
71
|
+
* Returns `{}` for a null attach value (a call outside any attach) and for
|
|
72
|
+
* an attach that had no options.
|
|
73
|
+
*
|
|
74
|
+
* @throws {AttachOptionsUnavailableError} The bytes were not handed out by the framework.
|
|
75
|
+
*/
|
|
76
|
+
export declare function attachOptions(attachOpaqueData: Uint8Array | null | undefined): AttachOptionValues;
|
|
77
|
+
/**
|
|
78
|
+
* One option from {@link attachOptions}, looked up case-insensitively (DuckDB
|
|
79
|
+
* option names are case-insensitive). `undefined` when it was not supplied.
|
|
80
|
+
*/
|
|
81
|
+
export declare function attachOption(attachOpaqueData: Uint8Array | null | undefined, name: string): unknown;
|
|
82
|
+
/**
|
|
83
|
+
* Names (lower-cased) of the options `catalog` declares `secret: true` for
|
|
84
|
+
* catalog `name`, read from what it advertises in `catalogsInfo()` — the same
|
|
85
|
+
* specs the extension redacts by — or its `attachOptionSpecs(name)`.
|
|
86
|
+
*/
|
|
87
|
+
export declare function secretAttachOptionNames(catalog: {
|
|
88
|
+
catalogsInfo?(): unknown;
|
|
89
|
+
attachOptionSpecs?(name: string): Array<{
|
|
90
|
+
name: string;
|
|
91
|
+
secret?: boolean;
|
|
92
|
+
}>;
|
|
93
|
+
}, name: string, deserialize: (bytes: Uint8Array) => {
|
|
94
|
+
name: string;
|
|
95
|
+
secret?: boolean;
|
|
96
|
+
}): Promise<Set<string>>;
|
|
@@ -50,6 +50,12 @@ export interface AttachOptionSpec {
|
|
|
50
50
|
* api_key getenv('SALES_API_KEY'));
|
|
51
51
|
* ```
|
|
52
52
|
*
|
|
53
|
+
* Functions and transaction hooks read the value with `attachOptions()`
|
|
54
|
+
* (`CatalogInterface.attachOptions()` in hooks), like any other option: the
|
|
55
|
+
* framework carries it to them encrypted inside `attach_opaque_data` with a
|
|
56
|
+
* worker-held key, so it is never in plaintext in any opaque value. Never
|
|
57
|
+
* put a secret into your catalog's own attach bytes.
|
|
58
|
+
*
|
|
53
59
|
* Combines with `required` (a credential the catalog cannot attach without,
|
|
54
60
|
* which a client can then ask for before attaching). It is allowed together
|
|
55
61
|
* with `default`, but a secret option normally has none: a default would be
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AttachOpaqueData, CatalogAttachResult, CatalogInfo, CopyFromFormatInfo, FunctionInfo, IndexInfo, MacroInfo, CatalogContentsResult, SchemaInfo, TableInfo, TransactionOpaqueData, ViewInfo } from "./interface.js";
|
|
2
2
|
import { CatalogInterface } from "./interface.js";
|
|
3
|
+
import type { ScanPlanningFilters } from "./scan-planning.js";
|
|
3
4
|
export declare class CompositeCatalogInterface extends CatalogInterface {
|
|
4
5
|
private readonly _backends;
|
|
5
6
|
constructor(_backends: CatalogInterface[]);
|
|
@@ -22,6 +23,7 @@ export declare class CompositeCatalogInterface extends CatalogInterface {
|
|
|
22
23
|
tableGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Promise<TableInfo | null>;
|
|
23
24
|
tableScanFunctionGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Promise<any>;
|
|
24
25
|
tableScanBranchesGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Promise<any>;
|
|
26
|
+
tableScanBranchesPlan(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit: string | undefined, atValue: string | undefined, transactionOpaqueData: TransactionOpaqueData | undefined, pushdownFilters: ScanPlanningFilters | null): Promise<any>;
|
|
25
27
|
tableColumnStatisticsGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, transactionOpaqueData?: TransactionOpaqueData): Promise<{
|
|
26
28
|
bytes: Uint8Array;
|
|
27
29
|
cacheMaxAgeSeconds: number | null;
|
|
@@ -109,6 +109,17 @@ export interface TableDescriptor {
|
|
|
109
109
|
* a child does not satisfy its parent. Empty/undefined means no requirements. */
|
|
110
110
|
requiredFilters?: string[][][];
|
|
111
111
|
supportsTimeTravel?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Protocol 3.2 — when the client resolves this table's scan redirect.
|
|
114
|
+
* `"bind"` (default) keeps 3.1 behaviour. `"filtered"` makes the client call
|
|
115
|
+
* `catalog_table_scan_branches_get` once per scan, after collecting the
|
|
116
|
+
* query's predicates on the table, and pass them as `pushdown_filters` to
|
|
117
|
+
* the catalog's `tableScanBranchesPlan` (override it on a
|
|
118
|
+
* `ReadOnlyCatalogInterface` subclass); zero branches then means "no rows".
|
|
119
|
+
* Requires `columns` and no `function`: a `function` table inlines a fixed
|
|
120
|
+
* scan redirect.
|
|
121
|
+
*/
|
|
122
|
+
scanPlanning?: "bind" | "filtered";
|
|
112
123
|
/**
|
|
113
124
|
* Inline cardinality estimate/max surfaced through TableInfo. When set,
|
|
114
125
|
* the C++ extension uses these directly and skips the per-bind
|
|
@@ -85,6 +85,8 @@ export interface AttachCatalogInfo {
|
|
|
85
85
|
/** Encode an AttachCatalogInfo to Arrow IPC bytes (single-row batch). */
|
|
86
86
|
export declare const encodeAttachCatalogInfo: (v: AttachCatalogInfo) => Uint8Array;
|
|
87
87
|
import { type VgiDataType } from "../arrow/index.js";
|
|
88
|
+
import { type ColumnStatistics } from "../util/statistics.js";
|
|
89
|
+
import type { ScanPlanningFilters } from "./scan-planning.js";
|
|
88
90
|
/**
|
|
89
91
|
* Result from `tableScanFunctionGet` — tells the VGI DuckDB extension which
|
|
90
92
|
* DuckDB function to call to obtain the data for a table.
|
|
@@ -225,6 +227,20 @@ export interface ScanBranchInput {
|
|
|
225
227
|
* names a catalog-table branch's *source table's* schema.
|
|
226
228
|
*/
|
|
227
229
|
schemaPath?: string[] | null;
|
|
230
|
+
/**
|
|
231
|
+
* Protocol 3.2 — estimated rows this branch produces before any predicate.
|
|
232
|
+
* Cardinality estimation only; a client never trusts it as exact.
|
|
233
|
+
*/
|
|
234
|
+
rowCount?: number | bigint | null;
|
|
235
|
+
/**
|
|
236
|
+
* Protocol 3.2 — conservative per-column statistics for every row this
|
|
237
|
+
* branch produces, keyed by the table's declared column names (columns may
|
|
238
|
+
* be omitted). A client drops the branch when a query predicate is provably
|
|
239
|
+
* false against them, so wrong statistics silently lose rows: leave a column
|
|
240
|
+
* out rather than guess. Either the statistics themselves or an
|
|
241
|
+
* already-serialized `serializeColumnStatistics` payload.
|
|
242
|
+
*/
|
|
243
|
+
columnStatistics?: ColumnStatistics[] | Uint8Array | null;
|
|
228
244
|
}
|
|
229
245
|
/**
|
|
230
246
|
* Serialize a single branch's arguments to the nested-IPC form `ScanBranch`
|
|
@@ -251,8 +267,10 @@ export declare function encodeFormatOptions(options: Record<string, {
|
|
|
251
267
|
* `ScanBranchesResult` construction in the test fixture's
|
|
252
268
|
* `table_scan_branches_get`.
|
|
253
269
|
*
|
|
254
|
-
* An empty `branches` list is serialized verbatim
|
|
255
|
-
*
|
|
270
|
+
* An empty `branches` list is serialized verbatim. For a table declaring
|
|
271
|
+
* `scan_planning: "filtered"` (protocol 3.2) it means the scan produces no
|
|
272
|
+
* rows; for a `"bind"` table the client still rejects it (exercised by
|
|
273
|
+
* multi_branch_empty_branches.test).
|
|
256
274
|
*/
|
|
257
275
|
export declare function buildScanBranchesResult(branches: ScanBranchInput[], requiredExtensions?: string[]): {
|
|
258
276
|
branches: Uint8Array[];
|
|
@@ -440,6 +458,25 @@ export declare abstract class CatalogInterface {
|
|
|
440
458
|
* branches-aware C++ extension. Override for genuine multi-source tables.
|
|
441
459
|
*/
|
|
442
460
|
tableScanBranchesGet(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit?: string, atValue?: string, transactionOpaqueData?: TransactionOpaqueData): Awaitable<any>;
|
|
461
|
+
/**
|
|
462
|
+
* Plan a table's scan branches with the query's predicates (protocol 3.2).
|
|
463
|
+
*
|
|
464
|
+
* The worker calls this for every `catalog_table_scan_branches_get`. The
|
|
465
|
+
* default ignores `pushdownFilters` and returns `tableScanBranchesGet`, so
|
|
466
|
+
* catalogs written for 3.1 keep working unchanged. Override it for tables
|
|
467
|
+
* declaring `scan_planning: "filtered"` to return fewer branches or files.
|
|
468
|
+
*
|
|
469
|
+
* Every predicate is advisory: the client re-applies all of them, so return
|
|
470
|
+
* any superset of the branches and files that could hold matching rows, and
|
|
471
|
+
* never drop one that could. `ScanPlanningFilters.mayMatch` prunes
|
|
472
|
+
* candidates by min/max statistics. A `"filtered"` table may return zero
|
|
473
|
+
* branches, meaning the scan produces no rows.
|
|
474
|
+
*
|
|
475
|
+
* `pushdownFilters` is null when none were collected (bind-time planning, or
|
|
476
|
+
* no usable predicate); otherwise its predicates are decoded lazily against
|
|
477
|
+
* the table's declared columns (`tableGet(...).columns`).
|
|
478
|
+
*/
|
|
479
|
+
tableScanBranchesPlan(attachOpaqueData: AttachOpaqueData, schemaPath: string[], name: string, atUnit: string | undefined, atValue: string | undefined, transactionOpaqueData: TransactionOpaqueData | undefined, pushdownFilters: ScanPlanningFilters | null): Awaitable<any>;
|
|
443
480
|
/**
|
|
444
481
|
* Return serialized column statistics for a table, or null if none are
|
|
445
482
|
* available. The result is the IPC bytes of a ColumnStatistics RecordBatch
|
|
@@ -520,6 +557,21 @@ export declare abstract class CatalogInterface {
|
|
|
520
557
|
* worker cache. `this`, except for a composite, which routes to its backend.
|
|
521
558
|
*/
|
|
522
559
|
catalogContentsOwner(_attachOpaqueData: AttachOpaqueData): CatalogInterface;
|
|
560
|
+
/**
|
|
561
|
+
* The ATTACH options of the attach `attachOpaqueData` belongs to — every
|
|
562
|
+
* supplied option, secret ones (`AttachOptionSpec.secret`) included, as
|
|
563
|
+
* `attach()` received them. Works in every catalog method and transaction
|
|
564
|
+
* hook (`transactionBegin` / `transactionCommit` / `transactionRollback`)
|
|
565
|
+
* on the `attachOpaqueData` argument it was given; functions use the
|
|
566
|
+
* standalone {@link attachOptions} on `bindCall.attach_opaque_data`.
|
|
567
|
+
*
|
|
568
|
+
* The framework carries the options inside `attach_opaque_data` itself and
|
|
569
|
+
* encrypts the secret ones with a worker-held key, so they never appear in
|
|
570
|
+
* plaintext in any opaque value on any transport. An `attach()` override
|
|
571
|
+
* therefore never needs to pack options into its own attach bytes, and must
|
|
572
|
+
* not put a credential there.
|
|
573
|
+
*/
|
|
574
|
+
attachOptions(attachOpaqueData: AttachOpaqueData): Readonly<Record<string, unknown>>;
|
|
523
575
|
transactionBegin(attachOpaqueData: AttachOpaqueData): Awaitable<Uint8Array | null>;
|
|
524
576
|
transactionCommit(attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData): Awaitable<void>;
|
|
525
577
|
transactionRollback(attachOpaqueData: AttachOpaqueData, transactionOpaqueData: TransactionOpaqueData): Awaitable<void>;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type VgiDataType, type VgiSchema } from "../arrow/index.js";
|
|
2
|
+
import type { PushdownFilters } from "../filter-pushdown/evaluate.js";
|
|
3
|
+
/** Protocol 3.2 `TableInfo.scan_planning`: resolve the scan redirect at bind time (3.1 behaviour). */
|
|
4
|
+
export declare const SCAN_PLANNING_BIND = "bind";
|
|
5
|
+
/** Protocol 3.2 `TableInfo.scan_planning`: resolve it per scan with the query's filters. */
|
|
6
|
+
export declare const SCAN_PLANNING_FILTERED = "filtered";
|
|
7
|
+
/** When the client resolves a table's scan redirect. */
|
|
8
|
+
export type ScanPlanningMode = typeof SCAN_PLANNING_BIND | typeof SCAN_PLANNING_FILTERED;
|
|
9
|
+
/** Every legal `TableInfo.scan_planning` value. */
|
|
10
|
+
export declare const SCAN_PLANNING_MODES: readonly ScanPlanningMode[];
|
|
11
|
+
/**
|
|
12
|
+
* Validate a table's `scan_planning` value and return it (`"bind"` when
|
|
13
|
+
* absent). Unknown values are a protocol error, and a `"filtered"` table must
|
|
14
|
+
* not inline `scan_function`: its scan redirect is resolved per query with
|
|
15
|
+
* the query's filters.
|
|
16
|
+
*/
|
|
17
|
+
export declare function validateScanPlanning(tableName: string, scanPlanning: unknown, hasInlineScanFunction: boolean): ScanPlanningMode;
|
|
18
|
+
/**
|
|
19
|
+
* Per-column statistics describing a scan candidate (a file, a partition, a
|
|
20
|
+
* branch) — the same claims `ScanBranch.column_statistics` makes: every
|
|
21
|
+
* non-null value of the column lies within `[min, max]`; `hasNull: false`
|
|
22
|
+
* means the column has no NULLs; `hasNotNull: false` means it is entirely
|
|
23
|
+
* NULL. A missing `min`/`max`/flag claims nothing. `ColumnStatistics` (the
|
|
24
|
+
* type `serializeColumnStatistics` takes) satisfies this shape.
|
|
25
|
+
*/
|
|
26
|
+
export interface ScanCandidateStatistics {
|
|
27
|
+
columnName: string;
|
|
28
|
+
/** Arrow type of `min`/`max`; defaults to the column's declared type. */
|
|
29
|
+
arrowType?: VgiDataType | null;
|
|
30
|
+
min?: unknown;
|
|
31
|
+
max?: unknown;
|
|
32
|
+
hasNull?: boolean | null;
|
|
33
|
+
hasNotNull?: boolean | null;
|
|
34
|
+
}
|
|
35
|
+
type Awaitable<T> = T | Promise<T>;
|
|
36
|
+
/**
|
|
37
|
+
* The query predicates sent with a filtered `catalog_table_scan_branches_get`.
|
|
38
|
+
*
|
|
39
|
+
* `raw` is the wire bytes: an Arrow IPC stream holding one VGI Filter
|
|
40
|
+
* Encoding v2 snapshot batch whose column indexes refer to the table's
|
|
41
|
+
* declared columns (`TableInfo.columns`). `decode()` resolves those columns
|
|
42
|
+
* (at most once) and decodes the predicates; nothing is decoded until a hook
|
|
43
|
+
* asks.
|
|
44
|
+
*/
|
|
45
|
+
export declare class ScanPlanningFilters {
|
|
46
|
+
/** The wire bytes of the filter v2 snapshot. */
|
|
47
|
+
readonly raw: Uint8Array;
|
|
48
|
+
/** Resolves the table's declared columns, the schema the column indexes refer to. */
|
|
49
|
+
private readonly tableColumns;
|
|
50
|
+
private _decoded;
|
|
51
|
+
constructor(
|
|
52
|
+
/** The wire bytes of the filter v2 snapshot. */
|
|
53
|
+
raw: Uint8Array,
|
|
54
|
+
/** Resolves the table's declared columns, the schema the column indexes refer to. */
|
|
55
|
+
tableColumns: () => Awaitable<VgiSchema | null>);
|
|
56
|
+
/** Decode the predicates against the table's declared columns (cached). */
|
|
57
|
+
decode(): Promise<PushdownFilters>;
|
|
58
|
+
/**
|
|
59
|
+
* False only when the predicates provably exclude every row `statistics`
|
|
60
|
+
* describes. See `filtersMayMatch`.
|
|
61
|
+
*/
|
|
62
|
+
mayMatch(statistics: Iterable<ScanCandidateStatistics> | Readonly<Record<string, ScanCandidateStatistics>>): Promise<boolean>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Return false only when `filters` provably exclude every row described by
|
|
66
|
+
* `statistics`; use it to prune a manifest (files, partitions) before
|
|
67
|
+
* returning branches.
|
|
68
|
+
*
|
|
69
|
+
* Reasons over top-level conjuncts built from `AND`/`OR`, comparisons between
|
|
70
|
+
* a column and a literal (`=`, `!=`, `<`, `<=`, `>`, `>=`), `IN` lists and
|
|
71
|
+
* `IS [NOT] NULL`. Columns, predicates or values it cannot reason about —
|
|
72
|
+
* casts, function calls, incomparable literal types, columns without
|
|
73
|
+
* statistics — count as "may match", so the answer errs towards keeping data.
|
|
74
|
+
*/
|
|
75
|
+
export declare function filtersMayMatch(filters: PushdownFilters, statistics: Iterable<ScanCandidateStatistics> | Readonly<Record<string, ScanCandidateStatistics>>): boolean;
|
|
76
|
+
export {};
|
package/dist/client-entry.js
CHANGED
|
@@ -2667,7 +2667,8 @@ var TableInfoSchema = schema2([
|
|
|
2667
2667
|
field2("bind_result", binary2(), true),
|
|
2668
2668
|
field2("required_filters", list2(field2("item", list2(field2("item", list2(field2("item", utf82(), true)), true)), true)), false),
|
|
2669
2669
|
field2("options", binary2(), true),
|
|
2670
|
-
field2("layout", binary2(), true)
|
|
2670
|
+
field2("layout", binary2(), true),
|
|
2671
|
+
field2("scan_planning", utf82(), false)
|
|
2671
2672
|
]);
|
|
2672
2673
|
var ViewInfoSchema = schema2([
|
|
2673
2674
|
field2("comment", utf82(), true),
|
|
@@ -2991,7 +2992,9 @@ var ScanBranchSchema = schema2([
|
|
|
2991
2992
|
field2("format_name", utf82(), true),
|
|
2992
2993
|
field2("format_locations", list2(field2("item", utf82(), true)), true),
|
|
2993
2994
|
field2("format_options", binary2(), true),
|
|
2994
|
-
field2("schema_path", list2(field2("item", utf82(), true)), true)
|
|
2995
|
+
field2("schema_path", list2(field2("item", utf82(), true)), true),
|
|
2996
|
+
field2("row_count", int642(), true),
|
|
2997
|
+
field2("column_statistics", binary2(), true)
|
|
2995
2998
|
]);
|
|
2996
2999
|
var ScanSplitSchema = schema2([
|
|
2997
3000
|
field2("payload", binary2(), false),
|
|
@@ -3834,7 +3837,8 @@ var CatalogTableScanBranchesGetParamsSchema = schema2([
|
|
|
3834
3837
|
field2("name", utf82(), false),
|
|
3835
3838
|
field2("at_unit", utf82(), true),
|
|
3836
3839
|
field2("at_value", utf82(), true),
|
|
3837
|
-
field2("transaction_opaque_data", binary2(), true)
|
|
3840
|
+
field2("transaction_opaque_data", binary2(), true),
|
|
3841
|
+
field2("pushdown_filters", binary2(), true)
|
|
3838
3842
|
]);
|
|
3839
3843
|
var CatalogTableScanFunctionGetParamsSchema = schema2([
|
|
3840
3844
|
field2("attach_opaque_data", binary2(), false),
|
|
@@ -5440,6 +5444,29 @@ function wrapRpcWithErrorEnrichment(rpc) {
|
|
|
5440
5444
|
};
|
|
5441
5445
|
}
|
|
5442
5446
|
|
|
5447
|
+
// src/catalog/scan-planning.ts
|
|
5448
|
+
var SCAN_PLANNING_BIND = "bind";
|
|
5449
|
+
var SCAN_PLANNING_FILTERED = "filtered";
|
|
5450
|
+
var SCAN_PLANNING_MODES = Object.freeze([SCAN_PLANNING_BIND, SCAN_PLANNING_FILTERED]);
|
|
5451
|
+
function validateScanPlanning(tableName, scanPlanning, hasInlineScanFunction) {
|
|
5452
|
+
const mode = scanPlanning ?? SCAN_PLANNING_BIND;
|
|
5453
|
+
if (mode !== SCAN_PLANNING_BIND && mode !== SCAN_PLANNING_FILTERED) {
|
|
5454
|
+
throw new Error(`Table '${tableName}': scan_planning must be one of ${JSON.stringify(SCAN_PLANNING_MODES)}, got ${JSON.stringify(mode)}`);
|
|
5455
|
+
}
|
|
5456
|
+
if (mode === SCAN_PLANNING_FILTERED && hasInlineScanFunction) {
|
|
5457
|
+
throw new Error(`Table '${tableName}': scan_planning='filtered' cannot be combined with an inlined scan_function; ` + "the scan redirect must be resolved per query with the query's filters");
|
|
5458
|
+
}
|
|
5459
|
+
return mode;
|
|
5460
|
+
}
|
|
5461
|
+
var FLIPPED = {
|
|
5462
|
+
["eq" /* EQ */]: "eq" /* EQ */,
|
|
5463
|
+
["ne" /* NE */]: "ne" /* NE */,
|
|
5464
|
+
["lt" /* LT */]: "gt" /* GT */,
|
|
5465
|
+
["le" /* LE */]: "ge" /* GE */,
|
|
5466
|
+
["gt" /* GT */]: "lt" /* LT */,
|
|
5467
|
+
["ge" /* GE */]: "le" /* LE */
|
|
5468
|
+
};
|
|
5469
|
+
|
|
5443
5470
|
// src/catalog/column-metadata.ts
|
|
5444
5471
|
function scalarText(value) {
|
|
5445
5472
|
for (let i = 0;i < value.length; i++) {
|
|
@@ -5571,6 +5598,7 @@ function validateColumnMetadataIpc(bytes) {
|
|
|
5571
5598
|
vector(schema, 1, (f) => field(f, 0));
|
|
5572
5599
|
}
|
|
5573
5600
|
function validateTableInfoColumns(info) {
|
|
5601
|
+
validateScanPlanning(info.name, info.scan_planning, info.scan_function != null);
|
|
5574
5602
|
if (info.columns.length) {
|
|
5575
5603
|
validateColumnMetadataIpc(info.columns);
|
|
5576
5604
|
validateColumnExpressionsIpc(info.columns, info.schema_path);
|
|
@@ -6857,4 +6885,4 @@ export {
|
|
|
6857
6885
|
validateTableConstraints
|
|
6858
6886
|
};
|
|
6859
6887
|
|
|
6860
|
-
//# debugId=
|
|
6888
|
+
//# debugId=21F171AD00864D0C64756E2164756E21
|