@query-farm/vgi 0.48.6 → 0.49.1
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 +1 -1
- package/dist/catalog/composite.d.ts +2 -0
- package/dist/catalog/descriptors.d.ts +11 -0
- package/dist/catalog/interface.d.ts +39 -2
- package/dist/catalog/scan-planning.d.ts +76 -0
- package/dist/client-entry.js +32 -4
- package/dist/client-entry.js.map +8 -7
- 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 +1 -0
- package/dist/index.js +301 -18
- package/dist/index.js.map +15 -14
- package/dist/protocol/dispatch.d.ts +2 -2
- package/dist/serve-entry.js +1552 -8
- package/dist/serve-entry.js.map +15 -10
- package/dist/worker-cf-entry.d.ts +2 -2
- package/dist/worker-cf-entry.js +327 -11
- package/dist/worker-cf-entry.js.map +16 -15
- package/package.json +1 -1
- 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 +78 -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 +11 -0
- package/src/protocol/dispatch.ts +2 -2
- package/src/protocol/handlers/catalog/table.ts +19 -8
- package/src/worker-cf-entry.ts +9 -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
|
|
@@ -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
|
|
@@ -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
|