@query-farm/vgi 0.6.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/LICENSE +134 -0
- package/README.md +494 -0
- package/dist/__dbg.test-d.d.ts +1 -0
- package/dist/arguments/argument-spec.d.ts +51 -0
- package/dist/arguments/arguments.d.ts +13 -0
- package/dist/arrow/codec/branded.d.ts +83 -0
- package/dist/arrow/codec/registry.d.ts +29 -0
- package/dist/arrow/codec/repr.d.ts +23 -0
- package/dist/arrow/codec/type-descriptors.d.ts +109 -0
- package/dist/arrow/impl-arrowjs/build.d.ts +19 -0
- package/dist/arrow/impl-arrowjs/canonical.d.ts +15 -0
- package/dist/arrow/impl-arrowjs/empty.d.ts +7 -0
- package/dist/arrow/impl-arrowjs/filter.d.ts +11 -0
- package/dist/arrow/impl-arrowjs/index.d.ts +11 -0
- package/dist/arrow/impl-arrowjs/ipc.d.ts +24 -0
- package/dist/arrow/impl-arrowjs/iterate.d.ts +39 -0
- package/dist/arrow/impl-arrowjs/project.d.ts +10 -0
- package/dist/arrow/impl-arrowjs/schema.d.ts +62 -0
- package/dist/arrow/impl-arrowjs/statistics.d.ts +13 -0
- package/dist/arrow/impl-flechette/build.d.ts +14 -0
- package/dist/arrow/impl-flechette/canonical.d.ts +18 -0
- package/dist/arrow/impl-flechette/empty.d.ts +9 -0
- package/dist/arrow/impl-flechette/filter.d.ts +10 -0
- package/dist/arrow/impl-flechette/index.d.ts +11 -0
- package/dist/arrow/impl-flechette/ipc.d.ts +33 -0
- package/dist/arrow/impl-flechette/iterate.d.ts +29 -0
- package/dist/arrow/impl-flechette/message-meta.d.ts +10 -0
- package/dist/arrow/impl-flechette/normalize-type.d.ts +11 -0
- package/dist/arrow/impl-flechette/project.d.ts +3 -0
- package/dist/arrow/impl-flechette/schema.d.ts +47 -0
- package/dist/arrow/impl-flechette/statistics.d.ts +13 -0
- package/dist/arrow/index.d.ts +11 -0
- package/dist/arrow/predicates.d.ts +47 -0
- package/dist/arrow/repr.test-d.d.ts +52 -0
- package/dist/arrow/schema-types.d.ts +71 -0
- package/dist/arrow/types.d.ts +57 -0
- package/dist/catalog/attach-option.d.ts +33 -0
- package/dist/catalog/attach-options.d.ts +30 -0
- package/dist/catalog/composite.d.ts +33 -0
- package/dist/catalog/descriptors.d.ts +154 -0
- package/dist/catalog/interface.d.ts +239 -0
- package/dist/catalog/read-only.d.ts +33 -0
- package/dist/client/client.d.ts +189 -0
- package/dist/client/errors.d.ts +26 -0
- package/dist/client/helpers.d.ts +12 -0
- package/dist/client/protocol.d.ts +16 -0
- package/dist/client/types.d.ts +125 -0
- package/dist/client-entry.d.ts +11 -0
- package/dist/client-entry.js +48 -0
- package/dist/client-entry.js.map +9 -0
- package/dist/codec/asd.d.ts +25 -0
- package/dist/crypto.d.ts +36 -0
- package/dist/errors.d.ts +24 -0
- package/dist/filter-pushdown/collector.d.ts +32 -0
- package/dist/filter-pushdown/deserialize.d.ts +16 -0
- package/dist/filter-pushdown/evaluate.d.ts +51 -0
- package/dist/filter-pushdown/index.d.ts +4 -0
- package/dist/filter-pushdown/types.d.ts +84 -0
- package/dist/functions/aggregate.d.ts +129 -0
- package/dist/functions/copy-from.d.ts +81 -0
- package/dist/functions/copy-to.d.ts +121 -0
- package/dist/functions/registry.d.ts +16 -0
- package/dist/functions/scalar.d.ts +98 -0
- package/dist/functions/storage-cf-do.d.ts +47 -0
- package/dist/functions/storage.d.ts +86 -0
- package/dist/functions/table-buffering.d.ts +99 -0
- package/dist/functions/table-in-out.d.ts +64 -0
- package/dist/functions/table.d.ts +118 -0
- package/dist/functions/types.d.ts +157 -0
- package/dist/generated/vgi-client.d.ts +466 -0
- package/dist/generated/vgi-protocol-schemas.d.ts +115 -0
- package/dist/index.core.d.ts +42 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +10888 -0
- package/dist/index.js.map +85 -0
- package/dist/metadata/resolve.d.ts +3 -0
- package/dist/metadata/serialize.d.ts +12 -0
- package/dist/metadata/types.d.ts +47 -0
- package/dist/protocol/dispatch.d.ts +23 -0
- package/dist/protocol/handlers/aggregate.d.ts +3 -0
- package/dist/protocol/handlers/catalog/admin.d.ts +3 -0
- package/dist/protocol/handlers/catalog/index.d.ts +3 -0
- package/dist/protocol/handlers/catalog/index_methods.d.ts +3 -0
- package/dist/protocol/handlers/catalog/macro.d.ts +3 -0
- package/dist/protocol/handlers/catalog/shared.d.ts +70 -0
- package/dist/protocol/handlers/catalog/table.d.ts +3 -0
- package/dist/protocol/handlers/catalog/view.d.ts +3 -0
- package/dist/protocol/handlers/function.d.ts +8 -0
- package/dist/protocol/handlers/shared.d.ts +31 -0
- package/dist/protocol/handlers/table-buffering.d.ts +3 -0
- package/dist/protocol/serialize.d.ts +4 -0
- package/dist/protocol/serializers/arguments.d.ts +3 -0
- package/dist/protocol/serializers/bind.d.ts +9 -0
- package/dist/protocol/serializers/cardinality.d.ts +7 -0
- package/dist/protocol/serializers/init.d.ts +9 -0
- package/dist/protocol/serializers/shared.d.ts +12 -0
- package/dist/protocol/state-serializer.d.ts +23 -0
- package/dist/protocol/types.d.ts +129 -0
- package/dist/secrets/helpers.d.ts +15 -0
- package/dist/types.d.ts +52 -0
- package/dist/util/arrow/index.d.ts +1 -0
- package/dist/util/bytes.d.ts +2 -0
- package/dist/util/statistics.d.ts +7 -0
- package/dist/worker-cf-entry.d.ts +30 -0
- package/dist/worker-cf-entry.js +8767 -0
- package/dist/worker-cf-entry.js.map +74 -0
- package/dist/worker.d.ts +36 -0
- package/package.json +96 -0
- package/src/arguments/argument-spec.ts +200 -0
- package/src/arguments/arguments.ts +81 -0
- package/src/arrow/codec/branded.ts +206 -0
- package/src/arrow/codec/registry.ts +674 -0
- package/src/arrow/codec/repr.ts +181 -0
- package/src/arrow/codec/type-descriptors.ts +137 -0
- package/src/arrow/impl-arrowjs/build.ts +88 -0
- package/src/arrow/impl-arrowjs/canonical.ts +509 -0
- package/src/arrow/impl-arrowjs/empty.ts +72 -0
- package/src/arrow/impl-arrowjs/filter.ts +53 -0
- package/src/arrow/impl-arrowjs/index.ts +54 -0
- package/src/arrow/impl-arrowjs/ipc.ts +67 -0
- package/src/arrow/impl-arrowjs/iterate.ts +159 -0
- package/src/arrow/impl-arrowjs/project.ts +73 -0
- package/src/arrow/impl-arrowjs/schema.ts +256 -0
- package/src/arrow/impl-arrowjs/statistics.ts +185 -0
- package/src/arrow/impl-flechette/build.ts +65 -0
- package/src/arrow/impl-flechette/canonical.ts +289 -0
- package/src/arrow/impl-flechette/empty.ts +20 -0
- package/src/arrow/impl-flechette/filter.ts +42 -0
- package/src/arrow/impl-flechette/index.ts +54 -0
- package/src/arrow/impl-flechette/ipc.ts +110 -0
- package/src/arrow/impl-flechette/iterate.ts +121 -0
- package/src/arrow/impl-flechette/message-meta.ts +175 -0
- package/src/arrow/impl-flechette/normalize-type.ts +99 -0
- package/src/arrow/impl-flechette/project.ts +64 -0
- package/src/arrow/impl-flechette/schema.ts +202 -0
- package/src/arrow/impl-flechette/statistics.ts +198 -0
- package/src/arrow/index.ts +129 -0
- package/src/arrow/predicates.ts +66 -0
- package/src/arrow/repr.test-d.ts +189 -0
- package/src/arrow/schema-types.ts +213 -0
- package/src/arrow/types.ts +74 -0
- package/src/catalog/attach-option.ts +107 -0
- package/src/catalog/attach-options.ts +79 -0
- package/src/catalog/composite.ts +180 -0
- package/src/catalog/descriptors.ts +164 -0
- package/src/catalog/interface.ts +721 -0
- package/src/catalog/read-only.ts +909 -0
- package/src/client/client.ts +1348 -0
- package/src/client/errors.ts +69 -0
- package/src/client/helpers.ts +56 -0
- package/src/client/protocol.ts +33 -0
- package/src/client/types.ts +140 -0
- package/src/client-entry.ts +112 -0
- package/src/codec/asd.ts +147 -0
- package/src/crypto.ts +143 -0
- package/src/errors.ts +61 -0
- package/src/filter-pushdown/collector.ts +147 -0
- package/src/filter-pushdown/deserialize.ts +253 -0
- package/src/filter-pushdown/evaluate.ts +591 -0
- package/src/filter-pushdown/index.ts +28 -0
- package/src/filter-pushdown/types.ts +91 -0
- package/src/functions/aggregate.ts +384 -0
- package/src/functions/copy-from.ts +282 -0
- package/src/functions/copy-to.ts +319 -0
- package/src/functions/registry.ts +258 -0
- package/src/functions/scalar.ts +356 -0
- package/src/functions/storage-cf-do.ts +303 -0
- package/src/functions/storage.ts +521 -0
- package/src/functions/table-buffering.ts +562 -0
- package/src/functions/table-in-out.ts +373 -0
- package/src/functions/table.ts +521 -0
- package/src/functions/types.ts +192 -0
- package/src/generated/vgi-client.ts +560 -0
- package/src/generated/vgi-protocol-schemas.ts +864 -0
- package/src/index.core.ts +267 -0
- package/src/index.ts +11 -0
- package/src/metadata/resolve.ts +109 -0
- package/src/metadata/serialize.ts +242 -0
- package/src/metadata/types.ts +60 -0
- package/src/protocol/dispatch.ts +52 -0
- package/src/protocol/handlers/aggregate.ts +355 -0
- package/src/protocol/handlers/catalog/admin.ts +368 -0
- package/src/protocol/handlers/catalog/index.ts +25 -0
- package/src/protocol/handlers/catalog/index_methods.ts +65 -0
- package/src/protocol/handlers/catalog/macro.ts +114 -0
- package/src/protocol/handlers/catalog/shared.ts +291 -0
- package/src/protocol/handlers/catalog/table.ts +401 -0
- package/src/protocol/handlers/catalog/view.ts +119 -0
- package/src/protocol/handlers/function.ts +302 -0
- package/src/protocol/handlers/shared.ts +80 -0
- package/src/protocol/handlers/table-buffering.ts +207 -0
- package/src/protocol/serialize.ts +23 -0
- package/src/protocol/serializers/arguments.ts +160 -0
- package/src/protocol/serializers/bind.ts +212 -0
- package/src/protocol/serializers/cardinality.ts +45 -0
- package/src/protocol/serializers/init.ts +247 -0
- package/src/protocol/serializers/shared.ts +46 -0
- package/src/protocol/state-serializer.ts +181 -0
- package/src/protocol/types.ts +153 -0
- package/src/secrets/helpers.ts +70 -0
- package/src/types.ts +71 -0
- package/src/util/arrow/index.ts +23 -0
- package/src/util/bytes.ts +14 -0
- package/src/util/statistics.ts +40 -0
- package/src/worker-cf-entry.ts +172 -0
- package/src/worker.ts +212 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
//
|
|
3
|
+
// Type-level value mapping — phase 3.
|
|
4
|
+
//
|
|
5
|
+
// Given the precise static descriptor for an Arrow type (see
|
|
6
|
+
// ./type-descriptors.ts), `RichValue<T>` / `RawValue<T>` / `ValueFor<T, M>`
|
|
7
|
+
// compute the exact JS value that type represents in the `rich` (default) and
|
|
8
|
+
// `raw` (branded) representations. These mirror the runtime codec rules:
|
|
9
|
+
//
|
|
10
|
+
// rich = canonical EXCEPT date32/date64 -> JS Date.
|
|
11
|
+
// raw = canonical, but with branded aliases that carry the wire unit.
|
|
12
|
+
//
|
|
13
|
+
// struct/list/map recurse. Corners that are genuinely ambiguous at the type
|
|
14
|
+
// level (union; an Int/Decimal/Timestamp built through a non-literal factory
|
|
15
|
+
// such as `int(bitWidth)` or `timestamp(unit)` with a runtime `number` unit)
|
|
16
|
+
// degrade to the canonical/`unknown` value and are noted inline.
|
|
17
|
+
|
|
18
|
+
import type { VgiDataType } from "../types.js";
|
|
19
|
+
import type {
|
|
20
|
+
TypedField,
|
|
21
|
+
BoolType,
|
|
22
|
+
IntType,
|
|
23
|
+
FloatType,
|
|
24
|
+
Utf8Type,
|
|
25
|
+
LargeUtf8Type,
|
|
26
|
+
BinaryType,
|
|
27
|
+
LargeBinaryType,
|
|
28
|
+
FixedSizeBinaryType,
|
|
29
|
+
DecimalType,
|
|
30
|
+
Date32Type,
|
|
31
|
+
Date64Type,
|
|
32
|
+
Time32Type,
|
|
33
|
+
Time64Type,
|
|
34
|
+
TimestampType,
|
|
35
|
+
DurationType,
|
|
36
|
+
ListType,
|
|
37
|
+
FixedSizeListType,
|
|
38
|
+
StructType,
|
|
39
|
+
MapType,
|
|
40
|
+
DictionaryType,
|
|
41
|
+
NullDescriptor,
|
|
42
|
+
TUnit,
|
|
43
|
+
} from "./type-descriptors.js";
|
|
44
|
+
import type {
|
|
45
|
+
Date32,
|
|
46
|
+
Date64Ms,
|
|
47
|
+
Time32S,
|
|
48
|
+
Time32Ms,
|
|
49
|
+
Time64Us,
|
|
50
|
+
Time64Ns,
|
|
51
|
+
TimestampSeconds,
|
|
52
|
+
TimestampMillis,
|
|
53
|
+
TimestampMicros,
|
|
54
|
+
TimestampNanos,
|
|
55
|
+
DurationSeconds,
|
|
56
|
+
DurationMillis,
|
|
57
|
+
DurationMicros,
|
|
58
|
+
DurationNanos,
|
|
59
|
+
UnscaledDecimal,
|
|
60
|
+
Int64,
|
|
61
|
+
Uint64,
|
|
62
|
+
} from "./branded.js";
|
|
63
|
+
|
|
64
|
+
// Re-export TypedField for callers building struct value shapes manually.
|
|
65
|
+
export type { TypedField };
|
|
66
|
+
|
|
67
|
+
/** Representation mode selector. */
|
|
68
|
+
export type Repr = "rich" | "raw";
|
|
69
|
+
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// Per-unit branded selectors (raw mode)
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
type RawTimestamp<U extends TUnit> = U extends "s"
|
|
75
|
+
? TimestampSeconds
|
|
76
|
+
: U extends "ms"
|
|
77
|
+
? TimestampMillis
|
|
78
|
+
: U extends "us"
|
|
79
|
+
? TimestampMicros
|
|
80
|
+
: U extends "ns"
|
|
81
|
+
? TimestampNanos
|
|
82
|
+
: bigint;
|
|
83
|
+
|
|
84
|
+
type RawDuration<U extends TUnit> = U extends "s"
|
|
85
|
+
? DurationSeconds
|
|
86
|
+
: U extends "ms"
|
|
87
|
+
? DurationMillis
|
|
88
|
+
: U extends "us"
|
|
89
|
+
? DurationMicros
|
|
90
|
+
: U extends "ns"
|
|
91
|
+
? DurationNanos
|
|
92
|
+
: bigint;
|
|
93
|
+
|
|
94
|
+
type RawTime32<U extends "s" | "ms"> = U extends "s" ? Time32S : Time32Ms;
|
|
95
|
+
type RawTime64<U extends "us" | "ns"> = U extends "us" ? Time64Us : Time64Ns;
|
|
96
|
+
|
|
97
|
+
// 64-bit int brands. The descriptor's `__signed` phantom picks signed vs
|
|
98
|
+
// unsigned; anything else (e.g. a non-literal `int(64)`) falls back to bigint.
|
|
99
|
+
type RawInt64<Signed extends boolean | undefined> = Signed extends true
|
|
100
|
+
? Int64
|
|
101
|
+
: Signed extends false
|
|
102
|
+
? Uint64
|
|
103
|
+
: bigint;
|
|
104
|
+
|
|
105
|
+
// ---------------------------------------------------------------------------
|
|
106
|
+
// RichValue<T>
|
|
107
|
+
// ---------------------------------------------------------------------------
|
|
108
|
+
|
|
109
|
+
/** The default author-facing JS value for the Arrow type `T`. */
|
|
110
|
+
export type RichValue<T extends VgiDataType> =
|
|
111
|
+
T extends NullDescriptor ? null :
|
|
112
|
+
T extends BoolType ? boolean :
|
|
113
|
+
T extends IntType<64, infer _S> ? bigint :
|
|
114
|
+
T extends IntType<8 | 16 | 32, infer _S> ? number :
|
|
115
|
+
T extends FloatType ? number :
|
|
116
|
+
T extends Utf8Type ? string :
|
|
117
|
+
T extends LargeUtf8Type ? string :
|
|
118
|
+
T extends BinaryType ? Uint8Array :
|
|
119
|
+
T extends LargeBinaryType ? Uint8Array :
|
|
120
|
+
T extends FixedSizeBinaryType ? Uint8Array :
|
|
121
|
+
T extends DecimalType ? bigint :
|
|
122
|
+
// date32 / date64 -> JS Date (the ONLY rich != canonical case)
|
|
123
|
+
T extends Date32Type ? Date :
|
|
124
|
+
T extends Date64Type ? Date :
|
|
125
|
+
T extends Time32Type<"s" | "ms"> ? number :
|
|
126
|
+
T extends Time64Type<"us" | "ns"> ? bigint :
|
|
127
|
+
T extends TimestampType<TUnit> ? bigint :
|
|
128
|
+
T extends DurationType<TUnit> ? bigint :
|
|
129
|
+
T extends StructType<infer C> ? RichStruct<C> :
|
|
130
|
+
T extends ListType<infer E> ? Array<RichValue<E> | null> :
|
|
131
|
+
T extends FixedSizeListType<infer E> ? Array<RichValue<E> | null> :
|
|
132
|
+
T extends MapType<infer K, infer V> ? Array<[RichValue<K>, RichValue<V> | null]> :
|
|
133
|
+
T extends DictionaryType<infer V> ? RichValue<V> :
|
|
134
|
+
unknown;
|
|
135
|
+
|
|
136
|
+
type RichStruct<C extends readonly TypedField<string, VgiDataType>[]> = {
|
|
137
|
+
[F in C[number] as F["name"]]: RichValue<F["type"]> | null;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
// RawValue<T>
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
/** The branded `raw` JS value for the Arrow type `T`. */
|
|
145
|
+
export type RawValue<T extends VgiDataType> =
|
|
146
|
+
T extends NullDescriptor ? null :
|
|
147
|
+
T extends BoolType ? boolean :
|
|
148
|
+
T extends IntType<64, infer S> ? RawInt64<S> :
|
|
149
|
+
T extends IntType<8 | 16 | 32, infer _S> ? number :
|
|
150
|
+
T extends FloatType ? number :
|
|
151
|
+
T extends Utf8Type ? string :
|
|
152
|
+
T extends LargeUtf8Type ? string :
|
|
153
|
+
T extends BinaryType ? Uint8Array :
|
|
154
|
+
T extends LargeBinaryType ? Uint8Array :
|
|
155
|
+
T extends FixedSizeBinaryType ? Uint8Array :
|
|
156
|
+
T extends DecimalType ? UnscaledDecimal :
|
|
157
|
+
T extends Date32Type ? Date32 :
|
|
158
|
+
T extends Date64Type ? Date64Ms :
|
|
159
|
+
T extends Time32Type<infer U> ? RawTime32<U> :
|
|
160
|
+
T extends Time64Type<infer U> ? RawTime64<U> :
|
|
161
|
+
T extends TimestampType<infer U> ? RawTimestamp<U> :
|
|
162
|
+
T extends DurationType<infer U> ? RawDuration<U> :
|
|
163
|
+
T extends StructType<infer C> ? RawStruct<C> :
|
|
164
|
+
T extends ListType<infer E> ? Array<RawValue<E> | null> :
|
|
165
|
+
T extends FixedSizeListType<infer E> ? Array<RawValue<E> | null> :
|
|
166
|
+
T extends MapType<infer K, infer V> ? Array<[RawValue<K>, RawValue<V> | null]> :
|
|
167
|
+
T extends DictionaryType<infer V> ? RawValue<V> :
|
|
168
|
+
unknown;
|
|
169
|
+
|
|
170
|
+
type RawStruct<C extends readonly TypedField<string, VgiDataType>[]> = {
|
|
171
|
+
[F in C[number] as F["name"]]: RawValue<F["type"]> | null;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// ---------------------------------------------------------------------------
|
|
175
|
+
// ValueFor<T, M>
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
|
|
178
|
+
/** The JS value for the Arrow type `T` under representation mode `M`. */
|
|
179
|
+
export type ValueFor<T extends VgiDataType, M extends Repr> = M extends "raw"
|
|
180
|
+
? RawValue<T>
|
|
181
|
+
: RichValue<T>;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
//
|
|
3
|
+
// Precise NOMINAL static type descriptors for Arrow types — phase 3.
|
|
4
|
+
//
|
|
5
|
+
// These interfaces are the compile-time face of the runtime `VgiDataType`
|
|
6
|
+
// values built by the facade factories (see ../schema-types.ts). Each carries
|
|
7
|
+
// a LITERAL `typeId` (and `unit` / `bitWidth` / child shape where relevant) so
|
|
8
|
+
// the type-level mapping in ./repr.ts can recover the exact JS value a type
|
|
9
|
+
// represents in `rich` vs `raw` mode.
|
|
10
|
+
//
|
|
11
|
+
// They are purely structural over `VgiDataType` (`{ readonly typeId }`): the
|
|
12
|
+
// runtime value is unchanged — the facade factories just cast their return to
|
|
13
|
+
// the matching descriptor (`new A_Int64() as unknown as Int64Type`), so both
|
|
14
|
+
// the arrow-js and flechette backends report IDENTICAL static types from the
|
|
15
|
+
// facade while keeping their native runtime values.
|
|
16
|
+
|
|
17
|
+
import type { VgiDataType, VgiField } from "../types.js";
|
|
18
|
+
import { TypeId } from "../predicates.js";
|
|
19
|
+
|
|
20
|
+
/** Time/timestamp/duration unit tag (matches the facade `TimeUnit` integers,
|
|
21
|
+
* but expressed as a string literal so it can flow through the type level). */
|
|
22
|
+
export type TUnit = "s" | "ms" | "us" | "ns";
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Scalar descriptors
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
export interface NullDescriptor extends VgiDataType { readonly typeId: typeof TypeId.Null; }
|
|
29
|
+
export interface BoolType extends VgiDataType { readonly typeId: typeof TypeId.Bool; }
|
|
30
|
+
|
|
31
|
+
// The width/sign discriminants are REQUIRED phantom properties (they don't
|
|
32
|
+
// exist at runtime — factories cast through `as unknown as` — but being
|
|
33
|
+
// required lets the conditional types in ./repr.ts discriminate int widths
|
|
34
|
+
// cleanly; optional phantoms collapse `IntType<64>` into the number arm).
|
|
35
|
+
export interface IntType<BW extends 8 | 16 | 32 | 64, Signed extends boolean>
|
|
36
|
+
extends VgiDataType {
|
|
37
|
+
readonly typeId: typeof TypeId.Int;
|
|
38
|
+
readonly __bitWidth: BW;
|
|
39
|
+
readonly __signed: Signed;
|
|
40
|
+
}
|
|
41
|
+
export type Int8Type = IntType<8, true>;
|
|
42
|
+
export type Int16Type = IntType<16, true>;
|
|
43
|
+
export type Int32Type = IntType<32, true>;
|
|
44
|
+
export type Int64Type = IntType<64, true>;
|
|
45
|
+
export type Uint8Type = IntType<8, false>;
|
|
46
|
+
export type Uint16Type = IntType<16, false>;
|
|
47
|
+
export type Uint32Type = IntType<32, false>;
|
|
48
|
+
export type Uint64Type = IntType<64, false>;
|
|
49
|
+
|
|
50
|
+
export interface FloatType extends VgiDataType { readonly typeId: typeof TypeId.Float; }
|
|
51
|
+
export interface Utf8Type extends VgiDataType { readonly typeId: typeof TypeId.Utf8; }
|
|
52
|
+
export interface LargeUtf8Type extends VgiDataType { readonly typeId: typeof TypeId.LargeUtf8; }
|
|
53
|
+
export interface BinaryType extends VgiDataType { readonly typeId: typeof TypeId.Binary; }
|
|
54
|
+
export interface LargeBinaryType extends VgiDataType { readonly typeId: typeof TypeId.LargeBinary; }
|
|
55
|
+
export interface FixedSizeBinaryType extends VgiDataType { readonly typeId: typeof TypeId.FixedSizeBinary; }
|
|
56
|
+
|
|
57
|
+
export interface DecimalType extends VgiDataType { readonly typeId: typeof TypeId.Decimal; }
|
|
58
|
+
|
|
59
|
+
// As with IntType, the unit/width discriminants below are REQUIRED phantom
|
|
60
|
+
// properties so the conditional value mappings in ./repr.ts can tell apart
|
|
61
|
+
// date32/date64, time32/time64, and the timestamp/duration units. They are
|
|
62
|
+
// type-only (factories cast through `as unknown as`).
|
|
63
|
+
|
|
64
|
+
/** date32 (unit DAY) — days. */
|
|
65
|
+
export interface Date32Type extends VgiDataType {
|
|
66
|
+
readonly typeId: typeof TypeId.Date;
|
|
67
|
+
readonly __dateUnit: "day";
|
|
68
|
+
}
|
|
69
|
+
/** date64 (unit MILLISECOND) — ms. */
|
|
70
|
+
export interface Date64Type extends VgiDataType {
|
|
71
|
+
readonly typeId: typeof TypeId.Date;
|
|
72
|
+
readonly __dateUnit: "ms";
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** time32 (bitWidth 32; unit s or ms). */
|
|
76
|
+
export interface Time32Type<U extends "s" | "ms"> extends VgiDataType {
|
|
77
|
+
readonly typeId: typeof TypeId.Time;
|
|
78
|
+
readonly __timeBits: 32;
|
|
79
|
+
readonly __unit: U;
|
|
80
|
+
}
|
|
81
|
+
/** time64 (bitWidth 64; unit us or ns). */
|
|
82
|
+
export interface Time64Type<U extends "us" | "ns"> extends VgiDataType {
|
|
83
|
+
readonly typeId: typeof TypeId.Time;
|
|
84
|
+
readonly __timeBits: 64;
|
|
85
|
+
readonly __unit: U;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface TimestampType<U extends TUnit> extends VgiDataType {
|
|
89
|
+
readonly typeId: typeof TypeId.Timestamp;
|
|
90
|
+
readonly __tsUnit: U;
|
|
91
|
+
}
|
|
92
|
+
export interface DurationType<U extends TUnit> extends VgiDataType {
|
|
93
|
+
readonly typeId: typeof TypeId.Duration;
|
|
94
|
+
readonly __durUnit: U;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface IntervalType extends VgiDataType { readonly typeId: typeof TypeId.Interval; }
|
|
98
|
+
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Composite descriptors
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
/** A typed field carrying its child's precise descriptor in the static type. */
|
|
104
|
+
export interface TypedField<Name extends string, T extends VgiDataType> extends VgiField {
|
|
105
|
+
readonly name: Name;
|
|
106
|
+
readonly type: T;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export interface ListType<T extends VgiDataType> extends VgiDataType {
|
|
110
|
+
readonly typeId: typeof TypeId.List;
|
|
111
|
+
readonly __child?: T;
|
|
112
|
+
}
|
|
113
|
+
export interface FixedSizeListType<T extends VgiDataType> extends VgiDataType {
|
|
114
|
+
readonly typeId: typeof TypeId.FixedSizeList;
|
|
115
|
+
readonly __child?: T;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Struct descriptor carrying its children as a tuple of TypedFields so the
|
|
119
|
+
* value mapping can build a precise `{ name: value }` shape. */
|
|
120
|
+
export interface StructType<Children extends readonly TypedField<string, VgiDataType>[]>
|
|
121
|
+
extends VgiDataType {
|
|
122
|
+
readonly typeId: typeof TypeId.Struct;
|
|
123
|
+
readonly __children?: Children;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface MapType<K extends VgiDataType, V extends VgiDataType> extends VgiDataType {
|
|
127
|
+
readonly typeId: typeof TypeId.Map;
|
|
128
|
+
readonly __key?: K;
|
|
129
|
+
readonly __value?: V;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export interface DictionaryType<V extends VgiDataType> extends VgiDataType {
|
|
133
|
+
readonly typeId: typeof TypeId.Dictionary;
|
|
134
|
+
readonly __dictValue?: V;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface UnionType extends VgiDataType { readonly typeId: typeof TypeId.Union; }
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Copyright 2025, 2026 Query Farm LLC - https://query.farm
|
|
2
|
+
// Build Arrow RecordBatches from row objects or column arrays (arrow-js).
|
|
3
|
+
//
|
|
4
|
+
// The public build path routes RICH author values through the codec registry
|
|
5
|
+
// (rich -> canonical) and then through the per-backend canonical writer
|
|
6
|
+
// (canonical -> arrow-js column data). All the arrow-js-specific assembly that
|
|
7
|
+
// used to live here now lives in ./canonical.ts; this file is just the public
|
|
8
|
+
// shape (batchFromRows / batchFromColumns / columnFromArray).
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
RecordBatch,
|
|
12
|
+
Schema,
|
|
13
|
+
Field,
|
|
14
|
+
Struct,
|
|
15
|
+
DataType,
|
|
16
|
+
makeData,
|
|
17
|
+
vectorFromArray,
|
|
18
|
+
} from "@query-farm/apache-arrow";
|
|
19
|
+
import type { VgiSchema, VgiDataType, VgiColumnData } from "../types.js";
|
|
20
|
+
import { emptyBatch } from "./empty.js";
|
|
21
|
+
import { codecFor } from "../codec/registry.js";
|
|
22
|
+
import { writeCanonicalColumn } from "./canonical.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Build an opaque column-data handle from a JS array. arrow-js wraps
|
|
26
|
+
* `vectorFromArray` and exposes its first `Data` node. Unlike the public
|
|
27
|
+
* build path, this is a low-level pass-through used by callers that already
|
|
28
|
+
* hold backend-native values, so it does NOT run the codec.
|
|
29
|
+
*/
|
|
30
|
+
export function columnFromArray(values: any[], type: VgiDataType): VgiColumnData {
|
|
31
|
+
return vectorFromArray(values, type as DataType).data[0] as VgiColumnData;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Build a RecordBatch from row objects (values are RICH).
|
|
36
|
+
*/
|
|
37
|
+
export function batchFromRows(
|
|
38
|
+
rows: Record<string, any>[],
|
|
39
|
+
schema: Schema | VgiSchema,
|
|
40
|
+
): RecordBatch {
|
|
41
|
+
const a = schema as Schema;
|
|
42
|
+
if (rows.length === 0) {
|
|
43
|
+
return emptyBatch(a);
|
|
44
|
+
}
|
|
45
|
+
const columns: Record<string, any[]> = {};
|
|
46
|
+
for (const field of a.fields) {
|
|
47
|
+
columns[field.name] = rows.map((r) => r[field.name] ?? null);
|
|
48
|
+
}
|
|
49
|
+
return batchFromColumns(columns, a);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Build a RecordBatch from column arrays (values are RICH). Each column is
|
|
54
|
+
* converted rich -> canonical via the codec, then canonical -> arrow-js column
|
|
55
|
+
* data via the canonical writer.
|
|
56
|
+
*/
|
|
57
|
+
export function batchFromColumns(
|
|
58
|
+
columns: Record<string, any[]>,
|
|
59
|
+
schema: Schema | VgiSchema,
|
|
60
|
+
repr: "rich" | "raw" = "rich",
|
|
61
|
+
): RecordBatch {
|
|
62
|
+
const a = schema as Schema;
|
|
63
|
+
const numRows =
|
|
64
|
+
a.fields.length > 0
|
|
65
|
+
? columns[a.fields[0].name]?.length ?? 0
|
|
66
|
+
: 0;
|
|
67
|
+
|
|
68
|
+
const children = a.fields.map((f: Field) => {
|
|
69
|
+
const values = columns[f.name];
|
|
70
|
+
if (!values) {
|
|
71
|
+
return makeData({ type: f.type, length: numRows, nullCount: numRows });
|
|
72
|
+
}
|
|
73
|
+
const codec = codecFor(f.type as VgiDataType);
|
|
74
|
+
const toCanon = repr === "raw" ? codec.rawToCanonical : codec.richToCanonical;
|
|
75
|
+
const canonical = values.map((v) => toCanon.call(codec, v));
|
|
76
|
+
return writeCanonicalColumn(f.type as VgiDataType, canonical);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const structType = new Struct(a.fields);
|
|
80
|
+
const data = makeData({
|
|
81
|
+
type: structType,
|
|
82
|
+
length: numRows,
|
|
83
|
+
children: children as any,
|
|
84
|
+
nullCount: 0,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return new RecordBatch(a, data);
|
|
88
|
+
}
|