@query-farm/vgi 0.48.0 → 0.48.2
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 +24 -1
- package/dist/arguments/argument-spec.d.ts +17 -11
- package/dist/catalog/descriptors.d.ts +16 -2
- package/dist/catalog/publication.d.ts +7 -7
- package/dist/catalog/read-only.d.ts +4 -5
- package/dist/client/client.d.ts +9 -3
- package/dist/client/errors.d.ts +2 -2
- package/dist/client/types.d.ts +21 -0
- package/dist/client-entry.d.ts +1 -1
- package/dist/client-entry.js +31 -7
- package/dist/client-entry.js.map +20 -20
- package/dist/filter-pushdown/deserialize.d.ts +1 -1
- package/dist/filter-pushdown/types.d.ts +10 -10
- package/dist/functions/registry.d.ts +1 -0
- package/dist/functions/scalar.d.ts +17 -6
- package/dist/functions/table-buffering.d.ts +20 -20
- package/dist/functions/table-in-out.d.ts +4 -4
- package/dist/functions/table.d.ts +7 -7
- package/dist/functions/types.d.ts +51 -47
- package/dist/http/fetch.d.ts +10 -10
- package/dist/index.core.d.ts +2 -2
- package/dist/index.js +201 -116
- package/dist/index.js.map +53 -52
- package/dist/protocol/dispatch.d.ts +3 -3
- package/dist/protocol/handlers/function.d.ts +2 -2
- package/dist/protocol/serializers/cardinality.d.ts +4 -1
- package/dist/protocol/types.d.ts +5 -5
- package/dist/rpc-server.d.ts +6 -6
- package/dist/serve-entry.d.ts +16 -16
- package/dist/serve-entry.js +47 -24
- package/dist/serve-entry.js.map +38 -37
- package/dist/split-token.d.ts +6 -6
- package/dist/types.d.ts +9 -2
- package/dist/util/defined.d.ts +21 -0
- package/dist/worker-cf-entry.js +164 -106
- package/dist/worker-cf-entry.js.map +51 -50
- package/dist/worker.d.ts +2 -2
- package/package.json +6 -4
- package/src/arguments/argument-spec.ts +17 -11
- package/src/arrow/codec/registry.ts +2 -2
- package/src/arrow/impl-arrowjs/build.ts +1 -1
- package/src/arrow/impl-arrowjs/canonical.ts +23 -23
- package/src/arrow/impl-arrowjs/empty.ts +2 -2
- package/src/arrow/impl-arrowjs/ipc.ts +2 -2
- package/src/arrow/impl-arrowjs/iterate.ts +2 -2
- package/src/arrow/impl-arrowjs/project.ts +2 -2
- package/src/arrow/impl-flechette/build.ts +2 -1
- package/src/arrow/impl-flechette/canonical.ts +10 -9
- package/src/arrow/impl-flechette/compat.ts +3 -3
- package/src/arrow/impl-flechette/message-meta.ts +5 -4
- package/src/arrow/impl-flechette/statistics.ts +2 -2
- package/src/attach-ticket.ts +2 -2
- package/src/catalog/column-metadata.ts +1 -1
- package/src/catalog/composite.ts +2 -2
- package/src/catalog/constraints.ts +9 -9
- package/src/catalog/descriptors.ts +15 -1
- package/src/catalog/interface.ts +12 -12
- package/src/catalog/publication.ts +9 -8
- package/src/catalog/read-only.ts +27 -21
- package/src/catalog/sql-grammar.ts +6 -6
- package/src/client/client.ts +52 -15
- package/src/client/errors.ts +1 -1
- package/src/client/types.ts +23 -0
- package/src/client-entry.ts +2 -0
- package/src/codec/asd.ts +3 -3
- package/src/codec/conform.ts +3 -3
- package/src/filter-pushdown/collector.ts +1 -1
- package/src/filter-pushdown/deserialize.ts +13 -10
- package/src/filter-pushdown/evaluate.ts +3 -2
- package/src/filter-pushdown/history.ts +3 -2
- package/src/filter-pushdown/types.ts +10 -10
- package/src/functions/continuation.ts +1 -1
- package/src/functions/projection.ts +1 -1
- package/src/functions/registry.ts +20 -17
- package/src/functions/scalar.ts +33 -11
- package/src/functions/storage-cf-do.ts +2 -2
- package/src/functions/table-buffering.ts +28 -21
- package/src/functions/table-in-out.ts +37 -17
- package/src/functions/table.ts +36 -31
- package/src/functions/types.ts +58 -48
- package/src/generated/vgi-service.ts +5 -3
- package/src/http/fetch.ts +17 -12
- package/src/index.core.ts +3 -1
- package/src/protocol/carried-init-request.ts +1 -1
- package/src/protocol/dispatch.ts +3 -3
- package/src/protocol/handlers/aggregate.ts +8 -7
- package/src/protocol/handlers/catalog/shared.ts +1 -1
- package/src/protocol/handlers/function.ts +18 -5
- package/src/protocol/serializers/cardinality.ts +16 -3
- package/src/protocol/state-serializer.ts +1 -1
- package/src/protocol/types.ts +5 -5
- package/src/rpc-server.ts +13 -12
- package/src/serve-entry.ts +18 -18
- package/src/split-token.ts +10 -9
- package/src/types.ts +9 -2
- package/src/util/defined.ts +30 -0
- package/src/util/parent-rows.ts +2 -2
- package/src/worker.ts +15 -14
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { VgiSchema, VgiDataType } from "../arrow/index.js";
|
|
5
5
|
import type { AttachCatalogInfo } from "./interface.js";
|
|
6
|
+
import type { AttachOptionSpec } from "./attach-option.js";
|
|
6
7
|
import type { VgiFunction } from "../functions/types.js";
|
|
7
8
|
import type { Arguments } from "../arguments/arguments.js";
|
|
8
9
|
import type { ColumnStatistics } from "../util/statistics.js";
|
|
@@ -91,7 +92,7 @@ export interface TableDescriptor {
|
|
|
91
92
|
* table_function_cardinality RPC. Only meaningful for function-backed
|
|
92
93
|
* tables; static-column tables don't have a function to call.
|
|
93
94
|
*/
|
|
94
|
-
inlinedCardinality?: { estimate: bigint; max: bigint };
|
|
95
|
+
inlinedCardinality?: { estimate: number | bigint; max: number | bigint };
|
|
95
96
|
comment?: string;
|
|
96
97
|
tags?: Record<string, string>;
|
|
97
98
|
}
|
|
@@ -178,6 +179,19 @@ export interface CatalogDescriptor {
|
|
|
178
179
|
schemas: SchemaDescriptor[];
|
|
179
180
|
settings?: SettingDescriptor[];
|
|
180
181
|
secretTypes?: SecretTypeDescriptor[];
|
|
182
|
+
/**
|
|
183
|
+
* Options the catalog accepts at `ATTACH` time
|
|
184
|
+
* (`ATTACH 'x' (TYPE vgi, LOCATION '...', region 'eu', api_key '...')`).
|
|
185
|
+
* Advertised in the catalog's discovery record so the DuckDB extension
|
|
186
|
+
* validates and casts them (and redacts `secret` ones), and `required` ones
|
|
187
|
+
* are enforced at attach. Mirrors vgi-python's
|
|
188
|
+
* `ReadOnlyCatalogInterface.attach_option_specs`.
|
|
189
|
+
*
|
|
190
|
+
* The values reach `attach()` as its `options`; to hand them to functions,
|
|
191
|
+
* override `attach()` and carry them in `attach_opaque_data`
|
|
192
|
+
* (examples/attach-options-worker.ts), which every function call receives.
|
|
193
|
+
*/
|
|
194
|
+
attachOptions?: AttachOptionSpec[];
|
|
181
195
|
/**
|
|
182
196
|
* Companion catalogs (lakehouse federation) the client should ATTACH when this
|
|
183
197
|
* VGI catalog attaches. Surfaced via `catalog_attach.attach_catalogs`.
|
package/src/catalog/interface.ts
CHANGED
|
@@ -338,15 +338,15 @@ export function singleBranchResult(
|
|
|
338
338
|
function encodeScanBranch(cols: {
|
|
339
339
|
function_name: string;
|
|
340
340
|
arguments: Uint8Array;
|
|
341
|
-
branch_filter?: string | null;
|
|
342
|
-
writable?: boolean;
|
|
343
|
-
source_catalog?: string | null;
|
|
344
|
-
source_schema_path?: string[] | null;
|
|
345
|
-
source_table?: string | null;
|
|
346
|
-
format_name?: string | null;
|
|
347
|
-
format_locations?: string[] | null;
|
|
348
|
-
format_options?: Uint8Array | null;
|
|
349
|
-
schema_path?: string[] | null;
|
|
341
|
+
branch_filter?: string | null | undefined;
|
|
342
|
+
writable?: boolean | undefined;
|
|
343
|
+
source_catalog?: string | null | undefined;
|
|
344
|
+
source_schema_path?: string[] | null | undefined;
|
|
345
|
+
source_table?: string | null | undefined;
|
|
346
|
+
format_name?: string | null | undefined;
|
|
347
|
+
format_locations?: string[] | null | undefined;
|
|
348
|
+
format_options?: Uint8Array | null | undefined;
|
|
349
|
+
schema_path?: string[] | null | undefined;
|
|
350
350
|
}): Uint8Array {
|
|
351
351
|
return serializeBatch(
|
|
352
352
|
batchFromColumns(
|
|
@@ -613,7 +613,7 @@ export abstract class CatalogInterface {
|
|
|
613
613
|
*/
|
|
614
614
|
catalogNameForAttach(_attachOpaqueData: Uint8Array): string | null {
|
|
615
615
|
const names = this.catalogs();
|
|
616
|
-
return names.length === 1 ? names[0] : null;
|
|
616
|
+
return names.length === 1 ? names[0]! : null;
|
|
617
617
|
}
|
|
618
618
|
|
|
619
619
|
// Required overrides
|
|
@@ -794,8 +794,8 @@ export abstract class CatalogInterface {
|
|
|
794
794
|
const change = decodeConstraintChange(bytes);
|
|
795
795
|
if (change.operation === "ADD" && change.definition != null) {
|
|
796
796
|
const def = decodeConstraintDefinition(change.definition);
|
|
797
|
-
if (def.kind === "NOT_NULL" && def.column_paths.length === 1 && def.column_paths[0]
|
|
798
|
-
await this.tableNotNullSet(attach, schemaPath, target.name, [...def.column_paths[0]], false, tx);
|
|
797
|
+
if (def.kind === "NOT_NULL" && def.column_paths.length === 1 && def.column_paths[0]!.length === 1) {
|
|
798
|
+
await this.tableNotNullSet(attach, schemaPath, target.name, [...def.column_paths[0]!], false, tx);
|
|
799
799
|
continue;
|
|
800
800
|
}
|
|
801
801
|
} else if (change.operation === "DROP" && change.ref != null) {
|
|
@@ -21,7 +21,7 @@ export interface SnapshotIdentity {
|
|
|
21
21
|
export interface SnapshotRequest {
|
|
22
22
|
catalog: CatalogInterface;
|
|
23
23
|
attachOpaqueData: AttachOpaqueData;
|
|
24
|
-
callContext?: CallContext;
|
|
24
|
+
callContext?: CallContext | undefined;
|
|
25
25
|
catalogVersion: number;
|
|
26
26
|
}
|
|
27
27
|
export interface CatalogPublicationManifest {
|
|
@@ -39,9 +39,9 @@ export interface CatalogPublicationManifest {
|
|
|
39
39
|
rawSize: number;
|
|
40
40
|
storedSize: number;
|
|
41
41
|
url: string;
|
|
42
|
-
objectId?: string;
|
|
43
|
-
expiresAt?: number;
|
|
44
|
-
retainUntil?: number;
|
|
42
|
+
objectId?: string | undefined;
|
|
43
|
+
expiresAt?: number | undefined;
|
|
44
|
+
retainUntil?: number | undefined;
|
|
45
45
|
stable: boolean;
|
|
46
46
|
validated: true;
|
|
47
47
|
}
|
|
@@ -199,13 +199,14 @@ export class CatalogSnapshotManager {
|
|
|
199
199
|
validateCatalogPublicationEnvelope(bytes);
|
|
200
200
|
},
|
|
201
201
|
});
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
const resultField = resolved.schema.fields.length === 1 ? resolved.schema.fields[0] : undefined;
|
|
203
|
+
if (resolved.numRows !== 1 || !resultField || resultField.name !== "result"
|
|
204
|
+
|| typeSignature(resultField.type) !== typeSignature(binary()) || resultField.nullable) throw new Error("invalid published RPC envelope");
|
|
204
205
|
const bytes = resolved.getChild("result")?.get(0);
|
|
205
206
|
if (!(bytes instanceof Uint8Array)) throw new Error("published catalog has no result bytes");
|
|
206
207
|
const decoded = decodeASDCollection<CatalogContentsResponse>(CatalogContentsResultSchema, bytes);
|
|
207
|
-
|
|
208
|
-
|
|
208
|
+
const response = decoded.length === 1 ? decoded[0] : undefined;
|
|
209
|
+
if (!response) throw new Error("published catalog must contain exactly one response row");
|
|
209
210
|
if (response.not_modified || Number(response.catalog_version) !== identity.catalogVersion || response.etag !== m.etag) throw new Error("published catalog version or ETag mismatch");
|
|
210
211
|
decodeCatalogStreams(response);
|
|
211
212
|
if (expected) for (const kind of CATALOG_STREAM_KINDS) {
|
package/src/catalog/read-only.ts
CHANGED
|
@@ -28,7 +28,7 @@ import type { FunctionRegistry } from "../functions/registry.js";
|
|
|
28
28
|
import { argumentSpecsToSchema } from "../arguments/argument-spec.js";
|
|
29
29
|
import { serializeSchema, serializeBatch, emptyBatch, batchFromColumns } from "../util/arrow/index.js";
|
|
30
30
|
import { resolveMetadata } from "../metadata/resolve.js";
|
|
31
|
-
import { type AttachOptionSpec, validateRequiredAttachOptions } from "./attach-option.js";
|
|
31
|
+
import { type AttachOptionSpec, serializeAttachOptionSpecs, validateRequiredAttachOptions } from "./attach-option.js";
|
|
32
32
|
import { FunctionStability, NullHandling, OrderPreservation, DEFAULT_MAX_WORKERS } from "../types.js";
|
|
33
33
|
import { Arguments } from "../arguments/arguments.js";
|
|
34
34
|
import { normalizeSchemaPath, schemaPathDisplay, schemaPathsEqual } from "../schema-path.js";
|
|
@@ -123,7 +123,14 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
123
123
|
for (const tbl of sch.tables ?? []) {
|
|
124
124
|
for (const key of ["function", "insertFunction", "updateFunction", "deleteFunction"] as const) {
|
|
125
125
|
const fn = (tbl as any)[key];
|
|
126
|
-
if (fn)
|
|
126
|
+
if (!fn) continue;
|
|
127
|
+
registry.registerInSchema(fn, schemaDescriptorPath(sch), descriptor.name);
|
|
128
|
+
// A table's scan/write functions need not also be listed in the
|
|
129
|
+
// schema's `functions`. Index them by name too, so a bind that
|
|
130
|
+
// resolves by name (a scan whose ScanFunctionResult carries no
|
|
131
|
+
// schema path, because no schema lists the function) finds them.
|
|
132
|
+
// Mirrors vgi-python's Worker._build_registry auto-registration.
|
|
133
|
+
registry.register(fn);
|
|
127
134
|
}
|
|
128
135
|
}
|
|
129
136
|
}
|
|
@@ -159,26 +166,24 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
159
166
|
/**
|
|
160
167
|
* Attach-time options this catalog declares, for the named catalog.
|
|
161
168
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* several catalogs with different option sets.
|
|
169
|
+
* The descriptor's `attachOptions` (empty when it declares none). A
|
|
170
|
+
* subclass serving several catalogs with different option sets overrides
|
|
171
|
+
* this; `catalogsInfo()` advertises whatever it returns and `attach()`
|
|
172
|
+
* enforces the `required` ones, so the two never disagree.
|
|
167
173
|
*/
|
|
168
174
|
attachOptionSpecs(_name: string): AttachOptionSpec[] {
|
|
169
|
-
return [];
|
|
175
|
+
return this._descriptor.attachOptions ?? [];
|
|
170
176
|
}
|
|
171
177
|
|
|
172
|
-
// Advertise the catalog's discovery record
|
|
173
|
-
//
|
|
174
|
-
// `
|
|
175
|
-
// (DuckDB's `duckdb_databases()`).
|
|
178
|
+
// Advertise the catalog's discovery record: its attach option specs and the
|
|
179
|
+
// optional `source_url`, which flows through `catalog_catalogs` (DuckDB's
|
|
180
|
+
// `duckdb_databases()`). The declarative path carries no version metadata.
|
|
176
181
|
override catalogsInfo(): CatalogInfo[] {
|
|
177
182
|
return [{
|
|
178
183
|
name: this._descriptor.name,
|
|
179
184
|
implementation_version: null,
|
|
180
185
|
data_version_spec: null,
|
|
181
|
-
attach_option_specs:
|
|
186
|
+
attach_option_specs: serializeAttachOptionSpecs(this.attachOptionSpecs(this._descriptor.name)),
|
|
182
187
|
releases: [],
|
|
183
188
|
source_url: this._descriptor.sourceUrl ?? null,
|
|
184
189
|
}];
|
|
@@ -450,10 +455,11 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
450
455
|
const part = path[i];
|
|
451
456
|
if (typeof part !== "string" || !part || part.includes("\0")) throw new Error("invalid requiredFilters component");
|
|
452
457
|
const matches = fields.filter((f) => f.name === part);
|
|
453
|
-
|
|
458
|
+
const match = matches.length === 1 ? matches[0] : undefined;
|
|
459
|
+
if (!match) throw new Error(`unknown or ambiguous requiredFilters component: ${part}`);
|
|
454
460
|
if (i + 1 < path.length) {
|
|
455
|
-
if (!isStruct(
|
|
456
|
-
fields = (
|
|
461
|
+
if (!isStruct(match.type)) throw new Error(`non-struct requiredFilters parent: ${part}`);
|
|
462
|
+
fields = (match.type as VgiDataType & { children: readonly VgiField[] }).children;
|
|
457
463
|
}
|
|
458
464
|
}
|
|
459
465
|
}
|
|
@@ -610,13 +616,13 @@ export class ReadOnlyCatalogInterface extends CatalogInterface {
|
|
|
610
616
|
}
|
|
611
617
|
let argumentIndex = 0;
|
|
612
618
|
for (const defaultField of defaults.schema.fields) {
|
|
613
|
-
while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex]
|
|
619
|
+
while (argumentIndex < argSchema.fields.length && argSchema.fields[argumentIndex]!.name !== defaultField.name) {
|
|
614
620
|
argumentIndex++;
|
|
615
621
|
}
|
|
616
622
|
if (argumentIndex === argSchema.fields.length) {
|
|
617
623
|
throw new Error(`parameterDefaultValues field '${defaultField.name}' is not in argument signature order`);
|
|
618
624
|
}
|
|
619
|
-
const argumentField = argSchema.fields[argumentIndex]
|
|
625
|
+
const argumentField = argSchema.fields[argumentIndex]!;
|
|
620
626
|
if (typeSignature(argumentField.type) !== typeSignature(defaultField.type)) {
|
|
621
627
|
throw new Error(
|
|
622
628
|
`parameterDefaultValues field '${defaultField.name}' has type ${typeSignature(defaultField.type)}, ` +
|
|
@@ -1054,7 +1060,7 @@ function applyDefaults(schema: VgiSchema, defaults: Record<string, DefaultValue>
|
|
|
1054
1060
|
for (const [colName, value] of Object.entries(defaults)) {
|
|
1055
1061
|
const idx = result.fields.findIndex((f) => f.name === colName);
|
|
1056
1062
|
if (idx < 0) continue;
|
|
1057
|
-
const f = result.fields[idx]
|
|
1063
|
+
const f = result.fields[idx]!;
|
|
1058
1064
|
const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
|
|
1059
1065
|
const sql = defaultToSql(value);
|
|
1060
1066
|
// Canonical where it is exact (see canonicalDefault); the legacy "default"
|
|
@@ -1077,7 +1083,7 @@ function applyGeneratedColumns(schema: VgiSchema, generated: Record<string, stri
|
|
|
1077
1083
|
for (const [colName, expression] of Object.entries(generated)) {
|
|
1078
1084
|
const idx = result.fields.findIndex((f) => f.name === colName);
|
|
1079
1085
|
if (idx < 0) throw new Error(`Table '${table}': generatedColumns names unknown column ${colName}`);
|
|
1080
|
-
const f = result.fields[idx]
|
|
1086
|
+
const f = result.fields[idx]!;
|
|
1081
1087
|
const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
|
|
1082
1088
|
if (existingMeta.has(GENERATED_EXPRESSION_KEY) || existingMeta.has("generated_expression"))
|
|
1083
1089
|
throw new Error(`Table '${table}': generatedColumns for ${colName} conflicts with existing expression metadata`);
|
|
@@ -1100,7 +1106,7 @@ function applyColumnComments(schema: VgiSchema, comments: Record<string, string>
|
|
|
1100
1106
|
for (const [colName, comment] of Object.entries(comments)) {
|
|
1101
1107
|
const idx = result.fields.findIndex((f) => f.name === colName);
|
|
1102
1108
|
if (idx < 0) throw new Error(`Table '${table}': columnComments names unknown column ${colName}`);
|
|
1103
|
-
const f = result.fields[idx]
|
|
1109
|
+
const f = result.fields[idx]!;
|
|
1104
1110
|
const existingMeta = f.metadata ? new Map(f.metadata) : new Map<string, string>();
|
|
1105
1111
|
existingMeta.set("comment", comment);
|
|
1106
1112
|
const newField = field(f.name, f.type, f.nullable, existingMeta);
|
|
@@ -45,7 +45,7 @@ function tokenize(sql: string): Token[] {
|
|
|
45
45
|
const out: Token[] = [];
|
|
46
46
|
let i = 0;
|
|
47
47
|
while (i < sql.length) {
|
|
48
|
-
const c = sql[i]
|
|
48
|
+
const c = sql[i]!;
|
|
49
49
|
if (/\s/.test(c)) { i++; continue; }
|
|
50
50
|
if (sql.startsWith("--", i)) {
|
|
51
51
|
while (i < sql.length && sql[i] !== "\n") i++;
|
|
@@ -126,8 +126,8 @@ class Parser {
|
|
|
126
126
|
private pos = 0;
|
|
127
127
|
constructor(private readonly tokens: Token[]) {}
|
|
128
128
|
|
|
129
|
-
private peek(offset = 0): Token { return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)]
|
|
130
|
-
private next(): Token { return this.tokens[this.pos++]
|
|
129
|
+
private peek(offset = 0): Token { return this.tokens[Math.min(this.pos + offset, this.tokens.length - 1)]!; }
|
|
130
|
+
private next(): Token { return this.tokens[this.pos++]!; }
|
|
131
131
|
private isOp(v: string, offset = 0): boolean {
|
|
132
132
|
const t = this.peek(offset);
|
|
133
133
|
return t.t === "op" && t.v === v;
|
|
@@ -375,7 +375,7 @@ class Parser {
|
|
|
375
375
|
this.expectOp(")");
|
|
376
376
|
if (this.isWord("filter") || this.isWord("over")) fail("aggregate and window functions are unsupported");
|
|
377
377
|
if (names.length === 1 && !t.quoted && word === "coalesce") return { kind: "operator", op: "COALESCE", children };
|
|
378
|
-
return { kind: "function", name: names[names.length - 1]
|
|
378
|
+
return { kind: "function", name: names[names.length - 1]!, qualified: names.length > 1, children };
|
|
379
379
|
}
|
|
380
380
|
if (this.peek().t === "str") fail("typed literals are unsupported");
|
|
381
381
|
return { kind: "column", names };
|
|
@@ -417,7 +417,7 @@ export function validateColumnExpressionSql(
|
|
|
417
417
|
return;
|
|
418
418
|
case "column":
|
|
419
419
|
if (!usingColumns || node.names.length !== 1) fail("column references are unsupported in this scope");
|
|
420
|
-
columns.push(node.names[0]);
|
|
420
|
+
columns.push(node.names[0]!);
|
|
421
421
|
return;
|
|
422
422
|
case "cast":
|
|
423
423
|
if (node.qualified) fail("qualified scalar cast types are unsupported");
|
|
@@ -471,6 +471,6 @@ export function validateNumericCheckSql(sql: string, resolveColumn: (name: strin
|
|
|
471
471
|
if (operand.kind !== "column") fail("native CHECK read supports only numeric column/constant comparisons");
|
|
472
472
|
const column = operand as Extract<ScalarNode, { kind: "column" }>;
|
|
473
473
|
if (column.names.length !== 1) fail("CHECK requires unqualified column references");
|
|
474
|
-
resolveColumn(column.names[0]);
|
|
474
|
+
resolveColumn(column.names[0]!);
|
|
475
475
|
}
|
|
476
476
|
}
|
package/src/client/client.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// VgiClient — high-level client for calling VGI worker functions and catalog API.
|
|
3
3
|
// Works with any RpcClient (subprocess or HTTP transport).
|
|
4
4
|
|
|
5
|
-
import { type VgiSchema, schema as schema_, type VgiField, field, type VgiBatch, type VgiDataType, utf8, binary, list } from "../arrow/index.js";
|
|
5
|
+
import { type VgiSchema, schema as schema_, type VgiField, field, type VgiBatch, type VgiDataType, utf8, binary, list, isInt } from "../arrow/index.js";
|
|
6
6
|
// `import type`, not `import { type … }`: the latter keeps the statement and
|
|
7
7
|
// emits `import {} from "@query-farm/vgi-rpc"`, a side-effect import of the
|
|
8
8
|
// package root — which re-exports the whole framework, server included, into
|
|
@@ -66,9 +66,37 @@ import { decodeCatalogContentsResponse } from "../generated/vgi-protocol-types.j
|
|
|
66
66
|
import { deserializeInfoList, deserializeTags, toAsyncIterator } from "./helpers.js";
|
|
67
67
|
|
|
68
68
|
export { VgiClientError };
|
|
69
|
+
|
|
70
|
+
/** Names of the top-level 64-bit integer (int64/uint64) fields of `s`. */
|
|
71
|
+
function int64ColumnNames(s: VgiSchema | null | undefined): string[] {
|
|
72
|
+
if (!s) return [];
|
|
73
|
+
return s.fields
|
|
74
|
+
.filter((f) => isInt(f.type) && (f.type as { bitWidth?: number }).bitWidth === 64)
|
|
75
|
+
.map((f) => f.name);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const MIN_SAFE_BIGINT = BigInt(Number.MIN_SAFE_INTEGER);
|
|
79
|
+
const MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
80
|
+
|
|
81
|
+
/** Normalise the int64 columns of `rows` in place to `mode`. Lossless: the
|
|
82
|
+
* RPC layer only ever narrows a bigint to number when it is a safe integer. */
|
|
83
|
+
function applyInt64Mode(rows: Record<string, any>[], columns: string[], mode: Int64Mode): void {
|
|
84
|
+
for (const row of rows) {
|
|
85
|
+
for (const name of columns) {
|
|
86
|
+
const v = row[name];
|
|
87
|
+
if (mode === "bigint") {
|
|
88
|
+
if (typeof v === "number" && Number.isInteger(v)) row[name] = BigInt(v);
|
|
89
|
+
} else if (typeof v === "bigint" && v >= MIN_SAFE_BIGINT && v <= MAX_SAFE_BIGINT) {
|
|
90
|
+
row[name] = Number(v);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
69
95
|
import type {
|
|
70
96
|
VgiClientOptions,
|
|
71
97
|
TableFunctionOptions,
|
|
98
|
+
TableFunctionRowsOptions,
|
|
99
|
+
Int64Mode,
|
|
72
100
|
ScalarFunctionOptions,
|
|
73
101
|
TableInOutFunctionOptions,
|
|
74
102
|
OnCreateConflict,
|
|
@@ -262,13 +290,13 @@ export class VgiClient {
|
|
|
262
290
|
bindRequest: BindRequest,
|
|
263
291
|
bindResponse: BindResponse,
|
|
264
292
|
opts?: {
|
|
265
|
-
projectionIds?: number[] | null;
|
|
266
|
-
pushdownFilters?: VgiBatch | null;
|
|
267
|
-
phase?: TableInOutPhase | null;
|
|
268
|
-
executionId?: Uint8Array | null;
|
|
269
|
-
orderBy?: OrderByPushdown | null;
|
|
270
|
-
tablesample?: TablesamplePushdown | null;
|
|
271
|
-
joinKeys?: VgiBatch[] | null;
|
|
293
|
+
projectionIds?: number[] | null | undefined;
|
|
294
|
+
pushdownFilters?: VgiBatch | null | undefined;
|
|
295
|
+
phase?: TableInOutPhase | null | undefined;
|
|
296
|
+
executionId?: Uint8Array | null | undefined;
|
|
297
|
+
orderBy?: OrderByPushdown | null | undefined;
|
|
298
|
+
tablesample?: TablesamplePushdown | null | undefined;
|
|
299
|
+
joinKeys?: VgiBatch[] | null | undefined;
|
|
272
300
|
},
|
|
273
301
|
): Promise<{ session: StreamSession; initResponse: GlobalInitResponse }> {
|
|
274
302
|
const ob = opts?.orderBy ?? null;
|
|
@@ -617,9 +645,15 @@ export class VgiClient {
|
|
|
617
645
|
// Row convenience for table function
|
|
618
646
|
// ==========================================================================
|
|
619
647
|
|
|
620
|
-
/**
|
|
648
|
+
/**
|
|
649
|
+
* Call a table function, yielding output as row objects.
|
|
650
|
+
*
|
|
651
|
+
* int64/uint64 columns follow `opts.int64` (see {@link Int64Mode}); pass
|
|
652
|
+
* `int64: "bigint"` to get a `bigint` for every value instead of a
|
|
653
|
+
* magnitude-dependent mix of `number` and `bigint`.
|
|
654
|
+
*/
|
|
621
655
|
async *tableFunctionRows(
|
|
622
|
-
opts:
|
|
656
|
+
opts: TableFunctionRowsOptions,
|
|
623
657
|
): AsyncGenerator<Record<string, any>[]> {
|
|
624
658
|
const args = opts.arguments ?? new Arguments();
|
|
625
659
|
const { request: bindReq, response: bindResp } = await this._doBind(
|
|
@@ -640,9 +674,12 @@ export class VgiClient {
|
|
|
640
674
|
tablesample: opts.tablesample,
|
|
641
675
|
joinKeys: opts.joinKeys,
|
|
642
676
|
});
|
|
677
|
+
const int64Columns = opts.int64 === undefined ? [] : int64ColumnNames(bindResp.output_schema);
|
|
643
678
|
try {
|
|
644
679
|
for await (const rows of session) {
|
|
645
|
-
if (rows.length
|
|
680
|
+
if (rows.length === 0) continue;
|
|
681
|
+
if (int64Columns.length > 0) applyInt64Mode(rows, int64Columns, opts.int64!);
|
|
682
|
+
yield rows;
|
|
646
683
|
}
|
|
647
684
|
} finally {
|
|
648
685
|
session.close();
|
|
@@ -1056,7 +1093,7 @@ export class VgiClient {
|
|
|
1056
1093
|
if (!result) return null;
|
|
1057
1094
|
const inner = unwrapResult(result);
|
|
1058
1095
|
const items = deserializeInfoList(inner.items, decodeSchemaInfo);
|
|
1059
|
-
return items
|
|
1096
|
+
return items[0] ?? null;
|
|
1060
1097
|
}
|
|
1061
1098
|
|
|
1062
1099
|
/** Create a new schema. */
|
|
@@ -1182,7 +1219,7 @@ export class VgiClient {
|
|
|
1182
1219
|
if (!result) return null;
|
|
1183
1220
|
const inner = unwrapResult(result);
|
|
1184
1221
|
const items = deserializeInfoList(inner.items, decodeTableInfo);
|
|
1185
|
-
return items
|
|
1222
|
+
return items[0] ?? null;
|
|
1186
1223
|
}
|
|
1187
1224
|
|
|
1188
1225
|
/** Create a new table. */
|
|
@@ -1502,7 +1539,7 @@ export class VgiClient {
|
|
|
1502
1539
|
if (!result) return null;
|
|
1503
1540
|
const inner = unwrapResult(result);
|
|
1504
1541
|
const items = deserializeInfoList(inner.items, decodeViewInfo);
|
|
1505
|
-
return items
|
|
1542
|
+
return items[0] ?? null;
|
|
1506
1543
|
}
|
|
1507
1544
|
|
|
1508
1545
|
/** Create a new view. */
|
|
@@ -1623,7 +1660,7 @@ export class VgiClient {
|
|
|
1623
1660
|
if (!result) return null;
|
|
1624
1661
|
const inner = unwrapResult(result);
|
|
1625
1662
|
const items = deserializeInfoList(inner.items, decodeMacroInfo);
|
|
1626
|
-
return items
|
|
1663
|
+
return items[0] ?? null;
|
|
1627
1664
|
}
|
|
1628
1665
|
|
|
1629
1666
|
/** List macros in a schema, filtered by type. */
|
package/src/client/errors.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class VgiClientError extends Error {
|
|
|
22
22
|
|
|
23
23
|
constructor(
|
|
24
24
|
message: string,
|
|
25
|
-
options?: { remoteTraceback?: string; errorType?: string; cause?: unknown },
|
|
25
|
+
options?: { remoteTraceback?: string | undefined; errorType?: string | undefined; cause?: unknown },
|
|
26
26
|
) {
|
|
27
27
|
super(message, options?.cause != null ? { cause: options.cause } : undefined);
|
|
28
28
|
this.name = "VgiClientError";
|
package/src/client/types.ts
CHANGED
|
@@ -98,6 +98,29 @@ export interface TableFunctionOptions {
|
|
|
98
98
|
onBind?: BindResultCallback;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* How {@link VgiClient.tableFunctionRows} surfaces int64/uint64 column
|
|
103
|
+
* values. Same vocabulary as `@query-farm/vgi-rpc`'s client `int64` option.
|
|
104
|
+
*
|
|
105
|
+
* - `"number-if-safe"`: values within `Number.MAX_SAFE_INTEGER` become
|
|
106
|
+
* `number`, larger ones stay `bigint` (one column can hold both).
|
|
107
|
+
* - `"bigint"`: every value stays a `bigint` — one JS type per column.
|
|
108
|
+
*/
|
|
109
|
+
export type Int64Mode = "number-if-safe" | "bigint";
|
|
110
|
+
|
|
111
|
+
/** Options for {@link VgiClient.tableFunctionRows}. */
|
|
112
|
+
export interface TableFunctionRowsOptions extends TableFunctionOptions {
|
|
113
|
+
/**
|
|
114
|
+
* Surfacing of top-level int64/uint64 output columns (see {@link Int64Mode}).
|
|
115
|
+
* When omitted, rows are returned as the underlying `RpcClient` produced
|
|
116
|
+
* them — `"number-if-safe"` unless that client was created with
|
|
117
|
+
* `int64: "bigint"` (`@query-farm/vgi-rpc` >= 0.29.6). Setting it here
|
|
118
|
+
* overrides the client either way. The omitted-default may become
|
|
119
|
+
* `"bigint"` in a future minor release; pass it explicitly to pin it.
|
|
120
|
+
*/
|
|
121
|
+
int64?: Int64Mode;
|
|
122
|
+
}
|
|
123
|
+
|
|
101
124
|
/** Options for calling a scalar function. */
|
|
102
125
|
export interface ScalarFunctionOptions {
|
|
103
126
|
/** Name of the function to call. */
|
package/src/client-entry.ts
CHANGED
package/src/codec/asd.ts
CHANGED
|
@@ -111,7 +111,7 @@ function sortMapsForType(type: VgiDataType, value: any): any {
|
|
|
111
111
|
if (value == null || !typeHasMap(type)) return value;
|
|
112
112
|
if (isMap(type)) {
|
|
113
113
|
const entries = (type as any).children[0].type as VgiDataType;
|
|
114
|
-
const valueType = ((entries as any).children as VgiField[])[1]
|
|
114
|
+
const valueType = ((entries as any).children as VgiField[])[1]!.type;
|
|
115
115
|
return mapPairs(value)
|
|
116
116
|
.map(([k, v]): [unknown, unknown] => [k, sortMapsForType(valueType, v)])
|
|
117
117
|
.sort((x, y) => compareKeys(x[0], y[0]));
|
|
@@ -186,7 +186,7 @@ function normalizeValue(raw: any, type: VgiDataType): any {
|
|
|
186
186
|
// and struct children: a map<utf8, int64> yields numbers (bigint beyond
|
|
187
187
|
// the safe range), not strings, and a null value stays null.
|
|
188
188
|
const entries = (type as any).children[0].type as VgiDataType;
|
|
189
|
-
const valueType = ((entries as any).children as VgiField[])[1]
|
|
189
|
+
const valueType = ((entries as any).children as VgiField[])[1]!.type;
|
|
190
190
|
const out: Record<string, any> = {};
|
|
191
191
|
const put = (k: unknown, v: unknown): void => {
|
|
192
192
|
Object.defineProperty(out, String(k), {
|
|
@@ -267,7 +267,7 @@ export function decodeASDCollection<T>(schema: VgiSchema, bytes: Uint8Array | nu
|
|
|
267
267
|
const batches = deserializeBatches(bytes);
|
|
268
268
|
const validateSchema = (actualSchema: VgiSchema) => {
|
|
269
269
|
if (actualSchema.fields.length !== schema.fields.length || schema.fields.some((field, i) => {
|
|
270
|
-
const actual = actualSchema.fields[i]
|
|
270
|
+
const actual = actualSchema.fields[i]!;
|
|
271
271
|
return actual.name !== field.name || actual.nullable !== field.nullable || typeSignature(actual.type) !== typeSignature(field.type);
|
|
272
272
|
})) throw new Error("catalog collection has an incompatible metadata schema");
|
|
273
273
|
};
|
package/src/codec/conform.ts
CHANGED
|
@@ -61,8 +61,8 @@ function children(type: VgiDataType): VgiField[] {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
function mapValueType(type: VgiDataType): VgiDataType {
|
|
64
|
-
const entries = children(type)[0]
|
|
65
|
-
return children(entries)[1]
|
|
64
|
+
const entries = children(type)[0]!.type;
|
|
65
|
+
return children(entries)[1]!.type;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
function mapPairs(raw: any): Array<[unknown, unknown]> {
|
|
@@ -114,7 +114,7 @@ function conformValue(type: VgiDataType, value: any, nullable: boolean, name: st
|
|
|
114
114
|
if (!hasContainer(type)) return value;
|
|
115
115
|
|
|
116
116
|
if (isList(type)) {
|
|
117
|
-
const itemType = children(type)[0]
|
|
117
|
+
const itemType = children(type)[0]!.type;
|
|
118
118
|
const itemsNullable = OPTIONAL_ITEM_FIELDS.has(name);
|
|
119
119
|
const items = Array.isArray(value) ? value : Array.from(value as Iterable<unknown>);
|
|
120
120
|
let changed = !Array.isArray(value);
|
|
@@ -117,7 +117,7 @@ export class FilteringOutputCollector {
|
|
|
117
117
|
const mask = this.filters.evaluate(batch as any);
|
|
118
118
|
const parents = decodeParentRows(encoded);
|
|
119
119
|
const kept: number[] = [];
|
|
120
|
-
for (let i = 0; i < parents.length; i++) if (mask[i]) kept.push(parents[i]);
|
|
120
|
+
for (let i = 0; i < parents.length; i++) if (mask[i]) kept.push(parents[i]!);
|
|
121
121
|
const md = new Map(metadata);
|
|
122
122
|
if (kept.length > 0) md.set(PARENT_ROW_METADATA_KEY, encodeParentRows(kept));
|
|
123
123
|
else md.delete(PARENT_ROW_METADATA_KEY);
|
|
@@ -71,7 +71,7 @@ export class FilterV2Error extends Error {
|
|
|
71
71
|
export interface DeserializeFilterOptions extends FilterCapabilities {
|
|
72
72
|
/** The authoritative, unprojected bind output schema. */
|
|
73
73
|
outputSchema: VgiSchema;
|
|
74
|
-
joinKeyBatches?: VgiBatch[];
|
|
74
|
+
joinKeyBatches?: VgiBatch[] | undefined;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
function utf8Length(value: string): number {
|
|
@@ -180,7 +180,7 @@ class StrictJsonParser {
|
|
|
180
180
|
const start = this.offset++;
|
|
181
181
|
let escaped = false;
|
|
182
182
|
while (this.offset < this.text.length) {
|
|
183
|
-
const ch = this.text[this.offset++]
|
|
183
|
+
const ch = this.text[this.offset++]!;
|
|
184
184
|
if (!escaped && ch === '"') {
|
|
185
185
|
try {
|
|
186
186
|
return JSON.parse(this.text.slice(start, this.offset));
|
|
@@ -303,9 +303,10 @@ class FilterParser {
|
|
|
303
303
|
const names = batch.schema.fields.map((field) => field.name);
|
|
304
304
|
if (new Set(names).size !== names.length) throw new FilterV2Error("filter payload names must be unique");
|
|
305
305
|
for (let i = 1; i < names.length; i++) {
|
|
306
|
-
|
|
307
|
-
if (
|
|
308
|
-
|
|
306
|
+
const name = names[i]!;
|
|
307
|
+
if (!PAYLOAD_NAME.test(name)) throw new FilterV2Error(`noncanonical payload name ${name}`);
|
|
308
|
+
if (name.startsWith("type_") && this.valueAt(i) !== null) {
|
|
309
|
+
throw new FilterV2Error(`${name} must contain NULL`);
|
|
309
310
|
}
|
|
310
311
|
}
|
|
311
312
|
this.context = parseContext(batch.schema);
|
|
@@ -319,8 +320,9 @@ class FilterParser {
|
|
|
319
320
|
|
|
320
321
|
private valueAt(index: number): unknown {
|
|
321
322
|
const column = this.batch.getChildAt(index);
|
|
322
|
-
|
|
323
|
-
|
|
323
|
+
const field = this.batch.schema.fields[index];
|
|
324
|
+
if (!column || !field) throw new FilterV2Error(`missing payload column ${index}`);
|
|
325
|
+
return readCanonicalValue(field.type, column, 0);
|
|
324
326
|
}
|
|
325
327
|
|
|
326
328
|
private validateContextCapability(): void {
|
|
@@ -363,7 +365,7 @@ class FilterParser {
|
|
|
363
365
|
const entries = this.header("delta", "updates");
|
|
364
366
|
const live = new Map(prior.predicates.map((predicate) => [predicate.id, predicate]));
|
|
365
367
|
const revisions = new Map(prior.revisions);
|
|
366
|
-
const parsed: Array<{ id: string; revision: number; predicate?: FilterPredicate }> = [];
|
|
368
|
+
const parsed: Array<{ id: string; revision: number; predicate?: FilterPredicate | undefined }> = [];
|
|
367
369
|
const seen = new Set<string>();
|
|
368
370
|
for (let index = 0; index < entries.length; index++) {
|
|
369
371
|
const where = `updates[${index}]`;
|
|
@@ -436,8 +438,9 @@ class FilterParser {
|
|
|
436
438
|
const ref = expectUint(rawRef, `${prefix}_ref`);
|
|
437
439
|
const name = `${prefix}_${ref}`;
|
|
438
440
|
const indexes = this.batch.schema.fields.flatMap((field, index) => field.name === name ? [index] : []);
|
|
439
|
-
|
|
440
|
-
|
|
441
|
+
const index = indexes.length === 1 ? indexes[0] : undefined;
|
|
442
|
+
if (index === undefined) throw new FilterV2Error(`missing or duplicate payload ${name}`);
|
|
443
|
+
return { ref, field: this.batch.schema.fields[index]!, value: this.valueAt(index) };
|
|
441
444
|
}
|
|
442
445
|
|
|
443
446
|
private identity(raw: unknown, where: string): FunctionIdentity {
|
|
@@ -45,7 +45,8 @@ function resolveColumn(batch: VgiBatch, columnName: string): { type: VgiDataType
|
|
|
45
45
|
throw new FilterV2Error(`filter column ${columnName} is unavailable in emitted batch`);
|
|
46
46
|
}
|
|
47
47
|
const column = batch.getChildAt(index);
|
|
48
|
-
|
|
48
|
+
const field = batch.schema.fields[index];
|
|
49
|
+
resolved = column && field ? { type: field.type, column } : null;
|
|
49
50
|
byName.set(columnName, resolved);
|
|
50
51
|
}
|
|
51
52
|
return resolved;
|
|
@@ -510,7 +511,7 @@ export class PushdownFilters {
|
|
|
510
511
|
if (predicate.mode === "advisory") continue;
|
|
511
512
|
throw error;
|
|
512
513
|
}
|
|
513
|
-
for (let row = 0; row < batch.numRows; row++) mask[row] &= values[row] === true ? 1 : 0;
|
|
514
|
+
for (let row = 0; row < batch.numRows; row++) mask[row]! &= values[row] === true ? 1 : 0;
|
|
514
515
|
}
|
|
515
516
|
return mask;
|
|
516
517
|
}
|
|
@@ -98,8 +98,9 @@ export function decodeFilterDelta(bytes: Uint8Array): VgiBatch {
|
|
|
98
98
|
*/
|
|
99
99
|
function deltaRevisionKeys(batch: VgiBatch): string[] {
|
|
100
100
|
const column = batch.getChildAt(0);
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
const field = batch.schema.fields[0];
|
|
102
|
+
if (!column || !field) throw new FilterV2Error("delta document has no filter_spec column");
|
|
103
|
+
const raw = readCanonicalValue(field.type, column, 0);
|
|
103
104
|
const document = JSON.parse(String(raw)) as { updates?: Array<{ id: string; revision: number }> };
|
|
104
105
|
return (document.updates ?? []).map((update) => revisionKey(update.id, update.revision));
|
|
105
106
|
}
|