@query-farm/vgi 0.27.0 → 0.29.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 +26 -7
- package/dist/arguments/argument-spec.d.ts +53 -0
- package/dist/arrow/impl-arrowjs/index.d.ts +1 -1
- package/dist/arrow/impl-arrowjs/iterate.d.ts +10 -1
- package/dist/arrow/impl-arrowjs/schema.d.ts +2 -0
- package/dist/arrow/impl-flechette/index.d.ts +1 -1
- package/dist/arrow/impl-flechette/iterate.d.ts +10 -1
- package/dist/arrow/impl-flechette/schema.d.ts +2 -0
- package/dist/arrow/index.d.ts +1 -1
- package/dist/arrow/schema-types.d.ts +3 -1
- package/dist/arrow/types.d.ts +39 -3
- package/dist/catalog/interface.d.ts +43 -0
- package/dist/client/client.d.ts +1 -1
- package/dist/client-entry.js +360 -178
- package/dist/client-entry.js.map +14 -14
- package/dist/functions/table.d.ts +63 -0
- package/dist/functions/types.d.ts +38 -0
- package/dist/generated/vgi-client.d.ts +59 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +19 -0
- package/dist/http/fetch.d.ts +10 -0
- package/dist/index.core.d.ts +2 -2
- package/dist/index.js +1203 -834
- package/dist/index.js.map +40 -37
- package/dist/protocol/handlers/catalog/shared.d.ts +0 -8
- package/dist/protocol/handlers/function.d.ts +11 -0
- package/dist/protocol/serializers/bind.d.ts +1 -2
- package/dist/protocol/serializers/cardinality.d.ts +1 -2
- package/dist/protocol/serializers/splits.d.ts +126 -0
- package/dist/protocol/types.d.ts +27 -0
- package/dist/request-auth.d.ts +28 -0
- package/dist/serve-entry.d.ts +4 -0
- package/dist/serve-entry.js +745 -359
- package/dist/serve-entry.js.map +32 -29
- package/dist/split-token.d.ts +88 -0
- package/dist/worker-cf-entry.js +1029 -619
- package/dist/worker-cf-entry.js.map +37 -34
- package/package.json +3 -3
- package/src/arguments/argument-spec.ts +81 -0
- package/src/arguments/arguments.ts +0 -1
- package/src/arrow/impl-arrowjs/index.ts +1 -1
- package/src/arrow/impl-arrowjs/iterate.ts +21 -0
- package/src/arrow/impl-arrowjs/schema.ts +4 -0
- package/src/arrow/impl-flechette/index.ts +1 -1
- package/src/arrow/impl-flechette/iterate.ts +24 -1
- package/src/arrow/impl-flechette/schema.ts +4 -0
- package/src/arrow/index.ts +1 -1
- package/src/arrow/schema-types.ts +4 -0
- package/src/arrow/types.ts +39 -3
- package/src/catalog/interface.ts +124 -29
- package/src/catalog/read-only.ts +18 -18
- package/src/client/client.ts +6 -2
- package/src/functions/aggregate.ts +3 -0
- package/src/functions/copy-from.ts +2 -1
- package/src/functions/copy-to.ts +2 -1
- package/src/functions/scalar.ts +11 -0
- package/src/functions/table-buffering.ts +3 -0
- package/src/functions/table-in-out.ts +8 -4
- package/src/functions/table.ts +129 -2
- package/src/functions/types.ts +40 -0
- package/src/generated/vgi-client.ts +63 -1
- package/src/generated/vgi-protocol-schemas.ts +240 -14
- package/src/http/fetch.ts +117 -2
- package/src/index.core.ts +2 -2
- package/src/protocol/handlers/aggregate.ts +10 -5
- package/src/protocol/handlers/catalog/admin.ts +41 -48
- package/src/protocol/handlers/catalog/index_methods.ts +4 -11
- package/src/protocol/handlers/catalog/macro.ts +8 -16
- package/src/protocol/handlers/catalog/shared.ts +10 -57
- package/src/protocol/handlers/catalog/table.ts +33 -96
- package/src/protocol/handlers/catalog/view.ts +13 -17
- package/src/protocol/handlers/function.ts +311 -18
- package/src/protocol/handlers/table-buffering.ts +7 -4
- package/src/protocol/serializers/bind.ts +56 -63
- package/src/protocol/serializers/cardinality.ts +7 -7
- package/src/protocol/serializers/init.ts +52 -10
- package/src/protocol/serializers/splits.ts +219 -0
- package/src/protocol/state-serializer.ts +55 -1
- package/src/protocol/types.ts +27 -0
- package/src/request-auth.ts +73 -0
- package/src/serve-entry.ts +5 -0
- package/src/split-token.ts +297 -0
- package/src/worker-cf-entry.ts +2 -1
- package/src/worker.ts +30 -10
package/README.md
CHANGED
|
@@ -387,13 +387,32 @@ For manual conversions outside a function, `codecFor(type)` returns the codec wi
|
|
|
387
387
|
|
|
388
388
|
### Factory name note
|
|
389
389
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
390
|
+
Four names — `int`, `int32`, `float32`, `bool` — mean different things depending on
|
|
391
|
+
which entry point you import from:
|
|
392
|
+
|
|
393
|
+
| Import from | `int` is | Write |
|
|
394
|
+
| --- | --- | --- |
|
|
395
|
+
| `@query-farm/vgi` | a ready-made `Int64` **type**, re-exported from vgi-rpc | `params: { n: int }` |
|
|
396
|
+
| `@query-farm/vgi/worker-cf` | the typed **factory** `int(bitWidth?, signed?)` | `params: { n: int() }` |
|
|
397
|
+
|
|
398
|
+
The package root also re-exports `float`, `str` and `bytes` as ready-made types;
|
|
399
|
+
the Cloudflare entry does not have them at all (use `float64()`, `utf8()`,
|
|
400
|
+
`binary()`).
|
|
401
|
+
|
|
402
|
+
Everything else in the typed factory set — `int8`/`int16`/`int64`, `uint*`,
|
|
403
|
+
`float16`/`float64`, `utf8`, `decimal*`, `dateDay`, `timestampMicros`, `struct`,
|
|
404
|
+
`list`, `map`, … — is a **factory on both entry points** and is exported from the
|
|
405
|
+
package root as usual.
|
|
406
|
+
|
|
407
|
+
**Prefer the explicit factories in portable code.** `int64()` means the same thing
|
|
408
|
+
everywhere; `int` does not, so moving a worker to Cloudflare Workers can turn a
|
|
409
|
+
correct declaration into a wrong one with no other edit. Since 0.29.0 that mistake
|
|
410
|
+
is caught at definition time rather than silently registering a `Function` as an
|
|
411
|
+
argument type:
|
|
412
|
+
|
|
413
|
+
```
|
|
414
|
+
defineScalarFunction("double"): params.n is a type factory, not an Arrow type — call it: int64().
|
|
415
|
+
```
|
|
397
416
|
|
|
398
417
|
## Migration: the type-handling break
|
|
399
418
|
|
|
@@ -58,6 +58,59 @@ export declare function formatRange(ge?: number, le?: number, gt?: number, lt?:
|
|
|
58
58
|
* no field). Mirrors Python's `_constraint_kwargs`.
|
|
59
59
|
*/
|
|
60
60
|
export declare function constraintSpecFields(constraints: ArgumentConstraints | undefined): Pick<ArgumentSpec, "defaultJson" | "choicesJson" | "rangeNotation" | "pattern">;
|
|
61
|
+
/**
|
|
62
|
+
* Narrow a bind-time argument value from Arrow's bigint to a plain number.
|
|
63
|
+
*
|
|
64
|
+
* DuckDB types an integer literal as BIGINT, so `series(3)` arrives as `3n`
|
|
65
|
+
* whether or not anyone wanted 64 bits. Nobody writes `BigInt(1000)` for a page
|
|
66
|
+
* size, so the arg paths narrow — and they now all narrow the same way, which
|
|
67
|
+
* they did not before (two sites used safeNumber, two a bare Number).
|
|
68
|
+
*
|
|
69
|
+
* This is lossy above 2^53, and that is a deliberate call rather than an
|
|
70
|
+
* oversight. Every int64 *argument* across the fixtures and every shipped
|
|
71
|
+
* worker is a small control value — count, page_size, batch_size, increment,
|
|
72
|
+
* lag_minutes, restatement_lookback_days. The large int64s in the test suite
|
|
73
|
+
* are all somewhere else entirely:
|
|
74
|
+
*
|
|
75
|
+
* - column data (copy_to/types.test, copy_to/parallel.test) — never touches
|
|
76
|
+
* this path;
|
|
77
|
+
* - filter-pushdown constants (filter_pushdown/integers.test pins 2^53+1 on
|
|
78
|
+
* purpose) — deserialize.ts keeps those bigint, with its own regression
|
|
79
|
+
* test;
|
|
80
|
+
* - varargs values (constant_columns) — read raw off bindCall.arguments,
|
|
81
|
+
* because extractArgs' copy of them is not what the function reads;
|
|
82
|
+
* - time-travel versions — carried as strings (`at_value`).
|
|
83
|
+
*
|
|
84
|
+
* Preserving the bigint on overflow was tried and reverted: it buys nothing for
|
|
85
|
+
* any argument that exists, and costs a JS type that depends on magnitude, so a
|
|
86
|
+
* worker doing `args.n + 1` would work in every test and fail on one caller's
|
|
87
|
+
* input. If an argument ever genuinely needs the full range — a snowflake id, a
|
|
88
|
+
* nanosecond epoch — the fix is to make int64 arguments bigint by declared
|
|
89
|
+
* type, not by magnitude.
|
|
90
|
+
*/
|
|
91
|
+
export declare function narrowArgValue(value: unknown): unknown;
|
|
92
|
+
/**
|
|
93
|
+
* Reject a type *factory* where an Arrow *type* was expected.
|
|
94
|
+
*
|
|
95
|
+
* `params: { n: int64 }` (no parentheses) is accepted by the type system —
|
|
96
|
+
* `VgiDataType` is loose enough — and then silently produces an ArgumentSpec
|
|
97
|
+
* whose `arrowType` is a Function. Nothing complains until the schema is
|
|
98
|
+
* serialized or the bind arrives, and the error at that point names neither the
|
|
99
|
+
* argument nor the cause.
|
|
100
|
+
*
|
|
101
|
+
* The mistake is easy to make on purpose, too: the same identifier is a
|
|
102
|
+
* ready-made type on one entry point and a factory on another.
|
|
103
|
+
*
|
|
104
|
+
* @query-farm/vgi int, int32, float32, bool → type instances
|
|
105
|
+
* @query-farm/vgi/worker-cf int, int32, float32, bool → factories
|
|
106
|
+
*
|
|
107
|
+
* So moving a worker to Cloudflare can turn a correct declaration into a
|
|
108
|
+
* silently wrong one with no other edit. Failing here, at definition time,
|
|
109
|
+
* makes that a startup error naming the field.
|
|
110
|
+
*/
|
|
111
|
+
export declare function assertArrowType(value: unknown, where: string): void;
|
|
112
|
+
/** {@link assertArrowType} over a record of declared types, e.g. `params`. */
|
|
113
|
+
export declare function assertArrowTypes(types: Record<string, unknown> | undefined, where: string): void;
|
|
61
114
|
/**
|
|
62
115
|
* Enforce a bind-time const value against its declared {@link ArgumentConstraints},
|
|
63
116
|
* throwing {@link ArgumentValidationError} on violation. Mirrors the Python SDK's
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { VgiBackendInfo } from "../types.js";
|
|
2
2
|
export declare const backend: VgiBackendInfo;
|
|
3
|
-
export { schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, binary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, } from "./schema.js";
|
|
3
|
+
export { schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, largeUtf8, binary, largeBinary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, } from "./schema.js";
|
|
4
4
|
export { emptyBatch } from "./empty.js";
|
|
5
5
|
export { batchFromRows, batchFromColumns, columnFromArray } from "./build.js";
|
|
6
6
|
export { iterRows, batchToScalarDict, batchToSecretDict, safeNumber, decodeDictValue, } from "./iterate.js";
|
|
@@ -34,6 +34,15 @@ export declare function decodeDictValue(value: any, index?: number): any;
|
|
|
34
34
|
*/
|
|
35
35
|
export declare function batchToSecretDict(batch: RecordBatch | VgiBatch | null): Record<string, Record<string, any>>;
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Narrow a bigint to a number, refusing to do it lossily.
|
|
38
|
+
*
|
|
39
|
+
* Arrow int64/uint64 values arrive as bigint. Several bind-time argument paths
|
|
40
|
+
* want a plain number, and used to get one from a bare `Number(value)` — which
|
|
41
|
+
* silently rounds above 2^53, so an id or a nanosecond timestamp passed as a
|
|
42
|
+
* function argument came back subtly wrong with nothing logged anywhere.
|
|
43
|
+
*
|
|
44
|
+
* Throwing is the lesser evil: a caller that genuinely wants a lossy narrowing
|
|
45
|
+
* can still write `Number(v)` themselves, but nobody has to discover the loss
|
|
46
|
+
* from mismatched output weeks later.
|
|
38
47
|
*/
|
|
39
48
|
export declare function safeNumber(value: any): number;
|
|
@@ -36,7 +36,9 @@ export declare const float16: () => VgiDataType;
|
|
|
36
36
|
export declare const float32: () => VgiDataType;
|
|
37
37
|
export declare const float64: () => VgiDataType;
|
|
38
38
|
export declare const utf8: () => VgiDataType;
|
|
39
|
+
export declare const largeUtf8: () => VgiDataType;
|
|
39
40
|
export declare const binary: () => VgiDataType;
|
|
41
|
+
export declare const largeBinary: () => VgiDataType;
|
|
40
42
|
export declare const fixedSizeBinary: (byteWidth: number) => VgiDataType;
|
|
41
43
|
export declare function decimal(precision: number, scale: number, bitWidth?: 32 | 64 | 128 | 256): VgiDataType;
|
|
42
44
|
export declare const decimal128: (precision: number, scale: number) => VgiDataType;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { VgiBackendInfo } from "../types.js";
|
|
2
2
|
import "./compat.js";
|
|
3
3
|
export declare const backend: VgiBackendInfo;
|
|
4
|
-
export { schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, binary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, } from "./schema.js";
|
|
4
|
+
export { schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, largeUtf8, binary, largeBinary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, } from "./schema.js";
|
|
5
5
|
export { emptyBatch } from "./empty.js";
|
|
6
6
|
export { batchFromRows, batchFromColumns, columnFromArray } from "./build.js";
|
|
7
7
|
export { iterRows, batchToScalarDict, batchToSecretDict, safeNumber, decodeDictValue, } from "./iterate.js";
|
|
@@ -24,6 +24,15 @@ export declare function decodeDictValue(value: any, _index?: number): any;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function batchToSecretDict(batch: VgiBatch | null): Record<string, Record<string, any>>;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Narrow a bigint to a number, refusing to do it lossily.
|
|
28
|
+
*
|
|
29
|
+
* Arrow int64/uint64 values arrive as bigint. Several bind-time argument paths
|
|
30
|
+
* want a plain number, and used to get one from a bare `Number(value)` — which
|
|
31
|
+
* silently rounds above 2^53, so an id or a nanosecond timestamp passed as a
|
|
32
|
+
* function argument came back subtly wrong with nothing logged anywhere.
|
|
33
|
+
*
|
|
34
|
+
* Throwing is the lesser evil: a caller that genuinely wants a lossy narrowing
|
|
35
|
+
* can still write `Number(v)` themselves, but nobody has to discover the loss
|
|
36
|
+
* from mismatched output weeks later.
|
|
28
37
|
*/
|
|
29
38
|
export declare function safeNumber(value: any): number;
|
|
@@ -21,7 +21,9 @@ export declare const float16: () => VgiDataType;
|
|
|
21
21
|
export declare const float32: () => VgiDataType;
|
|
22
22
|
export declare const float64: () => VgiDataType;
|
|
23
23
|
export declare const utf8: () => VgiDataType;
|
|
24
|
+
export declare const largeUtf8: () => VgiDataType;
|
|
24
25
|
export declare const binary: () => VgiDataType;
|
|
26
|
+
export declare const largeBinary: () => VgiDataType;
|
|
25
27
|
export declare const fixedSizeBinary: (stride: number) => VgiDataType;
|
|
26
28
|
export declare function decimal(precision: number, scale: number, bitWidth?: 32 | 64 | 128 | 256): VgiDataType;
|
|
27
29
|
export declare const decimal128: (precision: number, scale: number) => VgiDataType;
|
package/dist/arrow/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type { VgiTypeId, VgiDataType, VgiField, VgiSchema, VgiColumn, VgiColumnD
|
|
|
2
2
|
export { TypeId, isNull, isInt, isFloat, isBinary, isUtf8, isBool, isDecimal, isDate, isTime, isTimestamp, isInterval, isList, isStruct, isUnion, isFixedSizeBinary, isFixedSizeList, isMap, isDuration, isDictionary, isBatch, typeSignature, } from "./predicates.js";
|
|
3
3
|
export { backend, emptyBatch, batchFromRows, batchFromColumns, columnFromArray, iterRows, batchToScalarDict, batchToSecretDict, safeNumber, decodeDictValue, filterBatch, projectSchema, projectBatch, withBatchMetadata, adoptArrowJsShape, readCanonicalValue, serializeSchema, deserializeSchema, serializeBatch, deserializeBatch, buildStatisticsBatch, } from "#arrow-impl";
|
|
4
4
|
export type { ColumnStatistics } from "#arrow-impl";
|
|
5
|
-
export { schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, binary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, timestampSeconds, timestampMillis, timestampMicros, timestampNanos, durationSeconds, durationMillis, durationMicros, durationNanos, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, } from "./schema-types.js";
|
|
5
|
+
export { schema, field, nullType, bool, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64, float16, float32, float64, utf8, largeUtf8, binary, largeBinary, fixedSizeBinary, decimal, decimal128, decimal256, date, dateDay, dateMillisecond, time, timeSecond, timeMillisecond, timeMicrosecond, timeNanosecond, timestamp, duration, interval, timestampSeconds, timestampMillis, timestampMicros, timestampNanos, durationSeconds, durationMillis, durationMicros, durationNanos, list, fixedSizeList, struct, map, dictionary, union, sparseUnion, denseUnion, TimeUnit, DateUnit, IntervalUnit, UnionMode, } from "./schema-types.js";
|
|
6
6
|
export type { NullDescriptor, BoolType, IntType, Int8Type, Int16Type, Int32Type, Int64Type, Uint8Type, Uint16Type, Uint32Type, Uint64Type, FloatType, Utf8Type, LargeUtf8Type, BinaryType, LargeBinaryType, FixedSizeBinaryType, DecimalType, Date32Type, Date64Type, Time32Type, Time64Type, TimestampType, DurationType, IntervalType, ListType, FixedSizeListType, StructType, MapType, DictionaryType, UnionType, TypedField, TUnit, } from "./codec/type-descriptors.js";
|
|
7
7
|
export type { RichValue, RawValue, ValueFor, Repr } from "./codec/repr.js";
|
|
8
8
|
export { codecFor } from "./codec/registry.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as impl from "#arrow-impl";
|
|
2
2
|
import type { VgiField, VgiDataType } from "./types.js";
|
|
3
|
-
import type { NullDescriptor, BoolType, Int8Type, Int16Type, Int32Type, Int64Type, Uint8Type, Uint16Type, Uint32Type, Uint64Type, IntType, FloatType, Utf8Type, BinaryType, FixedSizeBinaryType, DecimalType, Date32Type, Date64Type, Time32Type, Time64Type, TimestampType, DurationType, IntervalType, ListType, FixedSizeListType, StructType, MapType, DictionaryType, UnionType, TypedField, TUnit } from "./codec/type-descriptors.js";
|
|
3
|
+
import type { NullDescriptor, BoolType, Int8Type, Int16Type, Int32Type, Int64Type, Uint8Type, Uint16Type, Uint32Type, Uint64Type, IntType, FloatType, Utf8Type, LargeUtf8Type, BinaryType, LargeBinaryType, FixedSizeBinaryType, DecimalType, Date32Type, Date64Type, Time32Type, Time64Type, TimestampType, DurationType, IntervalType, ListType, FixedSizeListType, StructType, MapType, DictionaryType, UnionType, TypedField, TUnit } from "./codec/type-descriptors.js";
|
|
4
4
|
export declare const TimeUnit: {
|
|
5
5
|
readonly SECOND: import("@query-farm/apache-arrow").TimeUnit.SECOND;
|
|
6
6
|
readonly MILLISECOND: import("@query-farm/apache-arrow").TimeUnit.MILLISECOND;
|
|
@@ -35,7 +35,9 @@ export declare const float16: () => FloatType;
|
|
|
35
35
|
export declare const float32: () => FloatType;
|
|
36
36
|
export declare const float64: () => FloatType;
|
|
37
37
|
export declare const utf8: () => Utf8Type;
|
|
38
|
+
export declare const largeUtf8: () => LargeUtf8Type;
|
|
38
39
|
export declare const binary: () => BinaryType;
|
|
40
|
+
export declare const largeBinary: () => LargeBinaryType;
|
|
39
41
|
export declare const fixedSizeBinary: (byteWidth: number) => FixedSizeBinaryType;
|
|
40
42
|
export declare const decimal: (precision: number, scale: number, bitWidth?: 32 | 64 | 128 | 256) => DecimalType;
|
|
41
43
|
export declare const decimal128: (precision: number, scale: number) => DecimalType;
|
package/dist/arrow/types.d.ts
CHANGED
|
@@ -20,9 +20,43 @@ export interface VgiSchema {
|
|
|
20
20
|
readonly fields: readonly VgiField[];
|
|
21
21
|
readonly metadata: Map<string, string>;
|
|
22
22
|
}
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
/**
|
|
24
|
+
* Column view over one column of a batch.
|
|
25
|
+
*
|
|
26
|
+
* The value type is erased by default: arrow-js parameterizes on DataType and
|
|
27
|
+
* flechette on value type, so the facade cannot name one without picking a
|
|
28
|
+
* backend. Supply `T` at the use site — the column's declared type makes it
|
|
29
|
+
* known there — and the cast disappears:
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const ns = batch.getChildAt(0)! as Iterable<bigint | null>;
|
|
33
|
+
* for (const v of ns) { ... } // v: bigint | null
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* A type parameter here would read better, but it cannot be had cheaply: both
|
|
37
|
+
* backends' native batches are assigned to VgiBatch structurally, and a
|
|
38
|
+
* concrete `get(): unknown` does not satisfy a generic `get(): T`. Adding one
|
|
39
|
+
* would mean casting at ~25 internal sites to remove one cast in user code.
|
|
40
|
+
*
|
|
41
|
+
* **These are the backend's own values, not codec output.** `get()` and
|
|
42
|
+
* iteration return whatever the Arrow implementation stores, which for some
|
|
43
|
+
* types is not the value the SDK documents:
|
|
44
|
+
*
|
|
45
|
+
* | Arrow type | here | {@link iterRows} |
|
|
46
|
+
* | ---------------- | ----------------------------- | --------------------- |
|
|
47
|
+
* | `int64` | `bigint` | `bigint` (same) |
|
|
48
|
+
* | `utf8`, `float64`| `string`, `number` | same |
|
|
49
|
+
* | `decimal128` | backend limbs (`DecimalBigNum`)| `bigint`, unscaled |
|
|
50
|
+
* | `timestamp[us]` | millisecond `number` | microsecond `bigint` |
|
|
51
|
+
* | `date32` | millisecond `number` | `Date` |
|
|
52
|
+
*
|
|
53
|
+
* `repr: "raw"` on a function selects the *codec's* representation and has no
|
|
54
|
+
* effect on this path.
|
|
55
|
+
*
|
|
56
|
+
* So: reach for `getChildAt` on integer, float, boolean, string and binary
|
|
57
|
+
* columns, where it is the cheapest correct thing. For temporal, decimal and
|
|
58
|
+
* nested types go through {@link iterRows}, which runs the codec.
|
|
59
|
+
*/
|
|
26
60
|
export interface VgiColumn {
|
|
27
61
|
readonly type: VgiDataType;
|
|
28
62
|
readonly length: number;
|
|
@@ -32,7 +66,9 @@ export interface VgiColumn {
|
|
|
32
66
|
export interface VgiBatch {
|
|
33
67
|
readonly schema: VgiSchema;
|
|
34
68
|
readonly numRows: number;
|
|
69
|
+
/** See {@link VgiColumn} — this does NOT run the codec. */
|
|
35
70
|
getChild(name: string): VgiColumn | null;
|
|
71
|
+
/** See {@link VgiColumn} — this does NOT run the codec. */
|
|
36
72
|
getChildAt(index: number): VgiColumn | null;
|
|
37
73
|
}
|
|
38
74
|
export interface VgiBackendInfo {
|
|
@@ -96,6 +96,21 @@ export interface ScanFunctionResult {
|
|
|
96
96
|
/** DuckDB extensions to load before calling the function. */
|
|
97
97
|
requiredExtensions: string[];
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Encode a ScanFunctionResult wire record — the single-row batch shape
|
|
101
|
+
* `{ function_name, arguments, required_extensions }` that
|
|
102
|
+
* `catalog_table_scan_function_get` returns and that a function-backed table
|
|
103
|
+
* inlines into `TableInfo.scan_function`.
|
|
104
|
+
*
|
|
105
|
+
* It exists so there is exactly one place that names those columns. The
|
|
106
|
+
* inline-scan path used to restate the schema locally even though codegen
|
|
107
|
+
* emits it; a hand-written wire schema is how four SDKs ended up disagreeing
|
|
108
|
+
* about which columns were binary and which were large_binary.
|
|
109
|
+
*
|
|
110
|
+
* `argumentsBytes` is the already-serialized inner arguments batch (one column
|
|
111
|
+
* per argument: `arg_<index>` positional, bare name for named).
|
|
112
|
+
*/
|
|
113
|
+
export declare function encodeScanFunctionResult(functionName: string, argumentsBytes: Uint8Array, requiredExtensions?: string[]): Uint8Array;
|
|
99
114
|
/**
|
|
100
115
|
* Decode a ScanFunctionResult from a wire-shape inner result dict.
|
|
101
116
|
*
|
|
@@ -149,6 +164,16 @@ export interface ScanBranchInput {
|
|
|
149
164
|
branchFilter?: string | null;
|
|
150
165
|
/** Declares this branch as the INSERT target (at most one per table). */
|
|
151
166
|
writable?: boolean;
|
|
167
|
+
/** Custom file FORMAT this branch reads, for a format-backed branch. */
|
|
168
|
+
formatName?: string | null;
|
|
169
|
+
/** Locations the format branch reads. */
|
|
170
|
+
formatLocations?: string[] | null;
|
|
171
|
+
/** Reader options for a format branch, as a 1-row IPC batch whose COLUMN
|
|
172
|
+
* NAMES are the option names — the same shape `arguments` uses, because an
|
|
173
|
+
* option value may be any Arrow type. These BECOME the reader's named
|
|
174
|
+
* arguments, so without them a format branch cannot pass its reader a
|
|
175
|
+
* delimiter, a header flag, or anything else. */
|
|
176
|
+
formatOptions?: Uint8Array | null;
|
|
152
177
|
/**
|
|
153
178
|
* Catalog-table branch (lakehouse federation): leave `functionName` empty and
|
|
154
179
|
* set these to scan the base table
|
|
@@ -159,6 +184,24 @@ export interface ScanBranchInput {
|
|
|
159
184
|
sourceSchema?: string | null;
|
|
160
185
|
sourceTable?: string | null;
|
|
161
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* Serialize a single branch's arguments to the nested-IPC form `ScanBranch`
|
|
189
|
+
* expects: a 1-row batch with one column per argument — `arg_<index>` for
|
|
190
|
+
* positional args, the bare name for named args. Mirrors Python's
|
|
191
|
+
* `ScanBranch.to_row_dict` argument handling.
|
|
192
|
+
*/
|
|
193
|
+
/**
|
|
194
|
+
* Encode a format branch's reader options.
|
|
195
|
+
*
|
|
196
|
+
* Same shape as a branch's `arguments` blob — a 1-row batch whose COLUMN NAMES
|
|
197
|
+
* are the option names — because an option value may be any Arrow type, so no
|
|
198
|
+
* static schema could describe the map. Exported because a worker building a
|
|
199
|
+
* format branch needs it and has no other way to produce those bytes.
|
|
200
|
+
*/
|
|
201
|
+
export declare function encodeFormatOptions(options: Record<string, {
|
|
202
|
+
value: unknown;
|
|
203
|
+
type: VgiDataType;
|
|
204
|
+
}>): Uint8Array;
|
|
162
205
|
/**
|
|
163
206
|
* Build a multi-branch `ScanBranchesResult` wire dict from explicit branch
|
|
164
207
|
* definitions. Each branch becomes its own 1-row `ScanBranchSchema` IPC
|
package/dist/client/client.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { VgiClientOptions, TableFunctionOptions, ScalarFunctionOptions, Tab
|
|
|
10
10
|
* Works with any RpcClient transport (subprocess or HTTP):
|
|
11
11
|
* ```ts
|
|
12
12
|
* import { subprocessConnect } from "@query-farm/vgi-rpc";
|
|
13
|
-
* import { VgiClient, Arguments } from "vgi";
|
|
13
|
+
* import { VgiClient, Arguments } from "@query-farm/vgi";
|
|
14
14
|
*
|
|
15
15
|
* const rpc = subprocessConnect(["./my-worker"]);
|
|
16
16
|
* const client = new VgiClient(rpc);
|