@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
|
@@ -70,6 +70,7 @@ export interface TableInfo {
|
|
|
70
70
|
required_filters: string[][][];
|
|
71
71
|
options?: /** @ipc-record OptionState */ Uint8Array | null;
|
|
72
72
|
layout?: /** @ipc-record TableLayout */ Uint8Array | null;
|
|
73
|
+
scan_planning: string;
|
|
73
74
|
}
|
|
74
75
|
export interface ViewInfo {
|
|
75
76
|
comment?: string | null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Canonical fingerprint of the nested catalog wire schemas. */
|
|
2
|
-
export declare const VGI_CATALOG_CONTRACT_HASH = "
|
|
2
|
+
export declare const VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
|
|
3
3
|
export declare const CatalogInfoSchema: import("../index.core.js").VgiSchema;
|
|
4
4
|
export declare const SchemaInfoSchema: import("../index.core.js").VgiSchema;
|
|
5
5
|
export declare const TableInfoSchema: import("../index.core.js").VgiSchema;
|
|
@@ -3,7 +3,7 @@ import { type VgiSchema } from "../arrow/index.js";
|
|
|
3
3
|
/** The protocol's wire name: the `vgi_rpc.protocol` routing key and the HTTP path segment. */
|
|
4
4
|
export declare const VGI_PROTOCOL_NAME = "vgi.v3";
|
|
5
5
|
/** The protocol's semver, stamped on every request by a client of this protocol. */
|
|
6
|
-
export declare const VGI_PROTOCOL_VERSION = "3.
|
|
6
|
+
export declare const VGI_PROTOCOL_VERSION = "3.2.0";
|
|
7
7
|
/** What a unary handler returns: the result row, now or later. */
|
|
8
8
|
export type VgiReply<T> = T | ExternalRef | Promise<T | ExternalRef>;
|
|
9
9
|
/** The result of a unary method with no `result` column. */
|
|
@@ -672,6 +672,8 @@ export interface CatalogTableScanBranchesGetParams {
|
|
|
672
672
|
at_value: string | null;
|
|
673
673
|
/** The `transaction_opaque_data` column (`binary`, nullable). */
|
|
674
674
|
transaction_opaque_data: Uint8Array | null;
|
|
675
|
+
/** The `pushdown_filters` column (`binary`, nullable). */
|
|
676
|
+
pushdown_filters: Uint8Array | null;
|
|
675
677
|
}
|
|
676
678
|
/** The params of `catalog_table_scan_function_get`, one property per params-schema column. */
|
|
677
679
|
export interface CatalogTableScanFunctionGetParams {
|
|
@@ -1343,6 +1345,8 @@ export interface VgiService {
|
|
|
1343
1345
|
/**
|
|
1344
1346
|
* Get the list of scan branches for a multi-branch table. Returns `ScanBranchesResult` as IPC bytes.
|
|
1345
1347
|
*
|
|
1348
|
+
* Protocol 3.2: ``pushdown_filters`` carries the query's predicates on the table (an Arrow IPC stream holding one VGI Filter Encoding v2 snapshot batch; column indexes refer to ``TableInfo.columns``) when the table declares ``scan_planning = "filtered"``. Every predicate is advisory. ``None`` means none were collected. See ``docs/protocol/scan-planning.md``.
|
|
1349
|
+
*
|
|
1346
1350
|
* Additive successor to ``catalog_table_scan_function_get``. Workers that only implement the legacy method continue to work — the VGI extension's C++ side catches ``MethodNotImplementedError`` and falls back to the legacy RPC, wrapping the single-function result as a one-branch list. Workers that implement BOTH the legacy and the branches method guarantee single-process compatibility with both old and new extensions.
|
|
1347
1351
|
*
|
|
1348
1352
|
* Multi-branch tables compose a logical scan from N physical sources (canonical case: Kafka hot tier + Iceberg cold tier). The extension's optimizer rewrite stitches the branches together via ``LogicalSetOperation(UNION_ALL, ...)``, one arm per branch.
|
package/dist/index.core.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ export { attachOptions, attachOption, type AttachOptionValues, AttachOptionsUnav
|
|
|
38
38
|
export { hostLocalAttachSecretKeyPath, ATTACH_SECRET_KEY_FILE_ENV } from "./attach-secret-keyfile.js";
|
|
39
39
|
export { ATTACH_TICKET_OPTION, ATTACH_TICKET_PREFIX, ATTACH_TICKETS_PROTOCOL_NAME, ATTACH_TICKETS_PROTOCOL_VERSION, ATTACH_TICKET_SCHEMA, SEAL_ATTACH_REQUEST_SCHEMA, AttachTicketExpiredError, AttachTicketInvalidError, AttachTicketRequestError, SealAttachDeniedError, type AttachTicket, type AttachTicketClaims, type RestoredAttach, encodeAttachTicket, attachTicketAad, mintAttachTicket, openAttachTicket, redeemAttachTicket, } from "./attach-ticket.js";
|
|
40
40
|
export { type ColumnStatistics, serializeColumnStatistics } from "./util/statistics.js";
|
|
41
|
+
export { ScanPlanningFilters, filtersMayMatch, validateScanPlanning, SCAN_PLANNING_BIND, SCAN_PLANNING_FILTERED, SCAN_PLANNING_MODES, type ScanPlanningMode, type ScanCandidateStatistics, } from "./catalog/scan-planning.js";
|
|
41
42
|
export { toUint8Array } from "./util/bytes.js";
|
|
42
43
|
export { iterRows, batchFromRows, batchFromColumns, emptyBatch, filterBatch, projectSchema, projectBatch, batchToScalarDict, batchToSecretDict, safeNumber, } from "./util/arrow/index.js";
|
|
43
44
|
export { type SecretFields, type SecretsDict, secretType, secretsOfType, secretOfType, requireSecretOfType, secretByName, secretForScope, secretForScopeOfType, } from "./secrets/helpers.js";
|
package/dist/index.js
CHANGED
|
@@ -8950,7 +8950,7 @@ function decodeASDCollection(schema, bytes) {
|
|
|
8950
8950
|
|
|
8951
8951
|
// src/generated/vgi-protocol-schemas.ts
|
|
8952
8952
|
init_arrow();
|
|
8953
|
-
var VGI_CATALOG_CONTRACT_HASH = "
|
|
8953
|
+
var VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
|
|
8954
8954
|
var CatalogInfoSchema = schema2([
|
|
8955
8955
|
field2("name", utf82(), false),
|
|
8956
8956
|
field2("implementation_version", utf82(), true),
|
|
@@ -8986,7 +8986,8 @@ var TableInfoSchema = schema2([
|
|
|
8986
8986
|
field2("bind_result", binary2(), true),
|
|
8987
8987
|
field2("required_filters", list2(field2("item", list2(field2("item", list2(field2("item", utf82(), true)), true)), true)), false),
|
|
8988
8988
|
field2("options", binary2(), true),
|
|
8989
|
-
field2("layout", binary2(), true)
|
|
8989
|
+
field2("layout", binary2(), true),
|
|
8990
|
+
field2("scan_planning", utf82(), false)
|
|
8990
8991
|
]);
|
|
8991
8992
|
var ViewInfoSchema = schema2([
|
|
8992
8993
|
field2("comment", utf82(), true),
|
|
@@ -9310,7 +9311,9 @@ var ScanBranchSchema = schema2([
|
|
|
9310
9311
|
field2("format_name", utf82(), true),
|
|
9311
9312
|
field2("format_locations", list2(field2("item", utf82(), true)), true),
|
|
9312
9313
|
field2("format_options", binary2(), true),
|
|
9313
|
-
field2("schema_path", list2(field2("item", utf82(), true)), true)
|
|
9314
|
+
field2("schema_path", list2(field2("item", utf82(), true)), true),
|
|
9315
|
+
field2("row_count", int642(), true),
|
|
9316
|
+
field2("column_statistics", binary2(), true)
|
|
9314
9317
|
]);
|
|
9315
9318
|
var ScanSplitSchema = schema2([
|
|
9316
9319
|
field2("payload", binary2(), false),
|
|
@@ -10153,7 +10156,8 @@ var CatalogTableScanBranchesGetParamsSchema = schema2([
|
|
|
10153
10156
|
field2("name", utf82(), false),
|
|
10154
10157
|
field2("at_unit", utf82(), true),
|
|
10155
10158
|
field2("at_value", utf82(), true),
|
|
10156
|
-
field2("transaction_opaque_data", binary2(), true)
|
|
10159
|
+
field2("transaction_opaque_data", binary2(), true),
|
|
10160
|
+
field2("pushdown_filters", binary2(), true)
|
|
10157
10161
|
]);
|
|
10158
10162
|
var CatalogTableScanFunctionGetParamsSchema = schema2([
|
|
10159
10163
|
field2("attach_opaque_data", binary2(), false),
|
|
@@ -11699,6 +11703,14 @@ var encodeViewInfo = (v) => encodeASD(ViewInfoSchema, v);
|
|
|
11699
11703
|
var decodeViewInfo = (b) => decodeASD(ViewInfoSchema, b);
|
|
11700
11704
|
// src/catalog/interface.ts
|
|
11701
11705
|
init_arrow();
|
|
11706
|
+
|
|
11707
|
+
// src/util/statistics.ts
|
|
11708
|
+
init_arrow();
|
|
11709
|
+
function serializeColumnStatistics(stats, _cacheMaxAgeSeconds) {
|
|
11710
|
+
return serializeBatch(buildStatisticsBatch(stats));
|
|
11711
|
+
}
|
|
11712
|
+
|
|
11713
|
+
// src/catalog/interface.ts
|
|
11702
11714
|
var encodeCopyFromFormatInfo = (v) => encodeASD(CopyFromFormatInfoSchema, {
|
|
11703
11715
|
comment: v.comment ?? null,
|
|
11704
11716
|
tags: v.tags ?? {},
|
|
@@ -11779,9 +11791,34 @@ function encodeScanBranch(cols) {
|
|
|
11779
11791
|
format_name: [cols.format_name ?? null],
|
|
11780
11792
|
format_locations: [cols.format_locations ?? null],
|
|
11781
11793
|
format_options: [cols.format_options ?? null],
|
|
11782
|
-
schema_path: [cols.schema_path ?? null]
|
|
11794
|
+
schema_path: [cols.schema_path ?? null],
|
|
11795
|
+
row_count: [cols.row_count ?? null],
|
|
11796
|
+
column_statistics: [cols.column_statistics ?? null]
|
|
11783
11797
|
}), ScanBranchSchema));
|
|
11784
11798
|
}
|
|
11799
|
+
function branchStatistics(branch) {
|
|
11800
|
+
let rowCount = null;
|
|
11801
|
+
if (branch.rowCount != null) {
|
|
11802
|
+
if (typeof branch.rowCount === "number" && !Number.isSafeInteger(branch.rowCount)) {
|
|
11803
|
+
throw new Error(`ScanBranch.rowCount must be an integer, got ${branch.rowCount}`);
|
|
11804
|
+
}
|
|
11805
|
+
rowCount = BigInt(branch.rowCount);
|
|
11806
|
+
if (rowCount < 0n)
|
|
11807
|
+
throw new Error(`ScanBranch.rowCount must be >= 0, got ${rowCount}`);
|
|
11808
|
+
}
|
|
11809
|
+
let columnStatistics = null;
|
|
11810
|
+
const stats = branch.columnStatistics;
|
|
11811
|
+
if (stats instanceof Uint8Array) {
|
|
11812
|
+
columnStatistics = stats;
|
|
11813
|
+
} else if (stats != null) {
|
|
11814
|
+
const names = stats.map((s) => s.columnName);
|
|
11815
|
+
if (new Set(names).size !== names.length) {
|
|
11816
|
+
throw new Error("ScanBranch.columnStatistics names a column more than once");
|
|
11817
|
+
}
|
|
11818
|
+
columnStatistics = serializeColumnStatistics(stats);
|
|
11819
|
+
}
|
|
11820
|
+
return { row_count: rowCount, column_statistics: columnStatistics };
|
|
11821
|
+
}
|
|
11785
11822
|
function encodeFormatOptions(options) {
|
|
11786
11823
|
const fields = [];
|
|
11787
11824
|
const values = {};
|
|
@@ -11819,7 +11856,8 @@ function buildScanBranchesResult(branches, requiredExtensions = []) {
|
|
|
11819
11856
|
format_name: branch.formatName,
|
|
11820
11857
|
format_locations: branch.formatLocations,
|
|
11821
11858
|
format_options: branch.formatOptions,
|
|
11822
|
-
schema_path: branch.schemaPath
|
|
11859
|
+
schema_path: branch.schemaPath,
|
|
11860
|
+
...branchStatistics(branch)
|
|
11823
11861
|
}));
|
|
11824
11862
|
return {
|
|
11825
11863
|
branches: serializedBranches,
|
|
@@ -11942,6 +11980,9 @@ class CatalogInterface {
|
|
|
11942
11980
|
const legacy = this.tableScanFunctionGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData);
|
|
11943
11981
|
return isPromise(legacy) ? legacy.then((r) => singleBranchResult(r)) : singleBranchResult(legacy);
|
|
11944
11982
|
}
|
|
11983
|
+
tableScanBranchesPlan(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData, pushdownFilters) {
|
|
11984
|
+
return this.tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData);
|
|
11985
|
+
}
|
|
11945
11986
|
tableColumnStatisticsGet(attachOpaqueData, schemaPath, name, transactionOpaqueData) {
|
|
11946
11987
|
return null;
|
|
11947
11988
|
}
|
|
@@ -12072,6 +12113,220 @@ function sameBytes2(a, b) {
|
|
|
12072
12113
|
return false;
|
|
12073
12114
|
return true;
|
|
12074
12115
|
}
|
|
12116
|
+
// src/catalog/scan-planning.ts
|
|
12117
|
+
init_arrow();
|
|
12118
|
+
var SCAN_PLANNING_BIND = "bind";
|
|
12119
|
+
var SCAN_PLANNING_FILTERED = "filtered";
|
|
12120
|
+
var SCAN_PLANNING_MODES = Object.freeze([SCAN_PLANNING_BIND, SCAN_PLANNING_FILTERED]);
|
|
12121
|
+
function validateScanPlanning(tableName, scanPlanning, hasInlineScanFunction) {
|
|
12122
|
+
const mode = scanPlanning ?? SCAN_PLANNING_BIND;
|
|
12123
|
+
if (mode !== SCAN_PLANNING_BIND && mode !== SCAN_PLANNING_FILTERED) {
|
|
12124
|
+
throw new Error(`Table '${tableName}': scan_planning must be one of ${JSON.stringify(SCAN_PLANNING_MODES)}, got ${JSON.stringify(mode)}`);
|
|
12125
|
+
}
|
|
12126
|
+
if (mode === SCAN_PLANNING_FILTERED && hasInlineScanFunction) {
|
|
12127
|
+
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");
|
|
12128
|
+
}
|
|
12129
|
+
return mode;
|
|
12130
|
+
}
|
|
12131
|
+
|
|
12132
|
+
class ScanPlanningFilters {
|
|
12133
|
+
raw;
|
|
12134
|
+
tableColumns;
|
|
12135
|
+
_decoded = null;
|
|
12136
|
+
constructor(raw, tableColumns) {
|
|
12137
|
+
this.raw = raw;
|
|
12138
|
+
this.tableColumns = tableColumns;
|
|
12139
|
+
}
|
|
12140
|
+
decode() {
|
|
12141
|
+
if (this._decoded == null) {
|
|
12142
|
+
this._decoded = (async () => {
|
|
12143
|
+
const columns = await this.tableColumns();
|
|
12144
|
+
if (columns == null) {
|
|
12145
|
+
throw new Error("pushdown_filters: the table's declared columns could not be resolved");
|
|
12146
|
+
}
|
|
12147
|
+
return deserializeFilters(deserializeBatch(this.raw), { outputSchema: columns });
|
|
12148
|
+
})();
|
|
12149
|
+
this._decoded.catch(() => {
|
|
12150
|
+
this._decoded = null;
|
|
12151
|
+
});
|
|
12152
|
+
}
|
|
12153
|
+
return this._decoded;
|
|
12154
|
+
}
|
|
12155
|
+
async mayMatch(statistics) {
|
|
12156
|
+
return filtersMayMatch(await this.decode(), statistics);
|
|
12157
|
+
}
|
|
12158
|
+
}
|
|
12159
|
+
function filtersMayMatch(filters, statistics) {
|
|
12160
|
+
const list = Symbol.iterator in statistics ? statistics : Object.values(statistics);
|
|
12161
|
+
const byName = new Map;
|
|
12162
|
+
for (const stat of list)
|
|
12163
|
+
byName.set(stat.columnName, stat);
|
|
12164
|
+
if (byName.size === 0)
|
|
12165
|
+
return true;
|
|
12166
|
+
for (const predicate of filters.predicates) {
|
|
12167
|
+
if (provablyFalse(predicate.expression, byName))
|
|
12168
|
+
return false;
|
|
12169
|
+
}
|
|
12170
|
+
return true;
|
|
12171
|
+
}
|
|
12172
|
+
var FLIPPED = {
|
|
12173
|
+
["eq" /* EQ */]: "eq" /* EQ */,
|
|
12174
|
+
["ne" /* NE */]: "ne" /* NE */,
|
|
12175
|
+
["lt" /* LT */]: "gt" /* GT */,
|
|
12176
|
+
["le" /* LE */]: "ge" /* GE */,
|
|
12177
|
+
["gt" /* GT */]: "lt" /* LT */,
|
|
12178
|
+
["ge" /* GE */]: "le" /* LE */
|
|
12179
|
+
};
|
|
12180
|
+
function columnStat(expr, stats) {
|
|
12181
|
+
if (expr.node !== "column_ref")
|
|
12182
|
+
return null;
|
|
12183
|
+
const stat = stats.get(expr.columnName);
|
|
12184
|
+
return stat == null ? null : { stat, type: stat.arrowType ?? expr.dataType };
|
|
12185
|
+
}
|
|
12186
|
+
function outside(ref, value, valueType) {
|
|
12187
|
+
const lo = ref.stat.min ?? null;
|
|
12188
|
+
const hi = ref.stat.max ?? null;
|
|
12189
|
+
const cmpLo = lo == null ? null : compare2(lo, ref.type, value, valueType);
|
|
12190
|
+
const cmpHi = hi == null ? null : compare2(hi, ref.type, value, valueType);
|
|
12191
|
+
return cmpLo != null && cmpLo > 0 || cmpHi != null && cmpHi < 0;
|
|
12192
|
+
}
|
|
12193
|
+
function provablyFalse(expr, stats) {
|
|
12194
|
+
switch (expr.node) {
|
|
12195
|
+
case "and":
|
|
12196
|
+
return expr.children.some((child) => provablyFalse(child, stats));
|
|
12197
|
+
case "or":
|
|
12198
|
+
return expr.children.length > 0 && expr.children.every((child) => provablyFalse(child, stats));
|
|
12199
|
+
case "comparison": {
|
|
12200
|
+
let op = expr.op;
|
|
12201
|
+
let ref = columnStat(expr.left, stats);
|
|
12202
|
+
let literal = expr.right;
|
|
12203
|
+
if (ref == null) {
|
|
12204
|
+
ref = columnStat(expr.right, stats);
|
|
12205
|
+
literal = expr.left;
|
|
12206
|
+
op = FLIPPED[expr.op];
|
|
12207
|
+
}
|
|
12208
|
+
if (ref == null || op == null || !(op in FLIPPED) || literal.node !== "literal")
|
|
12209
|
+
return false;
|
|
12210
|
+
if (ref.stat.hasNotNull === false)
|
|
12211
|
+
return true;
|
|
12212
|
+
const c = literal.value;
|
|
12213
|
+
if (c == null)
|
|
12214
|
+
return true;
|
|
12215
|
+
const litType = literal.field?.type;
|
|
12216
|
+
const lo = ref.stat.min ?? null;
|
|
12217
|
+
const hi = ref.stat.max ?? null;
|
|
12218
|
+
const cmpLo = lo == null ? null : compare2(lo, ref.type, c, litType);
|
|
12219
|
+
const cmpHi = hi == null ? null : compare2(hi, ref.type, c, litType);
|
|
12220
|
+
switch (op) {
|
|
12221
|
+
case "eq" /* EQ */:
|
|
12222
|
+
return cmpLo != null && cmpLo > 0 || cmpHi != null && cmpHi < 0;
|
|
12223
|
+
case "ne" /* NE */:
|
|
12224
|
+
return cmpLo === 0 && cmpHi === 0;
|
|
12225
|
+
case "lt" /* LT */:
|
|
12226
|
+
return cmpLo != null && cmpLo >= 0;
|
|
12227
|
+
case "le" /* LE */:
|
|
12228
|
+
return cmpLo != null && cmpLo > 0;
|
|
12229
|
+
case "gt" /* GT */:
|
|
12230
|
+
return cmpHi != null && cmpHi <= 0;
|
|
12231
|
+
case "ge" /* GE */:
|
|
12232
|
+
return cmpHi != null && cmpHi < 0;
|
|
12233
|
+
default:
|
|
12234
|
+
return false;
|
|
12235
|
+
}
|
|
12236
|
+
}
|
|
12237
|
+
case "in": {
|
|
12238
|
+
if (expr.negated || expr.set.kind !== "literal")
|
|
12239
|
+
return false;
|
|
12240
|
+
const ref = columnStat(expr.expression, stats);
|
|
12241
|
+
if (ref == null)
|
|
12242
|
+
return false;
|
|
12243
|
+
if (ref.stat.hasNotNull === false)
|
|
12244
|
+
return true;
|
|
12245
|
+
if (ref.stat.min == null && ref.stat.max == null)
|
|
12246
|
+
return false;
|
|
12247
|
+
const setType = expr.set.field?.type;
|
|
12248
|
+
const values = expr.set.values.filter((v) => v != null);
|
|
12249
|
+
if (values.length === 0)
|
|
12250
|
+
return true;
|
|
12251
|
+
return values.every((v) => outside(ref, v, setType));
|
|
12252
|
+
}
|
|
12253
|
+
case "is_null": {
|
|
12254
|
+
const ref = columnStat(expr.expression, stats);
|
|
12255
|
+
if (ref == null)
|
|
12256
|
+
return false;
|
|
12257
|
+
return expr.negated ? ref.stat.hasNotNull === false : ref.stat.hasNull === false;
|
|
12258
|
+
}
|
|
12259
|
+
default:
|
|
12260
|
+
return false;
|
|
12261
|
+
}
|
|
12262
|
+
}
|
|
12263
|
+
function compare2(a, aType, b, bType) {
|
|
12264
|
+
const x = comparable(a, aType);
|
|
12265
|
+
const y = comparable(b, bType);
|
|
12266
|
+
if (x == null || y == null || x.kind !== y.kind)
|
|
12267
|
+
return null;
|
|
12268
|
+
const u = x.value;
|
|
12269
|
+
const v = y.value;
|
|
12270
|
+
if (typeof u === "number" && Number.isNaN(u))
|
|
12271
|
+
return null;
|
|
12272
|
+
if (typeof v === "number" && Number.isNaN(v))
|
|
12273
|
+
return null;
|
|
12274
|
+
if (typeof u === "string" && typeof v === "string")
|
|
12275
|
+
return compareCodePoints2(u, v);
|
|
12276
|
+
return u < v ? -1 : u > v ? 1 : 0;
|
|
12277
|
+
}
|
|
12278
|
+
function compareCodePoints2(a, b) {
|
|
12279
|
+
const ia = a[Symbol.iterator]();
|
|
12280
|
+
const ib = b[Symbol.iterator]();
|
|
12281
|
+
for (;; ) {
|
|
12282
|
+
const x = ia.next();
|
|
12283
|
+
const y = ib.next();
|
|
12284
|
+
if (x.done || y.done)
|
|
12285
|
+
return x.done && y.done ? 0 : x.done ? -1 : 1;
|
|
12286
|
+
const cx = x.value.codePointAt(0);
|
|
12287
|
+
const cy = y.value.codePointAt(0);
|
|
12288
|
+
if (cx !== cy)
|
|
12289
|
+
return cx < cy ? -1 : 1;
|
|
12290
|
+
}
|
|
12291
|
+
}
|
|
12292
|
+
var MS_PER_DAY2 = 86400000;
|
|
12293
|
+
var NS_PER_UNIT = [1000000000n, 1000000n, 1000n, 1n];
|
|
12294
|
+
function comparable(v, type) {
|
|
12295
|
+
if (type != null) {
|
|
12296
|
+
if (isDate(type)) {
|
|
12297
|
+
if (v instanceof Date)
|
|
12298
|
+
return { kind: "date", value: v.getTime() };
|
|
12299
|
+
if (typeof v === "number" || typeof v === "bigint") {
|
|
12300
|
+
return { kind: "date", value: type.unit === 0 ? Number(v) * MS_PER_DAY2 : Number(v) };
|
|
12301
|
+
}
|
|
12302
|
+
return null;
|
|
12303
|
+
}
|
|
12304
|
+
if (isTimestamp(type)) {
|
|
12305
|
+
const scale = NS_PER_UNIT[type.unit ?? -1];
|
|
12306
|
+
if (scale == null)
|
|
12307
|
+
return null;
|
|
12308
|
+
if (v instanceof Date)
|
|
12309
|
+
return { kind: "timestamp", value: BigInt(v.getTime()) * 1000000n };
|
|
12310
|
+
if (typeof v === "bigint")
|
|
12311
|
+
return { kind: "timestamp", value: v * scale };
|
|
12312
|
+
if (typeof v === "number" && Number.isSafeInteger(v))
|
|
12313
|
+
return { kind: "timestamp", value: BigInt(v) * scale };
|
|
12314
|
+
return null;
|
|
12315
|
+
}
|
|
12316
|
+
if (isDecimal(type) || isTime(type) || isInterval(type) || isDuration(type))
|
|
12317
|
+
return null;
|
|
12318
|
+
}
|
|
12319
|
+
if (v instanceof Date)
|
|
12320
|
+
return null;
|
|
12321
|
+
if (typeof v === "number" || typeof v === "bigint")
|
|
12322
|
+
return { kind: "numeric", value: v };
|
|
12323
|
+
if (typeof v === "string")
|
|
12324
|
+
return { kind: "string", value: v };
|
|
12325
|
+
if (typeof v === "boolean")
|
|
12326
|
+
return { kind: "boolean", value: v ? 1 : 0 };
|
|
12327
|
+
return null;
|
|
12328
|
+
}
|
|
12329
|
+
|
|
12075
12330
|
// src/catalog/column-metadata.ts
|
|
12076
12331
|
function scalarText(value) {
|
|
12077
12332
|
for (let i = 0;i < value.length; i++) {
|
|
@@ -12218,12 +12473,16 @@ function validateColumnMetadataIpc(bytes) {
|
|
|
12218
12473
|
vector(schema, 1, (f) => field(f, 0));
|
|
12219
12474
|
}
|
|
12220
12475
|
function validateTableInfoColumns(info) {
|
|
12476
|
+
validateScanPlanning(info.name, info.scan_planning, info.scan_function != null);
|
|
12221
12477
|
if (info.columns.length) {
|
|
12222
12478
|
validateColumnMetadataIpc(info.columns);
|
|
12223
12479
|
validateColumnExpressionsIpc(info.columns, info.schema_path);
|
|
12224
12480
|
}
|
|
12225
12481
|
}
|
|
12226
12482
|
function servedValidatedTableInfo(info) {
|
|
12483
|
+
const scanPlanning = validateScanPlanning(info.name, info.scan_planning, info.scan_function != null);
|
|
12484
|
+
if (info.scan_planning !== scanPlanning)
|
|
12485
|
+
info = { ...info, scan_planning: scanPlanning };
|
|
12227
12486
|
if (info.columns.length)
|
|
12228
12487
|
validateColumnMetadataIpc(info.columns);
|
|
12229
12488
|
const served = servedTableInfo(info);
|
|
@@ -12252,12 +12511,6 @@ function schemaDescriptorPath(schema) {
|
|
|
12252
12511
|
throw new Error("SchemaDescriptor requires a non-empty path");
|
|
12253
12512
|
}
|
|
12254
12513
|
|
|
12255
|
-
// src/util/statistics.ts
|
|
12256
|
-
init_arrow();
|
|
12257
|
-
function serializeColumnStatistics(stats, _cacheMaxAgeSeconds) {
|
|
12258
|
-
return serializeBatch(buildStatisticsBatch(stats));
|
|
12259
|
-
}
|
|
12260
|
-
|
|
12261
12514
|
// src/metadata/types.ts
|
|
12262
12515
|
var CatalogFunctionType;
|
|
12263
12516
|
((CatalogFunctionType) => {
|
|
@@ -12628,8 +12881,10 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
12628
12881
|
if (options.perAttachItemIds)
|
|
12629
12882
|
this.perAttachItemIds = true;
|
|
12630
12883
|
for (const sch of descriptor.schemas ?? [])
|
|
12631
|
-
for (const tbl of sch.tables ?? [])
|
|
12884
|
+
for (const tbl of sch.tables ?? []) {
|
|
12632
12885
|
validateWritableTable(tbl);
|
|
12886
|
+
validateTableScanPlanning(tbl);
|
|
12887
|
+
}
|
|
12633
12888
|
for (const sch of descriptor.schemas ?? []) {
|
|
12634
12889
|
for (const fn of sch.functions ?? [])
|
|
12635
12890
|
registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
|
|
@@ -12874,7 +13129,8 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
12874
13129
|
delete_function: t.deleteFunction ? inlineScanFunction(t.deleteFunction, undefined, this._schemaForFunction(t.deleteFunction)) : null,
|
|
12875
13130
|
cardinality_estimate: t.inlinedCardinality ? Number(t.inlinedCardinality.estimate) : null,
|
|
12876
13131
|
cardinality_max: t.inlinedCardinality ? Number(t.inlinedCardinality.max) : null,
|
|
12877
|
-
required_filters: requiredFilters
|
|
13132
|
+
required_filters: requiredFilters,
|
|
13133
|
+
scan_planning: t.scanPlanning ?? SCAN_PLANNING_BIND
|
|
12878
13134
|
};
|
|
12879
13135
|
}));
|
|
12880
13136
|
validateForeignKeyTargets(infos.map((info) => ({ schemaPath: info.schema_path, name: info.name, constraints: info.constraints })));
|
|
@@ -13407,6 +13663,12 @@ function sameSpelling(left, right) {
|
|
|
13407
13663
|
function writeFunctionOf(table, operation) {
|
|
13408
13664
|
return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
|
|
13409
13665
|
}
|
|
13666
|
+
function validateTableScanPlanning(table) {
|
|
13667
|
+
validateScanPlanning(table.name, table.scanPlanning, false);
|
|
13668
|
+
if (table.scanPlanning === SCAN_PLANNING_FILTERED && (table.function || !table.columns)) {
|
|
13669
|
+
throw new Error(`Table '${table.name}': scanPlanning 'filtered' requires columns and no function; the catalog's ` + "tableScanBranchesPlan supplies the scan per query");
|
|
13670
|
+
}
|
|
13671
|
+
}
|
|
13410
13672
|
function validateWritableTable(table) {
|
|
13411
13673
|
const modes = validateWriteResultModes(table.writeResultModes ?? {});
|
|
13412
13674
|
for (const operation of Object.keys(modes)) {
|
|
@@ -13547,6 +13809,9 @@ class CompositeCatalogInterface extends CatalogInterface {
|
|
|
13547
13809
|
async tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
|
|
13548
13810
|
return await this._route(attachOpaqueData).tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData);
|
|
13549
13811
|
}
|
|
13812
|
+
async tableScanBranchesPlan(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData, pushdownFilters) {
|
|
13813
|
+
return await this._route(attachOpaqueData).tableScanBranchesPlan(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData, pushdownFilters);
|
|
13814
|
+
}
|
|
13550
13815
|
async tableColumnStatisticsGet(attachOpaqueData, schemaPath, name, transactionOpaqueData) {
|
|
13551
13816
|
return await this._route(attachOpaqueData).tableColumnStatisticsGet(attachOpaqueData, schemaPath, name, transactionOpaqueData);
|
|
13552
13817
|
}
|
|
@@ -14164,7 +14429,7 @@ import {
|
|
|
14164
14429
|
Protocol
|
|
14165
14430
|
} from "@query-farm/vgi-rpc";
|
|
14166
14431
|
var VGI_PROTOCOL_NAME = "vgi.v3";
|
|
14167
|
-
var VGI_PROTOCOL_VERSION = "3.
|
|
14432
|
+
var VGI_PROTOCOL_VERSION = "3.2.0";
|
|
14168
14433
|
function exchangeStream(callbacks) {
|
|
14169
14434
|
return { kind: "exchange", ...callbacks };
|
|
14170
14435
|
}
|
|
@@ -15034,7 +15299,8 @@ var VGI_V3_METHODS = [
|
|
|
15034
15299
|
field2("name", utf82(), false),
|
|
15035
15300
|
field2("at_unit", utf82(), true),
|
|
15036
15301
|
field2("at_value", utf82(), true),
|
|
15037
|
-
field2("transaction_opaque_data", binary2(), true)
|
|
15302
|
+
field2("transaction_opaque_data", binary2(), true),
|
|
15303
|
+
field2("pushdown_filters", binary2(), true)
|
|
15038
15304
|
]),
|
|
15039
15305
|
result: schema2([
|
|
15040
15306
|
field2("result", binary2(), false)
|
|
@@ -17990,6 +18256,7 @@ function catalogAdminHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
|
17990
18256
|
|
|
17991
18257
|
// src/protocol/handlers/catalog/table.ts
|
|
17992
18258
|
import { MethodNotImplementedError as MethodNotImplementedError4 } from "@query-farm/vgi-rpc";
|
|
18259
|
+
init_arrow();
|
|
17993
18260
|
|
|
17994
18261
|
// src/catalog/unconstrained-columns.ts
|
|
17995
18262
|
init_arrow();
|
|
@@ -18130,7 +18397,17 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
|
18130
18397
|
});
|
|
18131
18398
|
const catalogTableScanBranchesGet = catalogHandler(keys, async (params) => {
|
|
18132
18399
|
const cat = getCatalog();
|
|
18133
|
-
const
|
|
18400
|
+
const attach = toUint8Array(params.attach_opaque_data);
|
|
18401
|
+
const tx = params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
|
|
18402
|
+
const schemaPath = params.schema_path;
|
|
18403
|
+
const name = params.name;
|
|
18404
|
+
const atUnit = params.at_unit;
|
|
18405
|
+
const atValue = params.at_value;
|
|
18406
|
+
const filters = params.pushdown_filters != null ? new ScanPlanningFilters(toUint8Array(params.pushdown_filters), async () => {
|
|
18407
|
+
const info = await cat.tableGet(attach, schemaPath, name, atUnit, atValue, tx);
|
|
18408
|
+
return info && info.columns.length ? deserializeSchema(toUint8Array(info.columns)) : null;
|
|
18409
|
+
}) : null;
|
|
18410
|
+
const branchesResult = await cat.tableScanBranchesPlan(attach, schemaPath, name, atUnit, atValue, tx, filters);
|
|
18134
18411
|
return wrapResult(branchesResult, ScanBranchesResultSchema);
|
|
18135
18412
|
});
|
|
18136
18413
|
const catalogTableCommentSet = catalogHandler(keys, async (params) => {
|
|
@@ -20150,9 +20427,13 @@ export {
|
|
|
20150
20427
|
S3CatalogObjectStorage,
|
|
20151
20428
|
S3CatalogPublicationRepository,
|
|
20152
20429
|
SCALAR_PROJECTION_PROFILE,
|
|
20430
|
+
SCAN_PLANNING_BIND,
|
|
20431
|
+
SCAN_PLANNING_FILTERED,
|
|
20432
|
+
SCAN_PLANNING_MODES,
|
|
20153
20433
|
SEAL_ATTACH_REQUEST_SCHEMA,
|
|
20154
20434
|
STATUS_KEY,
|
|
20155
20435
|
ScanFunctionResultSchema,
|
|
20436
|
+
ScanPlanningFilters,
|
|
20156
20437
|
SealAttachDeniedError,
|
|
20157
20438
|
StatusError,
|
|
20158
20439
|
TRANSACTION_DDL,
|
|
@@ -20304,6 +20585,7 @@ export {
|
|
|
20304
20585
|
encodeViewInfo,
|
|
20305
20586
|
field2 as field,
|
|
20306
20587
|
filterBatch,
|
|
20588
|
+
filtersMayMatch,
|
|
20307
20589
|
fixedSizeBinary2 as fixedSizeBinary,
|
|
20308
20590
|
fixedSizeList2 as fixedSizeList,
|
|
20309
20591
|
float,
|
|
@@ -20426,6 +20708,7 @@ export {
|
|
|
20426
20708
|
validateConstraintNullability,
|
|
20427
20709
|
validateForeignKeyTargets,
|
|
20428
20710
|
validateNumericCheckSql,
|
|
20711
|
+
validateScanPlanning,
|
|
20429
20712
|
validateTableConstraints,
|
|
20430
20713
|
validateWriteResultModes,
|
|
20431
20714
|
writeChangesBatch,
|
|
@@ -20436,4 +20719,4 @@ export {
|
|
|
20436
20719
|
writeRowsBatch
|
|
20437
20720
|
};
|
|
20438
20721
|
|
|
20439
|
-
//# debugId=
|
|
20722
|
+
//# debugId=52476A3C118F9C0764756E2164756E21
|