@query-farm/vgi 0.48.5 → 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 +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
|
@@ -3,9 +3,9 @@ export type { VgiFetchOptions } from "./http/fetch.js";
|
|
|
3
3
|
export type { HostingOptions } from "./rpc-server.js";
|
|
4
4
|
export { AuthUnavailableError, GrantKeys, GrantRefusedError, IdentityUnavailableError, StatusError, } from "@query-farm/vgi-rpc";
|
|
5
5
|
export type { GrantMinter, IssuedGrant, TokenIdentity, TokenResolver } from "@query-farm/vgi-rpc";
|
|
6
|
-
export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, BindResultSchema, ScanFunctionResultSchema, secretType, secretsOfType, secretOfType, requireSecretOfType, secretByName, secretForScope, secretForScopeOfType, normalizeRequiredSecrets, } from "./index.core.js";
|
|
6
|
+
export { defineScalarFunction, defineTableFunction, defineAggregate, defineTableInOutFunction, defineRowTransformFunction, parentRowsMetadata, PARENT_ROW_METADATA_KEY, moreOutputMetadata, constraintSpecFields, cacheControlMetadata, FunctionRegistry, ReadOnlyCatalogInterface, CompositeCatalogInterface, CatalogInterface, Arguments, FunctionType, serializeAttachOptionSpec, serializeAttachOptionSpecs, serializeColumnStatistics, buildScanBranchesResult, ScanPlanningFilters, filtersMayMatch, SCAN_PLANNING_BIND, SCAN_PLANNING_FILTERED, BindResultSchema, ScanFunctionResultSchema, secretType, secretsOfType, secretOfType, requireSecretOfType, secretByName, secretForScope, secretForScopeOfType, normalizeRequiredSecrets, } from "./index.core.js";
|
|
7
7
|
export * from "./catalog/public-codecs.js";
|
|
8
|
-
export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, ConstraintRecordSpec, ConstraintRecordView, SecretFields, SecretsDict, RequiredSecret, SecretRequirement, SecretRequirementSpec, } from "./index.core.js";
|
|
8
|
+
export type { CacheControl, CacheScope, AttachOptionSpec, ColumnStatistics, ScanBranchInput, ScanPlanningMode, ScanCandidateStatistics, CatalogAttachResult, CatalogDescriptor, CatalogInfo, TableInfo, AttachOpaqueData, TransactionOpaqueData, SchemaInfo, VgiFunction, TableProcessParams, ArgumentSpec, ArgumentConstraints, RowTransformConfig, RowTransformProcessParams, TableInOutBindParams, ConstraintRecordSpec, ConstraintRecordView, SecretFields, SecretsDict, RequiredSecret, SecretRequirement, SecretRequirementSpec, } from "./index.core.js";
|
|
9
9
|
export type { ProtocolConfig } from "./protocol/dispatch.js";
|
|
10
10
|
export type { LandingInfo } from "./http/landing.js";
|
|
11
11
|
export { createLandingRoutes } from "./http/landing.js";
|
package/dist/worker-cf-entry.js
CHANGED
|
@@ -4923,7 +4923,7 @@ import {
|
|
|
4923
4923
|
Protocol
|
|
4924
4924
|
} from "@query-farm/vgi-rpc";
|
|
4925
4925
|
var VGI_PROTOCOL_NAME = "vgi.v3";
|
|
4926
|
-
var VGI_PROTOCOL_VERSION = "3.
|
|
4926
|
+
var VGI_PROTOCOL_VERSION = "3.2.0";
|
|
4927
4927
|
function exchangeStream(callbacks) {
|
|
4928
4928
|
return { kind: "exchange", ...callbacks };
|
|
4929
4929
|
}
|
|
@@ -5793,7 +5793,8 @@ var VGI_V3_METHODS = [
|
|
|
5793
5793
|
field2("name", utf82(), false),
|
|
5794
5794
|
field2("at_unit", utf82(), true),
|
|
5795
5795
|
field2("at_value", utf82(), true),
|
|
5796
|
-
field2("transaction_opaque_data", binary2(), true)
|
|
5796
|
+
field2("transaction_opaque_data", binary2(), true),
|
|
5797
|
+
field2("pushdown_filters", binary2(), true)
|
|
5797
5798
|
]),
|
|
5798
5799
|
result: schema2([
|
|
5799
5800
|
field2("result", binary2(), false)
|
|
@@ -6405,7 +6406,7 @@ init_arrow();
|
|
|
6405
6406
|
|
|
6406
6407
|
// src/generated/vgi-protocol-schemas.ts
|
|
6407
6408
|
init_arrow();
|
|
6408
|
-
var VGI_CATALOG_CONTRACT_HASH = "
|
|
6409
|
+
var VGI_CATALOG_CONTRACT_HASH = "d9304d52d78b0ceb90319d9a83759781df4a711b72443790654335c8cfcad9bf";
|
|
6409
6410
|
var CatalogInfoSchema = schema2([
|
|
6410
6411
|
field2("name", utf82(), false),
|
|
6411
6412
|
field2("implementation_version", utf82(), true),
|
|
@@ -6441,7 +6442,8 @@ var TableInfoSchema = schema2([
|
|
|
6441
6442
|
field2("bind_result", binary2(), true),
|
|
6442
6443
|
field2("required_filters", list2(field2("item", list2(field2("item", list2(field2("item", utf82(), true)), true)), true)), false),
|
|
6443
6444
|
field2("options", binary2(), true),
|
|
6444
|
-
field2("layout", binary2(), true)
|
|
6445
|
+
field2("layout", binary2(), true),
|
|
6446
|
+
field2("scan_planning", utf82(), false)
|
|
6445
6447
|
]);
|
|
6446
6448
|
var ViewInfoSchema = schema2([
|
|
6447
6449
|
field2("comment", utf82(), true),
|
|
@@ -6765,7 +6767,9 @@ var ScanBranchSchema = schema2([
|
|
|
6765
6767
|
field2("format_name", utf82(), true),
|
|
6766
6768
|
field2("format_locations", list2(field2("item", utf82(), true)), true),
|
|
6767
6769
|
field2("format_options", binary2(), true),
|
|
6768
|
-
field2("schema_path", list2(field2("item", utf82(), true)), true)
|
|
6770
|
+
field2("schema_path", list2(field2("item", utf82(), true)), true),
|
|
6771
|
+
field2("row_count", int642(), true),
|
|
6772
|
+
field2("column_statistics", binary2(), true)
|
|
6769
6773
|
]);
|
|
6770
6774
|
var ScanSplitSchema = schema2([
|
|
6771
6775
|
field2("payload", binary2(), false),
|
|
@@ -7608,7 +7612,8 @@ var CatalogTableScanBranchesGetParamsSchema = schema2([
|
|
|
7608
7612
|
field2("name", utf82(), false),
|
|
7609
7613
|
field2("at_unit", utf82(), true),
|
|
7610
7614
|
field2("at_value", utf82(), true),
|
|
7611
|
-
field2("transaction_opaque_data", binary2(), true)
|
|
7615
|
+
field2("transaction_opaque_data", binary2(), true),
|
|
7616
|
+
field2("pushdown_filters", binary2(), true)
|
|
7612
7617
|
]);
|
|
7613
7618
|
var CatalogTableScanFunctionGetParamsSchema = schema2([
|
|
7614
7619
|
field2("attach_opaque_data", binary2(), false),
|
|
@@ -12297,6 +12302,220 @@ function servedTableInfo(info) {
|
|
|
12297
12302
|
return served === schema ? info : { ...info, columns: serializeSchema(served) };
|
|
12298
12303
|
}
|
|
12299
12304
|
|
|
12305
|
+
// src/catalog/scan-planning.ts
|
|
12306
|
+
init_arrow();
|
|
12307
|
+
var SCAN_PLANNING_BIND = "bind";
|
|
12308
|
+
var SCAN_PLANNING_FILTERED = "filtered";
|
|
12309
|
+
var SCAN_PLANNING_MODES = Object.freeze([SCAN_PLANNING_BIND, SCAN_PLANNING_FILTERED]);
|
|
12310
|
+
function validateScanPlanning(tableName, scanPlanning, hasInlineScanFunction) {
|
|
12311
|
+
const mode = scanPlanning ?? SCAN_PLANNING_BIND;
|
|
12312
|
+
if (mode !== SCAN_PLANNING_BIND && mode !== SCAN_PLANNING_FILTERED) {
|
|
12313
|
+
throw new Error(`Table '${tableName}': scan_planning must be one of ${JSON.stringify(SCAN_PLANNING_MODES)}, got ${JSON.stringify(mode)}`);
|
|
12314
|
+
}
|
|
12315
|
+
if (mode === SCAN_PLANNING_FILTERED && hasInlineScanFunction) {
|
|
12316
|
+
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");
|
|
12317
|
+
}
|
|
12318
|
+
return mode;
|
|
12319
|
+
}
|
|
12320
|
+
|
|
12321
|
+
class ScanPlanningFilters {
|
|
12322
|
+
raw;
|
|
12323
|
+
tableColumns;
|
|
12324
|
+
_decoded = null;
|
|
12325
|
+
constructor(raw, tableColumns) {
|
|
12326
|
+
this.raw = raw;
|
|
12327
|
+
this.tableColumns = tableColumns;
|
|
12328
|
+
}
|
|
12329
|
+
decode() {
|
|
12330
|
+
if (this._decoded == null) {
|
|
12331
|
+
this._decoded = (async () => {
|
|
12332
|
+
const columns = await this.tableColumns();
|
|
12333
|
+
if (columns == null) {
|
|
12334
|
+
throw new Error("pushdown_filters: the table's declared columns could not be resolved");
|
|
12335
|
+
}
|
|
12336
|
+
return deserializeFilters(deserializeBatch(this.raw), { outputSchema: columns });
|
|
12337
|
+
})();
|
|
12338
|
+
this._decoded.catch(() => {
|
|
12339
|
+
this._decoded = null;
|
|
12340
|
+
});
|
|
12341
|
+
}
|
|
12342
|
+
return this._decoded;
|
|
12343
|
+
}
|
|
12344
|
+
async mayMatch(statistics) {
|
|
12345
|
+
return filtersMayMatch(await this.decode(), statistics);
|
|
12346
|
+
}
|
|
12347
|
+
}
|
|
12348
|
+
function filtersMayMatch(filters, statistics) {
|
|
12349
|
+
const list = Symbol.iterator in statistics ? statistics : Object.values(statistics);
|
|
12350
|
+
const byName = new Map;
|
|
12351
|
+
for (const stat of list)
|
|
12352
|
+
byName.set(stat.columnName, stat);
|
|
12353
|
+
if (byName.size === 0)
|
|
12354
|
+
return true;
|
|
12355
|
+
for (const predicate of filters.predicates) {
|
|
12356
|
+
if (provablyFalse(predicate.expression, byName))
|
|
12357
|
+
return false;
|
|
12358
|
+
}
|
|
12359
|
+
return true;
|
|
12360
|
+
}
|
|
12361
|
+
var FLIPPED = {
|
|
12362
|
+
["eq" /* EQ */]: "eq" /* EQ */,
|
|
12363
|
+
["ne" /* NE */]: "ne" /* NE */,
|
|
12364
|
+
["lt" /* LT */]: "gt" /* GT */,
|
|
12365
|
+
["le" /* LE */]: "ge" /* GE */,
|
|
12366
|
+
["gt" /* GT */]: "lt" /* LT */,
|
|
12367
|
+
["ge" /* GE */]: "le" /* LE */
|
|
12368
|
+
};
|
|
12369
|
+
function columnStat(expr, stats) {
|
|
12370
|
+
if (expr.node !== "column_ref")
|
|
12371
|
+
return null;
|
|
12372
|
+
const stat = stats.get(expr.columnName);
|
|
12373
|
+
return stat == null ? null : { stat, type: stat.arrowType ?? expr.dataType };
|
|
12374
|
+
}
|
|
12375
|
+
function outside(ref, value, valueType) {
|
|
12376
|
+
const lo = ref.stat.min ?? null;
|
|
12377
|
+
const hi = ref.stat.max ?? null;
|
|
12378
|
+
const cmpLo = lo == null ? null : compare2(lo, ref.type, value, valueType);
|
|
12379
|
+
const cmpHi = hi == null ? null : compare2(hi, ref.type, value, valueType);
|
|
12380
|
+
return cmpLo != null && cmpLo > 0 || cmpHi != null && cmpHi < 0;
|
|
12381
|
+
}
|
|
12382
|
+
function provablyFalse(expr, stats) {
|
|
12383
|
+
switch (expr.node) {
|
|
12384
|
+
case "and":
|
|
12385
|
+
return expr.children.some((child) => provablyFalse(child, stats));
|
|
12386
|
+
case "or":
|
|
12387
|
+
return expr.children.length > 0 && expr.children.every((child) => provablyFalse(child, stats));
|
|
12388
|
+
case "comparison": {
|
|
12389
|
+
let op = expr.op;
|
|
12390
|
+
let ref = columnStat(expr.left, stats);
|
|
12391
|
+
let literal = expr.right;
|
|
12392
|
+
if (ref == null) {
|
|
12393
|
+
ref = columnStat(expr.right, stats);
|
|
12394
|
+
literal = expr.left;
|
|
12395
|
+
op = FLIPPED[expr.op];
|
|
12396
|
+
}
|
|
12397
|
+
if (ref == null || op == null || !(op in FLIPPED) || literal.node !== "literal")
|
|
12398
|
+
return false;
|
|
12399
|
+
if (ref.stat.hasNotNull === false)
|
|
12400
|
+
return true;
|
|
12401
|
+
const c = literal.value;
|
|
12402
|
+
if (c == null)
|
|
12403
|
+
return true;
|
|
12404
|
+
const litType = literal.field?.type;
|
|
12405
|
+
const lo = ref.stat.min ?? null;
|
|
12406
|
+
const hi = ref.stat.max ?? null;
|
|
12407
|
+
const cmpLo = lo == null ? null : compare2(lo, ref.type, c, litType);
|
|
12408
|
+
const cmpHi = hi == null ? null : compare2(hi, ref.type, c, litType);
|
|
12409
|
+
switch (op) {
|
|
12410
|
+
case "eq" /* EQ */:
|
|
12411
|
+
return cmpLo != null && cmpLo > 0 || cmpHi != null && cmpHi < 0;
|
|
12412
|
+
case "ne" /* NE */:
|
|
12413
|
+
return cmpLo === 0 && cmpHi === 0;
|
|
12414
|
+
case "lt" /* LT */:
|
|
12415
|
+
return cmpLo != null && cmpLo >= 0;
|
|
12416
|
+
case "le" /* LE */:
|
|
12417
|
+
return cmpLo != null && cmpLo > 0;
|
|
12418
|
+
case "gt" /* GT */:
|
|
12419
|
+
return cmpHi != null && cmpHi <= 0;
|
|
12420
|
+
case "ge" /* GE */:
|
|
12421
|
+
return cmpHi != null && cmpHi < 0;
|
|
12422
|
+
default:
|
|
12423
|
+
return false;
|
|
12424
|
+
}
|
|
12425
|
+
}
|
|
12426
|
+
case "in": {
|
|
12427
|
+
if (expr.negated || expr.set.kind !== "literal")
|
|
12428
|
+
return false;
|
|
12429
|
+
const ref = columnStat(expr.expression, stats);
|
|
12430
|
+
if (ref == null)
|
|
12431
|
+
return false;
|
|
12432
|
+
if (ref.stat.hasNotNull === false)
|
|
12433
|
+
return true;
|
|
12434
|
+
if (ref.stat.min == null && ref.stat.max == null)
|
|
12435
|
+
return false;
|
|
12436
|
+
const setType = expr.set.field?.type;
|
|
12437
|
+
const values = expr.set.values.filter((v) => v != null);
|
|
12438
|
+
if (values.length === 0)
|
|
12439
|
+
return true;
|
|
12440
|
+
return values.every((v) => outside(ref, v, setType));
|
|
12441
|
+
}
|
|
12442
|
+
case "is_null": {
|
|
12443
|
+
const ref = columnStat(expr.expression, stats);
|
|
12444
|
+
if (ref == null)
|
|
12445
|
+
return false;
|
|
12446
|
+
return expr.negated ? ref.stat.hasNotNull === false : ref.stat.hasNull === false;
|
|
12447
|
+
}
|
|
12448
|
+
default:
|
|
12449
|
+
return false;
|
|
12450
|
+
}
|
|
12451
|
+
}
|
|
12452
|
+
function compare2(a, aType, b, bType) {
|
|
12453
|
+
const x = comparable(a, aType);
|
|
12454
|
+
const y = comparable(b, bType);
|
|
12455
|
+
if (x == null || y == null || x.kind !== y.kind)
|
|
12456
|
+
return null;
|
|
12457
|
+
const u = x.value;
|
|
12458
|
+
const v = y.value;
|
|
12459
|
+
if (typeof u === "number" && Number.isNaN(u))
|
|
12460
|
+
return null;
|
|
12461
|
+
if (typeof v === "number" && Number.isNaN(v))
|
|
12462
|
+
return null;
|
|
12463
|
+
if (typeof u === "string" && typeof v === "string")
|
|
12464
|
+
return compareCodePoints2(u, v);
|
|
12465
|
+
return u < v ? -1 : u > v ? 1 : 0;
|
|
12466
|
+
}
|
|
12467
|
+
function compareCodePoints2(a, b) {
|
|
12468
|
+
const ia = a[Symbol.iterator]();
|
|
12469
|
+
const ib = b[Symbol.iterator]();
|
|
12470
|
+
for (;; ) {
|
|
12471
|
+
const x = ia.next();
|
|
12472
|
+
const y = ib.next();
|
|
12473
|
+
if (x.done || y.done)
|
|
12474
|
+
return x.done && y.done ? 0 : x.done ? -1 : 1;
|
|
12475
|
+
const cx = x.value.codePointAt(0);
|
|
12476
|
+
const cy = y.value.codePointAt(0);
|
|
12477
|
+
if (cx !== cy)
|
|
12478
|
+
return cx < cy ? -1 : 1;
|
|
12479
|
+
}
|
|
12480
|
+
}
|
|
12481
|
+
var MS_PER_DAY2 = 86400000;
|
|
12482
|
+
var NS_PER_UNIT = [1000000000n, 1000000n, 1000n, 1n];
|
|
12483
|
+
function comparable(v, type) {
|
|
12484
|
+
if (type != null) {
|
|
12485
|
+
if (isDate(type)) {
|
|
12486
|
+
if (v instanceof Date)
|
|
12487
|
+
return { kind: "date", value: v.getTime() };
|
|
12488
|
+
if (typeof v === "number" || typeof v === "bigint") {
|
|
12489
|
+
return { kind: "date", value: type.unit === 0 ? Number(v) * MS_PER_DAY2 : Number(v) };
|
|
12490
|
+
}
|
|
12491
|
+
return null;
|
|
12492
|
+
}
|
|
12493
|
+
if (isTimestamp(type)) {
|
|
12494
|
+
const scale = NS_PER_UNIT[type.unit ?? -1];
|
|
12495
|
+
if (scale == null)
|
|
12496
|
+
return null;
|
|
12497
|
+
if (v instanceof Date)
|
|
12498
|
+
return { kind: "timestamp", value: BigInt(v.getTime()) * 1000000n };
|
|
12499
|
+
if (typeof v === "bigint")
|
|
12500
|
+
return { kind: "timestamp", value: v * scale };
|
|
12501
|
+
if (typeof v === "number" && Number.isSafeInteger(v))
|
|
12502
|
+
return { kind: "timestamp", value: BigInt(v) * scale };
|
|
12503
|
+
return null;
|
|
12504
|
+
}
|
|
12505
|
+
if (isDecimal(type) || isTime(type) || isInterval(type) || isDuration(type))
|
|
12506
|
+
return null;
|
|
12507
|
+
}
|
|
12508
|
+
if (v instanceof Date)
|
|
12509
|
+
return null;
|
|
12510
|
+
if (typeof v === "number" || typeof v === "bigint")
|
|
12511
|
+
return { kind: "numeric", value: v };
|
|
12512
|
+
if (typeof v === "string")
|
|
12513
|
+
return { kind: "string", value: v };
|
|
12514
|
+
if (typeof v === "boolean")
|
|
12515
|
+
return { kind: "boolean", value: v ? 1 : 0 };
|
|
12516
|
+
return null;
|
|
12517
|
+
}
|
|
12518
|
+
|
|
12300
12519
|
// src/catalog/column-metadata.ts
|
|
12301
12520
|
function scalarText(value) {
|
|
12302
12521
|
for (let i = 0;i < value.length; i++) {
|
|
@@ -12443,12 +12662,16 @@ function validateColumnMetadataIpc(bytes) {
|
|
|
12443
12662
|
vector(schema, 1, (f) => field(f, 0));
|
|
12444
12663
|
}
|
|
12445
12664
|
function validateTableInfoColumns(info) {
|
|
12665
|
+
validateScanPlanning(info.name, info.scan_planning, info.scan_function != null);
|
|
12446
12666
|
if (info.columns.length) {
|
|
12447
12667
|
validateColumnMetadataIpc(info.columns);
|
|
12448
12668
|
validateColumnExpressionsIpc(info.columns, info.schema_path);
|
|
12449
12669
|
}
|
|
12450
12670
|
}
|
|
12451
12671
|
function servedValidatedTableInfo(info) {
|
|
12672
|
+
const scanPlanning = validateScanPlanning(info.name, info.scan_planning, info.scan_function != null);
|
|
12673
|
+
if (info.scan_planning !== scanPlanning)
|
|
12674
|
+
info = { ...info, scan_planning: scanPlanning };
|
|
12452
12675
|
if (info.columns.length)
|
|
12453
12676
|
validateColumnMetadataIpc(info.columns);
|
|
12454
12677
|
const served = servedTableInfo(info);
|
|
@@ -13058,6 +13281,7 @@ function encodeFunctionInfoOnce(info) {
|
|
|
13058
13281
|
return encoded;
|
|
13059
13282
|
}
|
|
13060
13283
|
// src/catalog/interface.ts
|
|
13284
|
+
init_arrow();
|
|
13061
13285
|
var encodeCopyFromFormatInfo = (v) => encodeASD(CopyFromFormatInfoSchema, {
|
|
13062
13286
|
comment: v.comment ?? null,
|
|
13063
13287
|
tags: v.tags ?? {},
|
|
@@ -13109,9 +13333,70 @@ function encodeScanBranch(cols) {
|
|
|
13109
13333
|
format_name: [cols.format_name ?? null],
|
|
13110
13334
|
format_locations: [cols.format_locations ?? null],
|
|
13111
13335
|
format_options: [cols.format_options ?? null],
|
|
13112
|
-
schema_path: [cols.schema_path ?? null]
|
|
13336
|
+
schema_path: [cols.schema_path ?? null],
|
|
13337
|
+
row_count: [cols.row_count ?? null],
|
|
13338
|
+
column_statistics: [cols.column_statistics ?? null]
|
|
13113
13339
|
}), ScanBranchSchema));
|
|
13114
13340
|
}
|
|
13341
|
+
function branchStatistics(branch) {
|
|
13342
|
+
let rowCount = null;
|
|
13343
|
+
if (branch.rowCount != null) {
|
|
13344
|
+
if (typeof branch.rowCount === "number" && !Number.isSafeInteger(branch.rowCount)) {
|
|
13345
|
+
throw new Error(`ScanBranch.rowCount must be an integer, got ${branch.rowCount}`);
|
|
13346
|
+
}
|
|
13347
|
+
rowCount = BigInt(branch.rowCount);
|
|
13348
|
+
if (rowCount < 0n)
|
|
13349
|
+
throw new Error(`ScanBranch.rowCount must be >= 0, got ${rowCount}`);
|
|
13350
|
+
}
|
|
13351
|
+
let columnStatistics = null;
|
|
13352
|
+
const stats = branch.columnStatistics;
|
|
13353
|
+
if (stats instanceof Uint8Array) {
|
|
13354
|
+
columnStatistics = stats;
|
|
13355
|
+
} else if (stats != null) {
|
|
13356
|
+
const names = stats.map((s) => s.columnName);
|
|
13357
|
+
if (new Set(names).size !== names.length) {
|
|
13358
|
+
throw new Error("ScanBranch.columnStatistics names a column more than once");
|
|
13359
|
+
}
|
|
13360
|
+
columnStatistics = serializeColumnStatistics(stats);
|
|
13361
|
+
}
|
|
13362
|
+
return { row_count: rowCount, column_statistics: columnStatistics };
|
|
13363
|
+
}
|
|
13364
|
+
function serializeBranchArguments(branch) {
|
|
13365
|
+
const fields = [];
|
|
13366
|
+
const values = {};
|
|
13367
|
+
const positional = branch.positionalArguments ?? [];
|
|
13368
|
+
positional.forEach((arg, index) => {
|
|
13369
|
+
const name = `arg_${index}`;
|
|
13370
|
+
fields.push(field2(name, arg.type, true));
|
|
13371
|
+
values[name] = [arg.value];
|
|
13372
|
+
});
|
|
13373
|
+
for (const [name, arg] of Object.entries(branch.namedArguments ?? {})) {
|
|
13374
|
+
fields.push(field2(name, arg.type, true));
|
|
13375
|
+
values[name] = [arg.value];
|
|
13376
|
+
}
|
|
13377
|
+
const batchSchema = schema2(fields);
|
|
13378
|
+
return serializeBatch(batchFromColumns(values, batchSchema));
|
|
13379
|
+
}
|
|
13380
|
+
function buildScanBranchesResult(branches, requiredExtensions = []) {
|
|
13381
|
+
const serializedBranches = branches.map((branch) => encodeScanBranch({
|
|
13382
|
+
function_name: branch.functionName,
|
|
13383
|
+
arguments: serializeBranchArguments(branch),
|
|
13384
|
+
branch_filter: branch.branchFilter,
|
|
13385
|
+
writable: branch.writable,
|
|
13386
|
+
source_catalog: branch.sourceCatalog,
|
|
13387
|
+
source_schema_path: branch.sourceSchemaPath,
|
|
13388
|
+
source_table: branch.sourceTable,
|
|
13389
|
+
format_name: branch.formatName,
|
|
13390
|
+
format_locations: branch.formatLocations,
|
|
13391
|
+
format_options: branch.formatOptions,
|
|
13392
|
+
schema_path: branch.schemaPath,
|
|
13393
|
+
...branchStatistics(branch)
|
|
13394
|
+
}));
|
|
13395
|
+
return {
|
|
13396
|
+
branches: serializedBranches,
|
|
13397
|
+
required_extensions: requiredExtensions
|
|
13398
|
+
};
|
|
13399
|
+
}
|
|
13115
13400
|
function isPromise(v) {
|
|
13116
13401
|
return v != null && typeof v.then === "function";
|
|
13117
13402
|
}
|
|
@@ -13228,6 +13513,9 @@ class CatalogInterface {
|
|
|
13228
13513
|
const legacy = this.tableScanFunctionGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData);
|
|
13229
13514
|
return isPromise(legacy) ? legacy.then((r) => singleBranchResult(r)) : singleBranchResult(legacy);
|
|
13230
13515
|
}
|
|
13516
|
+
tableScanBranchesPlan(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData, pushdownFilters) {
|
|
13517
|
+
return this.tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData);
|
|
13518
|
+
}
|
|
13231
13519
|
tableColumnStatisticsGet(attachOpaqueData, schemaPath, name, transactionOpaqueData) {
|
|
13232
13520
|
return null;
|
|
13233
13521
|
}
|
|
@@ -14056,6 +14344,7 @@ function catalogAdminHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
|
14056
14344
|
|
|
14057
14345
|
// src/protocol/handlers/catalog/table.ts
|
|
14058
14346
|
import { MethodNotImplementedError as MethodNotImplementedError4 } from "@query-farm/vgi-rpc";
|
|
14347
|
+
init_arrow();
|
|
14059
14348
|
|
|
14060
14349
|
// src/catalog/unconstrained-columns.ts
|
|
14061
14350
|
init_arrow();
|
|
@@ -14196,7 +14485,17 @@ function catalogTableHandlers(getCatalog, signingKey, attachSecretKey) {
|
|
|
14196
14485
|
});
|
|
14197
14486
|
const catalogTableScanBranchesGet = catalogHandler(keys, async (params) => {
|
|
14198
14487
|
const cat = getCatalog();
|
|
14199
|
-
const
|
|
14488
|
+
const attach = toUint8Array(params.attach_opaque_data);
|
|
14489
|
+
const tx = params.transaction_opaque_data ? toUint8Array(params.transaction_opaque_data) : undefined;
|
|
14490
|
+
const schemaPath = params.schema_path;
|
|
14491
|
+
const name = params.name;
|
|
14492
|
+
const atUnit = params.at_unit;
|
|
14493
|
+
const atValue = params.at_value;
|
|
14494
|
+
const filters = params.pushdown_filters != null ? new ScanPlanningFilters(toUint8Array(params.pushdown_filters), async () => {
|
|
14495
|
+
const info = await cat.tableGet(attach, schemaPath, name, atUnit, atValue, tx);
|
|
14496
|
+
return info && info.columns.length ? deserializeSchema(toUint8Array(info.columns)) : null;
|
|
14497
|
+
}) : null;
|
|
14498
|
+
const branchesResult = await cat.tableScanBranchesPlan(attach, schemaPath, name, atUnit, atValue, tx, filters);
|
|
14200
14499
|
return wrapResult(branchesResult, ScanBranchesResultSchema);
|
|
14201
14500
|
});
|
|
14202
14501
|
const catalogTableCommentSet = catalogHandler(keys, async (params) => {
|
|
@@ -15992,8 +16291,10 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
15992
16291
|
if (options.perAttachItemIds)
|
|
15993
16292
|
this.perAttachItemIds = true;
|
|
15994
16293
|
for (const sch of descriptor.schemas ?? [])
|
|
15995
|
-
for (const tbl of sch.tables ?? [])
|
|
16294
|
+
for (const tbl of sch.tables ?? []) {
|
|
15996
16295
|
validateWritableTable(tbl);
|
|
16296
|
+
validateTableScanPlanning(tbl);
|
|
16297
|
+
}
|
|
15997
16298
|
for (const sch of descriptor.schemas ?? []) {
|
|
15998
16299
|
for (const fn of sch.functions ?? [])
|
|
15999
16300
|
registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
|
|
@@ -16238,7 +16539,8 @@ class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
16238
16539
|
delete_function: t.deleteFunction ? inlineScanFunction(t.deleteFunction, undefined, this._schemaForFunction(t.deleteFunction)) : null,
|
|
16239
16540
|
cardinality_estimate: t.inlinedCardinality ? Number(t.inlinedCardinality.estimate) : null,
|
|
16240
16541
|
cardinality_max: t.inlinedCardinality ? Number(t.inlinedCardinality.max) : null,
|
|
16241
|
-
required_filters: requiredFilters
|
|
16542
|
+
required_filters: requiredFilters,
|
|
16543
|
+
scan_planning: t.scanPlanning ?? SCAN_PLANNING_BIND
|
|
16242
16544
|
};
|
|
16243
16545
|
}));
|
|
16244
16546
|
validateForeignKeyTargets(infos.map((info) => ({ schemaPath: info.schema_path, name: info.name, constraints: info.constraints })));
|
|
@@ -16771,6 +17073,12 @@ function sameSpelling(left, right) {
|
|
|
16771
17073
|
function writeFunctionOf(table, operation) {
|
|
16772
17074
|
return operation === "insert" ? table.insertFunction : operation === "update" ? table.updateFunction : table.deleteFunction;
|
|
16773
17075
|
}
|
|
17076
|
+
function validateTableScanPlanning(table) {
|
|
17077
|
+
validateScanPlanning(table.name, table.scanPlanning, false);
|
|
17078
|
+
if (table.scanPlanning === SCAN_PLANNING_FILTERED && (table.function || !table.columns)) {
|
|
17079
|
+
throw new Error(`Table '${table.name}': scanPlanning 'filtered' requires columns and no function; the catalog's ` + "tableScanBranchesPlan supplies the scan per query");
|
|
17080
|
+
}
|
|
17081
|
+
}
|
|
16774
17082
|
function validateWritableTable(table) {
|
|
16775
17083
|
const modes = validateWriteResultModes(table.writeResultModes ?? {});
|
|
16776
17084
|
for (const operation of Object.keys(modes)) {
|
|
@@ -16911,6 +17219,9 @@ class CompositeCatalogInterface extends CatalogInterface {
|
|
|
16911
17219
|
async tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData) {
|
|
16912
17220
|
return await this._route(attachOpaqueData).tableScanBranchesGet(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData);
|
|
16913
17221
|
}
|
|
17222
|
+
async tableScanBranchesPlan(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData, pushdownFilters) {
|
|
17223
|
+
return await this._route(attachOpaqueData).tableScanBranchesPlan(attachOpaqueData, schemaPath, name, atUnit, atValue, transactionOpaqueData, pushdownFilters);
|
|
17224
|
+
}
|
|
16914
17225
|
async tableColumnStatisticsGet(attachOpaqueData, schemaPath, name, transactionOpaqueData) {
|
|
16915
17226
|
return await this._route(attachOpaqueData).tableColumnStatisticsGet(attachOpaqueData, schemaPath, name, transactionOpaqueData);
|
|
16916
17227
|
}
|
|
@@ -17408,7 +17719,10 @@ export {
|
|
|
17408
17719
|
PARENT_ROW_METADATA_KEY,
|
|
17409
17720
|
ROW_SCALAR_EXPRESSION,
|
|
17410
17721
|
ReadOnlyCatalogInterface,
|
|
17722
|
+
SCAN_PLANNING_BIND,
|
|
17723
|
+
SCAN_PLANNING_FILTERED,
|
|
17411
17724
|
ScanFunctionResultSchema,
|
|
17725
|
+
ScanPlanningFilters,
|
|
17412
17726
|
StatusError2 as StatusError,
|
|
17413
17727
|
TRANSACTION_DDL,
|
|
17414
17728
|
TimeUnit2 as TimeUnit,
|
|
@@ -17426,6 +17740,7 @@ export {
|
|
|
17426
17740
|
buildConstraintChange,
|
|
17427
17741
|
buildConstraintDefinition,
|
|
17428
17742
|
buildMacroOverload,
|
|
17743
|
+
buildScanBranchesResult,
|
|
17429
17744
|
buildStatisticsBatch,
|
|
17430
17745
|
cacheControlMetadata,
|
|
17431
17746
|
canonicalIndex,
|
|
@@ -17481,6 +17796,7 @@ export {
|
|
|
17481
17796
|
encodeSqlExpression,
|
|
17482
17797
|
field2 as field,
|
|
17483
17798
|
filterBatch,
|
|
17799
|
+
filtersMayMatch,
|
|
17484
17800
|
fixedSizeBinary2 as fixedSizeBinary,
|
|
17485
17801
|
fixedSizeList2 as fixedSizeList,
|
|
17486
17802
|
float162 as float16,
|
|
@@ -17564,4 +17880,4 @@ export {
|
|
|
17564
17880
|
validateTableConstraints
|
|
17565
17881
|
};
|
|
17566
17882
|
|
|
17567
|
-
//# debugId=
|
|
17883
|
+
//# debugId=A2EDD9D8BB9FFE7F64756E2164756E21
|