@query-farm/vgi 0.15.0 → 0.18.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 +53 -0
- package/dist/cache-control.d.ts +90 -0
- package/dist/catalog/descriptors.d.ts +13 -7
- package/dist/client-entry.js +3862 -1
- package/dist/client-entry.js.map +34 -3
- package/dist/functions/table.d.ts +12 -0
- package/dist/generated/vgi-client.d.ts +1 -1
- package/dist/http/fetch.d.ts +35 -0
- package/dist/index.core.d.ts +1 -0
- package/dist/index.js +225 -11
- package/dist/index.js.map +11 -9
- package/dist/serve-entry.d.ts +84 -0
- package/dist/serve-entry.js +6428 -0
- package/dist/serve-entry.js.map +62 -0
- package/dist/worker-cf-entry.d.ts +4 -22
- package/dist/worker-cf-entry.js +466 -34
- package/dist/worker-cf-entry.js.map +12 -9
- package/package.json +18 -6
- package/src/cache-control.ts +133 -0
- package/src/catalog/descriptors.ts +13 -7
- package/src/catalog/read-only.ts +22 -14
- package/src/functions/table.ts +25 -1
- package/src/generated/vgi-client.ts +2 -2
- package/src/generated/vgi-protocol-schemas.ts +2 -2
- package/src/http/fetch.ts +80 -0
- package/src/index.core.ts +21 -0
- package/src/serve-entry.ts +233 -0
- package/src/worker-cf-entry.ts +7 -51
package/dist/client-entry.js
CHANGED
|
@@ -1,3 +1,3864 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __returnValue = (v) => v;
|
|
3
|
+
function __exportSetter(name, newValue) {
|
|
4
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
5
|
+
}
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true,
|
|
11
|
+
configurable: true,
|
|
12
|
+
set: __exportSetter.bind(all, name)
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/arrow/predicates.ts
|
|
17
|
+
var TypeId = {
|
|
18
|
+
Null: 1,
|
|
19
|
+
Int: 2,
|
|
20
|
+
Float: 3,
|
|
21
|
+
Binary: 4,
|
|
22
|
+
Utf8: 5,
|
|
23
|
+
Bool: 6,
|
|
24
|
+
Decimal: 7,
|
|
25
|
+
Date: 8,
|
|
26
|
+
Time: 9,
|
|
27
|
+
Timestamp: 10,
|
|
28
|
+
Interval: 11,
|
|
29
|
+
List: 12,
|
|
30
|
+
Struct: 13,
|
|
31
|
+
Union: 14,
|
|
32
|
+
FixedSizeBinary: 15,
|
|
33
|
+
FixedSizeList: 16,
|
|
34
|
+
Map: 17,
|
|
35
|
+
Duration: 18,
|
|
36
|
+
LargeBinary: 19,
|
|
37
|
+
LargeUtf8: 20,
|
|
38
|
+
Dictionary: -1
|
|
39
|
+
};
|
|
40
|
+
function isInt(t) {
|
|
41
|
+
return t.typeId === TypeId.Int;
|
|
42
|
+
}
|
|
43
|
+
function isBinary(t) {
|
|
44
|
+
return t.typeId === TypeId.Binary || t.typeId === TypeId.LargeBinary;
|
|
45
|
+
}
|
|
46
|
+
function isBool(t) {
|
|
47
|
+
return t.typeId === TypeId.Bool;
|
|
48
|
+
}
|
|
49
|
+
function isList(t) {
|
|
50
|
+
return t.typeId === TypeId.List;
|
|
51
|
+
}
|
|
52
|
+
function isStruct(t) {
|
|
53
|
+
return t.typeId === TypeId.Struct;
|
|
54
|
+
}
|
|
55
|
+
function isMap(t) {
|
|
56
|
+
return t.typeId === TypeId.Map;
|
|
57
|
+
}
|
|
58
|
+
function isDictionary(t) {
|
|
59
|
+
return t.typeId === TypeId.Dictionary;
|
|
60
|
+
}
|
|
61
|
+
// src/arrow/impl-arrowjs/index.ts
|
|
62
|
+
var exports_impl_arrowjs = {};
|
|
63
|
+
__export(exports_impl_arrowjs, {
|
|
64
|
+
utf8: () => utf8,
|
|
65
|
+
union: () => union,
|
|
66
|
+
uint8: () => uint8,
|
|
67
|
+
uint64: () => uint64,
|
|
68
|
+
uint32: () => uint32,
|
|
69
|
+
uint16: () => uint16,
|
|
70
|
+
timestamp: () => timestamp,
|
|
71
|
+
timeSecond: () => timeSecond,
|
|
72
|
+
timeNanosecond: () => timeNanosecond,
|
|
73
|
+
timeMillisecond: () => timeMillisecond,
|
|
74
|
+
timeMicrosecond: () => timeMicrosecond,
|
|
75
|
+
time: () => time,
|
|
76
|
+
struct: () => struct,
|
|
77
|
+
sparseUnion: () => sparseUnion,
|
|
78
|
+
serializeSchema: () => serializeSchema,
|
|
79
|
+
serializeBatch: () => serializeBatch,
|
|
80
|
+
schema: () => schema,
|
|
81
|
+
safeNumber: () => safeNumber,
|
|
82
|
+
readCanonicalValue: () => readCanonicalValue,
|
|
83
|
+
projectSchema: () => projectSchema,
|
|
84
|
+
projectBatch: () => projectBatch,
|
|
85
|
+
nullType: () => nullType,
|
|
86
|
+
map: () => map,
|
|
87
|
+
list: () => list,
|
|
88
|
+
iterRows: () => iterRows,
|
|
89
|
+
interval: () => interval,
|
|
90
|
+
int8: () => int8,
|
|
91
|
+
int64: () => int64,
|
|
92
|
+
int32: () => int32,
|
|
93
|
+
int16: () => int16,
|
|
94
|
+
int: () => int,
|
|
95
|
+
float64: () => float64,
|
|
96
|
+
float32: () => float32,
|
|
97
|
+
float16: () => float16,
|
|
98
|
+
fixedSizeList: () => fixedSizeList,
|
|
99
|
+
fixedSizeBinary: () => fixedSizeBinary,
|
|
100
|
+
filterBatch: () => filterBatch,
|
|
101
|
+
field: () => field,
|
|
102
|
+
emptyBatch: () => emptyBatch,
|
|
103
|
+
duration: () => duration,
|
|
104
|
+
dictionary: () => dictionary,
|
|
105
|
+
deserializeSchema: () => deserializeSchema,
|
|
106
|
+
deserializeBatch: () => deserializeBatch,
|
|
107
|
+
denseUnion: () => denseUnion,
|
|
108
|
+
decodeDictValue: () => decodeDictValue,
|
|
109
|
+
decimal256: () => decimal256,
|
|
110
|
+
decimal128: () => decimal128,
|
|
111
|
+
decimal: () => decimal,
|
|
112
|
+
dateMillisecond: () => dateMillisecond,
|
|
113
|
+
dateDay: () => dateDay,
|
|
114
|
+
date: () => date,
|
|
115
|
+
columnFromArray: () => columnFromArray,
|
|
116
|
+
buildStatisticsBatch: () => buildStatisticsBatch,
|
|
117
|
+
bool: () => bool,
|
|
118
|
+
binary: () => binary,
|
|
119
|
+
batchToSecretDict: () => batchToSecretDict,
|
|
120
|
+
batchToScalarDict: () => batchToScalarDict,
|
|
121
|
+
batchFromRows: () => batchFromRows,
|
|
122
|
+
batchFromColumns: () => batchFromColumns,
|
|
123
|
+
backend: () => backend,
|
|
124
|
+
UnionMode: () => UnionMode,
|
|
125
|
+
TimeUnit: () => TimeUnit,
|
|
126
|
+
IntervalUnit: () => IntervalUnit,
|
|
127
|
+
DateUnit: () => DateUnit
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// src/arrow/impl-arrowjs/schema.ts
|
|
131
|
+
import {
|
|
132
|
+
Schema as A_Schema,
|
|
133
|
+
Field as A_Field,
|
|
134
|
+
Null as A_Null,
|
|
135
|
+
Bool as A_Bool,
|
|
136
|
+
Int8 as A_Int8,
|
|
137
|
+
Int16 as A_Int16,
|
|
138
|
+
Int32 as A_Int32,
|
|
139
|
+
Int64 as A_Int64,
|
|
140
|
+
Uint8 as A_Uint8,
|
|
141
|
+
Uint16 as A_Uint16,
|
|
142
|
+
Uint32 as A_Uint32,
|
|
143
|
+
Uint64 as A_Uint64,
|
|
144
|
+
Float16 as A_Float16,
|
|
145
|
+
Float32 as A_Float32,
|
|
146
|
+
Float64 as A_Float64,
|
|
147
|
+
Utf8 as A_Utf8,
|
|
148
|
+
Binary as A_Binary,
|
|
149
|
+
Decimal as A_Decimal,
|
|
150
|
+
Date_ as A_Date,
|
|
151
|
+
Time as A_Time,
|
|
152
|
+
Timestamp as A_Timestamp,
|
|
153
|
+
Duration as A_Duration,
|
|
154
|
+
Interval as A_Interval,
|
|
155
|
+
List as A_List,
|
|
156
|
+
Struct as A_Struct,
|
|
157
|
+
Map_ as A_Map,
|
|
158
|
+
Dictionary as A_Dictionary,
|
|
159
|
+
SparseUnion as A_SparseUnion,
|
|
160
|
+
DenseUnion as A_DenseUnion,
|
|
161
|
+
FixedSizeBinary as A_FixedSizeBinary,
|
|
162
|
+
FixedSizeList as A_FixedSizeList,
|
|
163
|
+
DateUnit as A_DateUnit,
|
|
164
|
+
TimeUnit as A_TimeUnit,
|
|
165
|
+
IntervalUnit as A_IntervalUnit,
|
|
166
|
+
UnionMode as A_UnionMode
|
|
167
|
+
} from "@query-farm/apache-arrow";
|
|
168
|
+
var TimeUnit = {
|
|
169
|
+
SECOND: A_TimeUnit.SECOND,
|
|
170
|
+
MILLISECOND: A_TimeUnit.MILLISECOND,
|
|
171
|
+
MICROSECOND: A_TimeUnit.MICROSECOND,
|
|
172
|
+
NANOSECOND: A_TimeUnit.NANOSECOND
|
|
173
|
+
};
|
|
174
|
+
var DateUnit = {
|
|
175
|
+
DAY: A_DateUnit.DAY,
|
|
176
|
+
MILLISECOND: A_DateUnit.MILLISECOND
|
|
177
|
+
};
|
|
178
|
+
var IntervalUnit = {
|
|
179
|
+
YEAR_MONTH: A_IntervalUnit.YEAR_MONTH,
|
|
180
|
+
DAY_TIME: A_IntervalUnit.DAY_TIME,
|
|
181
|
+
MONTH_DAY_NANO: A_IntervalUnit.MONTH_DAY_NANO
|
|
182
|
+
};
|
|
183
|
+
var UnionMode = {
|
|
184
|
+
Sparse: A_UnionMode.Sparse,
|
|
185
|
+
Dense: A_UnionMode.Dense
|
|
186
|
+
};
|
|
187
|
+
function schema(fields, metadata) {
|
|
188
|
+
return new A_Schema(fields, metadata ?? new Map);
|
|
189
|
+
}
|
|
190
|
+
function field(name, type, nullable = true, metadata) {
|
|
191
|
+
return new A_Field(name, type, nullable, metadata ?? new Map);
|
|
192
|
+
}
|
|
193
|
+
var nullType = () => new A_Null;
|
|
194
|
+
var bool = () => new A_Bool;
|
|
195
|
+
var int8 = () => new A_Int8;
|
|
196
|
+
var int16 = () => new A_Int16;
|
|
197
|
+
var int32 = () => new A_Int32;
|
|
198
|
+
var int64 = () => new A_Int64;
|
|
199
|
+
var uint8 = () => new A_Uint8;
|
|
200
|
+
var uint16 = () => new A_Uint16;
|
|
201
|
+
var uint32 = () => new A_Uint32;
|
|
202
|
+
var uint64 = () => new A_Uint64;
|
|
203
|
+
function int(bitWidth = 32, signed = true) {
|
|
204
|
+
if (signed) {
|
|
205
|
+
switch (bitWidth) {
|
|
206
|
+
case 8:
|
|
207
|
+
return int8();
|
|
208
|
+
case 16:
|
|
209
|
+
return int16();
|
|
210
|
+
case 32:
|
|
211
|
+
return int32();
|
|
212
|
+
case 64:
|
|
213
|
+
return int64();
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
switch (bitWidth) {
|
|
217
|
+
case 8:
|
|
218
|
+
return uint8();
|
|
219
|
+
case 16:
|
|
220
|
+
return uint16();
|
|
221
|
+
case 32:
|
|
222
|
+
return uint32();
|
|
223
|
+
case 64:
|
|
224
|
+
return uint64();
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
throw new Error(`int: unsupported bitWidth ${bitWidth}`);
|
|
228
|
+
}
|
|
229
|
+
var float16 = () => new A_Float16;
|
|
230
|
+
var float32 = () => new A_Float32;
|
|
231
|
+
var float64 = () => new A_Float64;
|
|
232
|
+
var utf8 = () => new A_Utf8;
|
|
233
|
+
var binary = () => new A_Binary;
|
|
234
|
+
var fixedSizeBinary = (byteWidth) => new A_FixedSizeBinary(byteWidth);
|
|
235
|
+
function decimal(precision, scale, bitWidth = 128) {
|
|
236
|
+
return new A_Decimal(scale, precision, bitWidth);
|
|
237
|
+
}
|
|
238
|
+
var decimal128 = (precision, scale) => decimal(precision, scale, 128);
|
|
239
|
+
var decimal256 = (precision, scale) => decimal(precision, scale, 256);
|
|
240
|
+
var date = (unit = A_DateUnit.MILLISECOND) => new A_Date(unit);
|
|
241
|
+
var dateDay = () => date(A_DateUnit.DAY);
|
|
242
|
+
var dateMillisecond = () => date(A_DateUnit.MILLISECOND);
|
|
243
|
+
function time(unit = A_TimeUnit.MILLISECOND, bitWidth) {
|
|
244
|
+
const bw = bitWidth ?? (unit <= A_TimeUnit.MILLISECOND ? 32 : 64);
|
|
245
|
+
return new A_Time(unit, bw);
|
|
246
|
+
}
|
|
247
|
+
var timeSecond = () => time(A_TimeUnit.SECOND, 32);
|
|
248
|
+
var timeMillisecond = () => time(A_TimeUnit.MILLISECOND, 32);
|
|
249
|
+
var timeMicrosecond = () => time(A_TimeUnit.MICROSECOND, 64);
|
|
250
|
+
var timeNanosecond = () => time(A_TimeUnit.NANOSECOND, 64);
|
|
251
|
+
var timestamp = (unit = A_TimeUnit.MILLISECOND, timezone = null) => new A_Timestamp(unit, timezone);
|
|
252
|
+
var duration = (unit = A_TimeUnit.MILLISECOND) => new A_Duration(unit);
|
|
253
|
+
var interval = (unit = A_IntervalUnit.MONTH_DAY_NANO) => new A_Interval(unit);
|
|
254
|
+
function list(child) {
|
|
255
|
+
const childField = isField(child) ? child : field("item", child, true);
|
|
256
|
+
return new A_List(childField);
|
|
257
|
+
}
|
|
258
|
+
function fixedSizeList(child, listSize) {
|
|
259
|
+
const childField = isField(child) ? child : field("item", child, true);
|
|
260
|
+
return new A_FixedSizeList(listSize, childField);
|
|
261
|
+
}
|
|
262
|
+
function struct(children) {
|
|
263
|
+
return new A_Struct(children);
|
|
264
|
+
}
|
|
265
|
+
function map(keyField, valueField, keysSorted = false) {
|
|
266
|
+
const k = isField(keyField) ? keyField : field("key", keyField, false);
|
|
267
|
+
const v = isField(valueField) ? valueField : field("value", valueField, true);
|
|
268
|
+
const entries = field("entries", struct([k, v]), false);
|
|
269
|
+
return new A_Map(entries, keysSorted);
|
|
270
|
+
}
|
|
271
|
+
function dictionary(valueType, indexType = int16(), ordered = false, id) {
|
|
272
|
+
return new A_Dictionary(valueType, indexType, id, ordered);
|
|
273
|
+
}
|
|
274
|
+
function union(mode, children, typeIds) {
|
|
275
|
+
const childFields = children.map((c, i) => isField(c) ? c : field(String(i), c, true));
|
|
276
|
+
const ids = typeIds ?? childFields.map((_, i) => i);
|
|
277
|
+
const Ctor = mode === A_UnionMode.Dense ? A_DenseUnion : A_SparseUnion;
|
|
278
|
+
return new Ctor(ids, childFields);
|
|
279
|
+
}
|
|
280
|
+
var sparseUnion = (children, typeIds) => union(A_UnionMode.Sparse, children, typeIds);
|
|
281
|
+
var denseUnion = (children, typeIds) => union(A_UnionMode.Dense, children, typeIds);
|
|
282
|
+
function isField(x) {
|
|
283
|
+
return typeof x.name === "string" && x.type != null;
|
|
284
|
+
}
|
|
285
|
+
// src/arrow/impl-arrowjs/empty.ts
|
|
286
|
+
import {
|
|
287
|
+
RecordBatch,
|
|
288
|
+
Struct,
|
|
289
|
+
DataType,
|
|
290
|
+
makeData
|
|
291
|
+
} from "@query-farm/apache-arrow";
|
|
292
|
+
function emptyData(field2) {
|
|
293
|
+
const type = field2.type;
|
|
294
|
+
if (DataType.isList(type)) {
|
|
295
|
+
const childField = type.children[0];
|
|
296
|
+
return makeData({
|
|
297
|
+
type,
|
|
298
|
+
length: 0,
|
|
299
|
+
nullCount: 0,
|
|
300
|
+
child: emptyData(childField),
|
|
301
|
+
valueOffsets: new Int32Array([0])
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
if (DataType.isMap(type)) {
|
|
305
|
+
const entriesField = type.children[0];
|
|
306
|
+
return makeData({
|
|
307
|
+
type,
|
|
308
|
+
length: 0,
|
|
309
|
+
nullCount: 0,
|
|
310
|
+
child: emptyData(entriesField),
|
|
311
|
+
valueOffsets: new Int32Array([0])
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
if (DataType.isStruct(type)) {
|
|
315
|
+
const children = type.children.map((child) => emptyData(child));
|
|
316
|
+
return makeData({ type, length: 0, nullCount: 0, children });
|
|
317
|
+
}
|
|
318
|
+
return makeData({ type, length: 0, nullCount: 0 });
|
|
319
|
+
}
|
|
320
|
+
function emptyBatch(schema2) {
|
|
321
|
+
const a = schema2;
|
|
322
|
+
const children = a.fields.map((f) => emptyData(f));
|
|
323
|
+
const structType = new Struct(a.fields);
|
|
324
|
+
const data = makeData({
|
|
325
|
+
type: structType,
|
|
326
|
+
length: 0,
|
|
327
|
+
children,
|
|
328
|
+
nullCount: 0
|
|
329
|
+
});
|
|
330
|
+
return new RecordBatch(a, data);
|
|
331
|
+
}
|
|
332
|
+
// src/arrow/impl-arrowjs/build.ts
|
|
333
|
+
import {
|
|
334
|
+
RecordBatch as RecordBatch2,
|
|
335
|
+
Struct as Struct3,
|
|
336
|
+
makeData as makeData3,
|
|
337
|
+
vectorFromArray as vectorFromArray2
|
|
338
|
+
} from "@query-farm/apache-arrow";
|
|
339
|
+
|
|
340
|
+
// src/arrow/codec/registry.ts
|
|
341
|
+
var MS_PER_DAY = 86400000;
|
|
342
|
+
function isNullish(v) {
|
|
343
|
+
return v === null || v === undefined;
|
|
344
|
+
}
|
|
345
|
+
function err(label, msg, value) {
|
|
346
|
+
let shown;
|
|
347
|
+
try {
|
|
348
|
+
shown = typeof value === "bigint" ? `${value}n` : typeof value === "object" ? Object.prototype.toString.call(value) : String(value);
|
|
349
|
+
} catch {
|
|
350
|
+
shown = "<unprintable>";
|
|
351
|
+
}
|
|
352
|
+
throw new TypeError(`codec[${label}]: ${msg} (got ${typeof value}: ${shown})`);
|
|
353
|
+
}
|
|
354
|
+
function identity(label, check) {
|
|
355
|
+
const conv = (value) => {
|
|
356
|
+
if (isNullish(value))
|
|
357
|
+
return null;
|
|
358
|
+
check(value);
|
|
359
|
+
return value;
|
|
360
|
+
};
|
|
361
|
+
return {
|
|
362
|
+
label,
|
|
363
|
+
richToCanonical: conv,
|
|
364
|
+
canonicalToRich: conv,
|
|
365
|
+
rawToCanonical: conv,
|
|
366
|
+
canonicalToRaw: conv
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
function checkBoolean(label) {
|
|
370
|
+
return (v) => {
|
|
371
|
+
if (typeof v !== "boolean")
|
|
372
|
+
err(label, "expected boolean", v);
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
function checkIntNumber(label, min, max) {
|
|
376
|
+
return (v) => {
|
|
377
|
+
let n;
|
|
378
|
+
if (typeof v === "number")
|
|
379
|
+
n = v;
|
|
380
|
+
else if (typeof v === "bigint") {
|
|
381
|
+
if (v < BigInt(min) || v > BigInt(max))
|
|
382
|
+
err(label, `bigint out of ${label} range`, v);
|
|
383
|
+
return;
|
|
384
|
+
} else
|
|
385
|
+
return err(label, "expected number", v);
|
|
386
|
+
if (!Number.isInteger(n))
|
|
387
|
+
err(label, "expected an integer", v);
|
|
388
|
+
if (n < min || n > max)
|
|
389
|
+
err(label, `value out of ${label} range [${min}, ${max}]`, v);
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
function checkFloat(label) {
|
|
393
|
+
return (v) => {
|
|
394
|
+
if (typeof v === "number")
|
|
395
|
+
return;
|
|
396
|
+
if (typeof v === "bigint")
|
|
397
|
+
return;
|
|
398
|
+
err(label, "expected number", v);
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
function checkBigInt(label, bits, signed) {
|
|
402
|
+
const max = signed ? (1n << BigInt(bits - 1)) - 1n : (1n << BigInt(bits)) - 1n;
|
|
403
|
+
const min = signed ? -(1n << BigInt(bits - 1)) : 0n;
|
|
404
|
+
return (v) => {
|
|
405
|
+
let b;
|
|
406
|
+
if (typeof v === "bigint")
|
|
407
|
+
b = v;
|
|
408
|
+
else if (typeof v === "number") {
|
|
409
|
+
if (!Number.isInteger(v))
|
|
410
|
+
err(label, "expected an integer", v);
|
|
411
|
+
b = BigInt(v);
|
|
412
|
+
} else
|
|
413
|
+
return err(label, "expected bigint", v);
|
|
414
|
+
if (b < min || b > max)
|
|
415
|
+
err(label, `value out of ${label} range`, v);
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function checkString(label) {
|
|
419
|
+
return (v) => {
|
|
420
|
+
if (typeof v !== "string")
|
|
421
|
+
err(label, "expected string", v);
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
function toBigIntStrict(label, v) {
|
|
425
|
+
if (typeof v === "bigint")
|
|
426
|
+
return v;
|
|
427
|
+
if (typeof v === "number") {
|
|
428
|
+
if (!Number.isInteger(v))
|
|
429
|
+
err(label, "expected an integer value", v);
|
|
430
|
+
return BigInt(v);
|
|
431
|
+
}
|
|
432
|
+
return err(label, "expected number or bigint", v);
|
|
433
|
+
}
|
|
434
|
+
function bigIntToSafeNumber(label, b) {
|
|
435
|
+
if (b < -9007199254740991n || b > 9007199254740991n) {
|
|
436
|
+
err(label, "bigint overflows the safe-integer range when narrowing to number", b);
|
|
437
|
+
}
|
|
438
|
+
return Number(b);
|
|
439
|
+
}
|
|
440
|
+
function dateDayCodec() {
|
|
441
|
+
const label = "date32";
|
|
442
|
+
return {
|
|
443
|
+
label,
|
|
444
|
+
richToCanonical(value) {
|
|
445
|
+
if (isNullish(value))
|
|
446
|
+
return null;
|
|
447
|
+
if (value instanceof Date) {
|
|
448
|
+
const ms = value.getTime();
|
|
449
|
+
if (Number.isNaN(ms))
|
|
450
|
+
err(label, "invalid Date", value);
|
|
451
|
+
if (ms % MS_PER_DAY !== 0) {
|
|
452
|
+
return Math.floor(ms / MS_PER_DAY);
|
|
453
|
+
}
|
|
454
|
+
return ms / MS_PER_DAY;
|
|
455
|
+
}
|
|
456
|
+
if (typeof value === "number") {
|
|
457
|
+
if (!Number.isInteger(value))
|
|
458
|
+
err(label, "day-number must be an integer", value);
|
|
459
|
+
return value;
|
|
460
|
+
}
|
|
461
|
+
if (typeof value === "bigint")
|
|
462
|
+
return bigIntToSafeNumber(label, value);
|
|
463
|
+
return err(label, "expected Date, number (days), or bigint", value);
|
|
464
|
+
},
|
|
465
|
+
canonicalToRich(value) {
|
|
466
|
+
if (isNullish(value))
|
|
467
|
+
return null;
|
|
468
|
+
let days;
|
|
469
|
+
if (typeof value === "number") {
|
|
470
|
+
if (!Number.isInteger(value))
|
|
471
|
+
err(label, "canonical day-number must be an integer", value);
|
|
472
|
+
days = value;
|
|
473
|
+
} else if (typeof value === "bigint") {
|
|
474
|
+
days = bigIntToSafeNumber(label, value);
|
|
475
|
+
} else if (value instanceof Date) {
|
|
476
|
+
return value;
|
|
477
|
+
} else
|
|
478
|
+
return err(label, "expected number (days) canonical", value);
|
|
479
|
+
const ms = days * MS_PER_DAY;
|
|
480
|
+
const d = new Date(ms);
|
|
481
|
+
if (Number.isNaN(d.getTime()))
|
|
482
|
+
err(label, "day-number produces an invalid Date", value);
|
|
483
|
+
return d;
|
|
484
|
+
},
|
|
485
|
+
rawToCanonical(value) {
|
|
486
|
+
if (isNullish(value))
|
|
487
|
+
return null;
|
|
488
|
+
if (typeof value === "number") {
|
|
489
|
+
if (!Number.isInteger(value))
|
|
490
|
+
err(label, "raw day-number must be an integer", value);
|
|
491
|
+
return value;
|
|
492
|
+
}
|
|
493
|
+
if (typeof value === "bigint")
|
|
494
|
+
return bigIntToSafeNumber(label, value);
|
|
495
|
+
return err(label, "expected branded Date32 (day-number)", value);
|
|
496
|
+
},
|
|
497
|
+
canonicalToRaw(value) {
|
|
498
|
+
if (isNullish(value))
|
|
499
|
+
return null;
|
|
500
|
+
if (typeof value === "number") {
|
|
501
|
+
if (!Number.isInteger(value))
|
|
502
|
+
err(label, "canonical day-number must be an integer", value);
|
|
503
|
+
return value;
|
|
504
|
+
}
|
|
505
|
+
if (typeof value === "bigint")
|
|
506
|
+
return bigIntToSafeNumber(label, value);
|
|
507
|
+
if (value instanceof Date) {
|
|
508
|
+
const ms = value.getTime();
|
|
509
|
+
if (Number.isNaN(ms))
|
|
510
|
+
err(label, "invalid Date", value);
|
|
511
|
+
return Math.floor(ms / MS_PER_DAY);
|
|
512
|
+
}
|
|
513
|
+
return err(label, "expected number (days) canonical", value);
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
function dateMillisCodec() {
|
|
518
|
+
const label = "date64";
|
|
519
|
+
return {
|
|
520
|
+
label,
|
|
521
|
+
richToCanonical(value) {
|
|
522
|
+
if (isNullish(value))
|
|
523
|
+
return null;
|
|
524
|
+
if (value instanceof Date) {
|
|
525
|
+
const ms = value.getTime();
|
|
526
|
+
if (Number.isNaN(ms))
|
|
527
|
+
err(label, "invalid Date", value);
|
|
528
|
+
return BigInt(ms);
|
|
529
|
+
}
|
|
530
|
+
if (typeof value === "bigint")
|
|
531
|
+
return value;
|
|
532
|
+
if (typeof value === "number") {
|
|
533
|
+
if (!Number.isInteger(value))
|
|
534
|
+
err(label, "ms value must be an integer", value);
|
|
535
|
+
return BigInt(value);
|
|
536
|
+
}
|
|
537
|
+
return err(label, "expected Date, bigint (ms), or number", value);
|
|
538
|
+
},
|
|
539
|
+
canonicalToRich(value) {
|
|
540
|
+
if (isNullish(value))
|
|
541
|
+
return null;
|
|
542
|
+
if (value instanceof Date)
|
|
543
|
+
return value;
|
|
544
|
+
const ms = toBigIntStrict(label, value);
|
|
545
|
+
const n = bigIntToSafeNumber(label, ms);
|
|
546
|
+
const d = new Date(n);
|
|
547
|
+
if (Number.isNaN(d.getTime()))
|
|
548
|
+
err(label, "ms value produces an invalid Date", value);
|
|
549
|
+
return d;
|
|
550
|
+
},
|
|
551
|
+
rawToCanonical(value) {
|
|
552
|
+
if (isNullish(value))
|
|
553
|
+
return null;
|
|
554
|
+
if (value instanceof Date)
|
|
555
|
+
return err(label, "raw Date64Ms must be a bigint (ms), not a Date", value);
|
|
556
|
+
return toBigIntStrict(label, value);
|
|
557
|
+
},
|
|
558
|
+
canonicalToRaw(value) {
|
|
559
|
+
if (isNullish(value))
|
|
560
|
+
return null;
|
|
561
|
+
if (value instanceof Date)
|
|
562
|
+
return BigInt(value.getTime());
|
|
563
|
+
return toBigIntStrict(label, value);
|
|
564
|
+
}
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
function time32Codec() {
|
|
568
|
+
const label = "time32";
|
|
569
|
+
const toCanon = (value) => {
|
|
570
|
+
if (isNullish(value))
|
|
571
|
+
return null;
|
|
572
|
+
if (typeof value === "number") {
|
|
573
|
+
if (!Number.isInteger(value))
|
|
574
|
+
err(label, "time32 value must be an integer", value);
|
|
575
|
+
return value;
|
|
576
|
+
}
|
|
577
|
+
if (typeof value === "bigint")
|
|
578
|
+
return bigIntToSafeNumber(label, value);
|
|
579
|
+
return err(label, "expected number (raw time unit)", value);
|
|
580
|
+
};
|
|
581
|
+
const fromCanon = (value) => {
|
|
582
|
+
if (isNullish(value))
|
|
583
|
+
return null;
|
|
584
|
+
if (typeof value === "number")
|
|
585
|
+
return value;
|
|
586
|
+
if (typeof value === "bigint")
|
|
587
|
+
return bigIntToSafeNumber(label, value);
|
|
588
|
+
return err(label, "expected number canonical", value);
|
|
589
|
+
};
|
|
590
|
+
return {
|
|
591
|
+
label,
|
|
592
|
+
richToCanonical: toCanon,
|
|
593
|
+
canonicalToRich: fromCanon,
|
|
594
|
+
rawToCanonical: toCanon,
|
|
595
|
+
canonicalToRaw: fromCanon
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function bigIntUnitCodec(label) {
|
|
599
|
+
const conv = (value) => {
|
|
600
|
+
if (isNullish(value))
|
|
601
|
+
return null;
|
|
602
|
+
return toBigIntStrict(label, value);
|
|
603
|
+
};
|
|
604
|
+
return {
|
|
605
|
+
label,
|
|
606
|
+
richToCanonical: conv,
|
|
607
|
+
canonicalToRich: conv,
|
|
608
|
+
rawToCanonical: conv,
|
|
609
|
+
canonicalToRaw: conv
|
|
610
|
+
};
|
|
611
|
+
}
|
|
612
|
+
function decimalViewToBigInt(view) {
|
|
613
|
+
const u8 = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
614
|
+
let bi = 0n;
|
|
615
|
+
for (let i = u8.length - 1;i >= 0; i--)
|
|
616
|
+
bi = bi << 8n | BigInt(u8[i]);
|
|
617
|
+
if (u8.length > 0 && u8[u8.length - 1] & 128)
|
|
618
|
+
bi -= 1n << BigInt(u8.length * 8);
|
|
619
|
+
return bi;
|
|
620
|
+
}
|
|
621
|
+
function decimalCodec() {
|
|
622
|
+
const label = "decimal";
|
|
623
|
+
const toCanon = (value) => {
|
|
624
|
+
if (isNullish(value))
|
|
625
|
+
return null;
|
|
626
|
+
if (typeof value === "bigint")
|
|
627
|
+
return value;
|
|
628
|
+
if (typeof value === "number")
|
|
629
|
+
return toBigIntStrict(label, value);
|
|
630
|
+
if (ArrayBuffer.isView(value))
|
|
631
|
+
return decimalViewToBigInt(value);
|
|
632
|
+
return err(label, "expected bigint, number, or decimal byte view", value);
|
|
633
|
+
};
|
|
634
|
+
const fromCanon = (value) => {
|
|
635
|
+
if (isNullish(value))
|
|
636
|
+
return null;
|
|
637
|
+
return toCanon(value);
|
|
638
|
+
};
|
|
639
|
+
return {
|
|
640
|
+
label,
|
|
641
|
+
richToCanonical: toCanon,
|
|
642
|
+
canonicalToRich: fromCanon,
|
|
643
|
+
rawToCanonical: toCanon,
|
|
644
|
+
canonicalToRaw: fromCanon
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
function structCodec(type) {
|
|
648
|
+
const children = type.children;
|
|
649
|
+
const childCodecs = children.map((c) => ({ name: c.name, codec: codecFor(c.type) }));
|
|
650
|
+
const label = "struct";
|
|
651
|
+
return {
|
|
652
|
+
label,
|
|
653
|
+
richToCanonical(value) {
|
|
654
|
+
if (isNullish(value))
|
|
655
|
+
return null;
|
|
656
|
+
if (typeof value !== "object")
|
|
657
|
+
err(label, "expected an object", value);
|
|
658
|
+
const obj = value;
|
|
659
|
+
const out = {};
|
|
660
|
+
for (const { name, codec } of childCodecs) {
|
|
661
|
+
out[name] = codec.richToCanonical(obj[name] ?? null);
|
|
662
|
+
}
|
|
663
|
+
return out;
|
|
664
|
+
},
|
|
665
|
+
canonicalToRich(value) {
|
|
666
|
+
if (isNullish(value))
|
|
667
|
+
return null;
|
|
668
|
+
if (typeof value !== "object")
|
|
669
|
+
err(label, "expected an object", value);
|
|
670
|
+
const obj = value;
|
|
671
|
+
const out = {};
|
|
672
|
+
for (const { name, codec } of childCodecs) {
|
|
673
|
+
out[name] = codec.canonicalToRich(obj[name] ?? null);
|
|
674
|
+
}
|
|
675
|
+
return out;
|
|
676
|
+
},
|
|
677
|
+
rawToCanonical(value) {
|
|
678
|
+
if (isNullish(value))
|
|
679
|
+
return null;
|
|
680
|
+
if (typeof value !== "object")
|
|
681
|
+
err(label, "expected an object", value);
|
|
682
|
+
const obj = value;
|
|
683
|
+
const out = {};
|
|
684
|
+
for (const { name, codec } of childCodecs) {
|
|
685
|
+
out[name] = codec.rawToCanonical(obj[name] ?? null);
|
|
686
|
+
}
|
|
687
|
+
return out;
|
|
688
|
+
},
|
|
689
|
+
canonicalToRaw(value) {
|
|
690
|
+
if (isNullish(value))
|
|
691
|
+
return null;
|
|
692
|
+
if (typeof value !== "object")
|
|
693
|
+
err(label, "expected an object", value);
|
|
694
|
+
const obj = value;
|
|
695
|
+
const out = {};
|
|
696
|
+
for (const { name, codec } of childCodecs) {
|
|
697
|
+
out[name] = codec.canonicalToRaw(obj[name] ?? null);
|
|
698
|
+
}
|
|
699
|
+
return out;
|
|
700
|
+
}
|
|
701
|
+
};
|
|
702
|
+
}
|
|
703
|
+
function listCodec(type) {
|
|
704
|
+
const childField = type.children?.[0];
|
|
705
|
+
if (!childField)
|
|
706
|
+
throw new Error("codec[list]: list type has no child field");
|
|
707
|
+
const child = codecFor(childField.type);
|
|
708
|
+
const label = "list";
|
|
709
|
+
const toArray = (value) => {
|
|
710
|
+
if (Array.isArray(value))
|
|
711
|
+
return value;
|
|
712
|
+
if (value != null && typeof value[Symbol.iterator] === "function") {
|
|
713
|
+
return Array.from(value);
|
|
714
|
+
}
|
|
715
|
+
return err(label, "expected an array or iterable", value);
|
|
716
|
+
};
|
|
717
|
+
return {
|
|
718
|
+
label,
|
|
719
|
+
richToCanonical(value) {
|
|
720
|
+
if (isNullish(value))
|
|
721
|
+
return null;
|
|
722
|
+
return toArray(value).map((v) => child.richToCanonical(v));
|
|
723
|
+
},
|
|
724
|
+
canonicalToRich(value) {
|
|
725
|
+
if (isNullish(value))
|
|
726
|
+
return null;
|
|
727
|
+
return toArray(value).map((v) => child.canonicalToRich(v));
|
|
728
|
+
},
|
|
729
|
+
rawToCanonical(value) {
|
|
730
|
+
if (isNullish(value))
|
|
731
|
+
return null;
|
|
732
|
+
return toArray(value).map((v) => child.rawToCanonical(v));
|
|
733
|
+
},
|
|
734
|
+
canonicalToRaw(value) {
|
|
735
|
+
if (isNullish(value))
|
|
736
|
+
return null;
|
|
737
|
+
return toArray(value).map((v) => child.canonicalToRaw(v));
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
function mapCodec(type) {
|
|
742
|
+
const entries = type.children?.[0];
|
|
743
|
+
const entryChildren = entries?.type?.children;
|
|
744
|
+
if (!entryChildren || entryChildren.length < 2) {
|
|
745
|
+
throw new Error("codec[map]: map type has no key/value entry fields");
|
|
746
|
+
}
|
|
747
|
+
const keyCodec = codecFor(entryChildren[0].type);
|
|
748
|
+
const valueCodec = codecFor(entryChildren[1].type);
|
|
749
|
+
const label = "map";
|
|
750
|
+
const toPairs = (value) => {
|
|
751
|
+
if (Array.isArray(value))
|
|
752
|
+
return value;
|
|
753
|
+
if (value instanceof Map)
|
|
754
|
+
return Array.from(value.entries());
|
|
755
|
+
if (value != null && typeof value[Symbol.iterator] === "function") {
|
|
756
|
+
return Array.from(value);
|
|
757
|
+
}
|
|
758
|
+
if (value != null && typeof value === "object") {
|
|
759
|
+
return Object.entries(value);
|
|
760
|
+
}
|
|
761
|
+
return err(label, "expected Map, array of pairs, or object", value);
|
|
762
|
+
};
|
|
763
|
+
return {
|
|
764
|
+
label,
|
|
765
|
+
richToCanonical(value) {
|
|
766
|
+
if (isNullish(value))
|
|
767
|
+
return null;
|
|
768
|
+
return toPairs(value).map(([k, v]) => [
|
|
769
|
+
keyCodec.richToCanonical(k),
|
|
770
|
+
valueCodec.richToCanonical(v)
|
|
771
|
+
]);
|
|
772
|
+
},
|
|
773
|
+
canonicalToRich(value) {
|
|
774
|
+
if (isNullish(value))
|
|
775
|
+
return null;
|
|
776
|
+
return toPairs(value).map(([k, v]) => [
|
|
777
|
+
keyCodec.canonicalToRich(k),
|
|
778
|
+
valueCodec.canonicalToRich(v)
|
|
779
|
+
]);
|
|
780
|
+
},
|
|
781
|
+
rawToCanonical(value) {
|
|
782
|
+
if (isNullish(value))
|
|
783
|
+
return null;
|
|
784
|
+
return toPairs(value).map(([k, v]) => [
|
|
785
|
+
keyCodec.rawToCanonical(k),
|
|
786
|
+
valueCodec.rawToCanonical(v)
|
|
787
|
+
]);
|
|
788
|
+
},
|
|
789
|
+
canonicalToRaw(value) {
|
|
790
|
+
if (isNullish(value))
|
|
791
|
+
return null;
|
|
792
|
+
return toPairs(value).map(([k, v]) => [
|
|
793
|
+
keyCodec.canonicalToRaw(k),
|
|
794
|
+
valueCodec.canonicalToRaw(v)
|
|
795
|
+
]);
|
|
796
|
+
}
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
function dictionaryCodec(type) {
|
|
800
|
+
const valueType = type.dictionary;
|
|
801
|
+
if (!valueType)
|
|
802
|
+
throw new Error("codec[dictionary]: missing dictionary value type");
|
|
803
|
+
const inner = codecFor(valueType);
|
|
804
|
+
return {
|
|
805
|
+
label: `dictionary<${inner.label}>`,
|
|
806
|
+
richToCanonical: (v) => inner.richToCanonical(v),
|
|
807
|
+
canonicalToRich: (v) => inner.canonicalToRich(v),
|
|
808
|
+
rawToCanonical: (v) => inner.rawToCanonical(v),
|
|
809
|
+
canonicalToRaw: (v) => inner.canonicalToRaw(v)
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
var INT8 = identity("int8", checkIntNumber("int8", -128, 127));
|
|
813
|
+
var INT16 = identity("int16", checkIntNumber("int16", -32768, 32767));
|
|
814
|
+
var INT32 = identity("int32", checkIntNumber("int32", -2147483648, 2147483647));
|
|
815
|
+
var UINT8 = identity("uint8", checkIntNumber("uint8", 0, 255));
|
|
816
|
+
var UINT16 = identity("uint16", checkIntNumber("uint16", 0, 65535));
|
|
817
|
+
var UINT32 = identity("uint32", checkIntNumber("uint32", 0, 4294967295));
|
|
818
|
+
var INT64 = identity("int64", checkBigInt("int64", 64, true));
|
|
819
|
+
var UINT64 = identity("uint64", checkBigInt("uint64", 64, false));
|
|
820
|
+
var FLOAT = identity("float", checkFloat("float"));
|
|
821
|
+
var BOOL = identity("bool", checkBoolean("bool"));
|
|
822
|
+
var UTF8 = {
|
|
823
|
+
label: "utf8",
|
|
824
|
+
richToCanonical(value) {
|
|
825
|
+
if (isNullish(value))
|
|
826
|
+
return null;
|
|
827
|
+
return typeof value === "string" ? value : String(value);
|
|
828
|
+
},
|
|
829
|
+
canonicalToRich(value) {
|
|
830
|
+
if (isNullish(value))
|
|
831
|
+
return null;
|
|
832
|
+
checkString("utf8")(value);
|
|
833
|
+
return value;
|
|
834
|
+
},
|
|
835
|
+
rawToCanonical(value) {
|
|
836
|
+
if (isNullish(value))
|
|
837
|
+
return null;
|
|
838
|
+
return typeof value === "string" ? value : String(value);
|
|
839
|
+
},
|
|
840
|
+
canonicalToRaw(value) {
|
|
841
|
+
if (isNullish(value))
|
|
842
|
+
return null;
|
|
843
|
+
checkString("utf8")(value);
|
|
844
|
+
return value;
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
function toCanonBytes(label, fixedWidth) {
|
|
848
|
+
return (value) => {
|
|
849
|
+
if (isNullish(value))
|
|
850
|
+
return null;
|
|
851
|
+
let u8;
|
|
852
|
+
if (value instanceof Uint8Array)
|
|
853
|
+
u8 = value;
|
|
854
|
+
else if (ArrayBuffer.isView(value)) {
|
|
855
|
+
const v = value;
|
|
856
|
+
u8 = new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
|
|
857
|
+
} else
|
|
858
|
+
return err(label, "expected Uint8Array", value);
|
|
859
|
+
if (fixedWidth != null && u8.length !== fixedWidth) {
|
|
860
|
+
err(label, `expected exactly ${fixedWidth} bytes`, value);
|
|
861
|
+
}
|
|
862
|
+
return u8;
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
function bytesCodec(label, fixedWidth) {
|
|
866
|
+
const conv = toCanonBytes(label, fixedWidth);
|
|
867
|
+
return {
|
|
868
|
+
label,
|
|
869
|
+
richToCanonical: conv,
|
|
870
|
+
canonicalToRich: conv,
|
|
871
|
+
rawToCanonical: conv,
|
|
872
|
+
canonicalToRaw: conv
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
var BINARY = bytesCodec("binary");
|
|
876
|
+
var NULL_CODEC = {
|
|
877
|
+
label: "null",
|
|
878
|
+
richToCanonical: () => null,
|
|
879
|
+
canonicalToRich: () => null,
|
|
880
|
+
rawToCanonical: () => null,
|
|
881
|
+
canonicalToRaw: () => null
|
|
882
|
+
};
|
|
883
|
+
function codecFor(type) {
|
|
884
|
+
switch (type.typeId) {
|
|
885
|
+
case TypeId.Null:
|
|
886
|
+
return NULL_CODEC;
|
|
887
|
+
case TypeId.Bool:
|
|
888
|
+
return BOOL;
|
|
889
|
+
case TypeId.Int: {
|
|
890
|
+
const bw = type.bitWidth ?? 32;
|
|
891
|
+
const signed = type.isSigned ?? type.signed ?? true;
|
|
892
|
+
if (bw === 64)
|
|
893
|
+
return signed ? INT64 : UINT64;
|
|
894
|
+
if (signed) {
|
|
895
|
+
if (bw === 8)
|
|
896
|
+
return INT8;
|
|
897
|
+
if (bw === 16)
|
|
898
|
+
return INT16;
|
|
899
|
+
return INT32;
|
|
900
|
+
}
|
|
901
|
+
if (bw === 8)
|
|
902
|
+
return UINT8;
|
|
903
|
+
if (bw === 16)
|
|
904
|
+
return UINT16;
|
|
905
|
+
return UINT32;
|
|
906
|
+
}
|
|
907
|
+
case TypeId.Float:
|
|
908
|
+
return FLOAT;
|
|
909
|
+
case TypeId.Utf8:
|
|
910
|
+
case TypeId.LargeUtf8:
|
|
911
|
+
return UTF8;
|
|
912
|
+
case TypeId.Binary:
|
|
913
|
+
case TypeId.LargeBinary:
|
|
914
|
+
return BINARY;
|
|
915
|
+
case TypeId.FixedSizeBinary:
|
|
916
|
+
return bytesCodec("fixedSizeBinary", type.byteWidth ?? type.stride);
|
|
917
|
+
case TypeId.Decimal:
|
|
918
|
+
return decimalCodec();
|
|
919
|
+
case TypeId.Date:
|
|
920
|
+
return type.unit === 0 ? dateDayCodec() : dateMillisCodec();
|
|
921
|
+
case TypeId.Time:
|
|
922
|
+
return (type.bitWidth ?? 32) === 64 ? bigIntUnitCodec("time64") : time32Codec();
|
|
923
|
+
case TypeId.Timestamp:
|
|
924
|
+
return bigIntUnitCodec("timestamp");
|
|
925
|
+
case TypeId.Duration:
|
|
926
|
+
return bigIntUnitCodec("duration");
|
|
927
|
+
case TypeId.Struct:
|
|
928
|
+
return structCodec(type);
|
|
929
|
+
case TypeId.Union:
|
|
930
|
+
return identity("union", () => {});
|
|
931
|
+
case TypeId.List:
|
|
932
|
+
case TypeId.FixedSizeList:
|
|
933
|
+
return listCodec(type);
|
|
934
|
+
case TypeId.Map:
|
|
935
|
+
return mapCodec(type);
|
|
936
|
+
case TypeId.Dictionary:
|
|
937
|
+
return dictionaryCodec(type);
|
|
938
|
+
case TypeId.Interval:
|
|
939
|
+
return identity("interval", () => {});
|
|
940
|
+
default:
|
|
941
|
+
return identity(`type#${type.typeId}`, () => {});
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
// src/arrow/impl-arrowjs/canonical.ts
|
|
946
|
+
import {
|
|
947
|
+
DataType as DataType2,
|
|
948
|
+
DateUnit as DateUnit2,
|
|
949
|
+
makeData as makeData2,
|
|
950
|
+
vectorFromArray
|
|
951
|
+
} from "@query-farm/apache-arrow";
|
|
952
|
+
function writeCanonicalColumn(type, canonical) {
|
|
953
|
+
return buildColumnData(canonical, type);
|
|
954
|
+
}
|
|
955
|
+
function buildColumnData(values, type) {
|
|
956
|
+
if (DataType2.isList(type))
|
|
957
|
+
return buildListData(values, type);
|
|
958
|
+
if (DataType2.isMap(type))
|
|
959
|
+
return buildMapData(values, type);
|
|
960
|
+
if (DataType2.isStruct(type))
|
|
961
|
+
return buildStructData(values, type);
|
|
962
|
+
if (DataType2.isDecimal(type))
|
|
963
|
+
return buildDecimalData(values, type);
|
|
964
|
+
if (DataType2.isDate(type) || DataType2.isTime(type) || DataType2.isTimestamp(type) || DataType2.isDuration(type)) {
|
|
965
|
+
const bitWidth = dateTimeBitWidth(type);
|
|
966
|
+
if (bitWidth === 64)
|
|
967
|
+
return buildBigIntData(values, type);
|
|
968
|
+
return buildInt32Data(values, type);
|
|
969
|
+
}
|
|
970
|
+
if (DataType2.isInt(type) && type.bitWidth === 64) {
|
|
971
|
+
return buildBigIntData(values, type);
|
|
972
|
+
}
|
|
973
|
+
return vectorFromArray(values, type).data[0];
|
|
974
|
+
}
|
|
975
|
+
function dateTimeBitWidth(type) {
|
|
976
|
+
if (DataType2.isDate(type))
|
|
977
|
+
return type.unit === DateUnit2.DAY ? 32 : 64;
|
|
978
|
+
if (DataType2.isTime(type))
|
|
979
|
+
return type.bitWidth ?? 32;
|
|
980
|
+
return 64;
|
|
981
|
+
}
|
|
982
|
+
function buildInt32Data(values, type) {
|
|
983
|
+
const length = values.length;
|
|
984
|
+
const buf = new Int32Array(length);
|
|
985
|
+
const nullBitmap = new Uint8Array(Math.ceil(length / 8));
|
|
986
|
+
let nullCount = 0;
|
|
987
|
+
for (let i = 0;i < length; i++) {
|
|
988
|
+
const v = values[i];
|
|
989
|
+
if (v === null || v === undefined) {
|
|
990
|
+
nullCount++;
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
994
|
+
buf[i] = typeof v === "bigint" ? Number(v) : v;
|
|
995
|
+
}
|
|
996
|
+
return makeData2({
|
|
997
|
+
type,
|
|
998
|
+
length,
|
|
999
|
+
nullBitmap: nullCount > 0 ? nullBitmap : undefined,
|
|
1000
|
+
data: buf,
|
|
1001
|
+
nullCount
|
|
1002
|
+
});
|
|
1003
|
+
}
|
|
1004
|
+
function buildBigIntData(values, type) {
|
|
1005
|
+
const length = values.length;
|
|
1006
|
+
const bigBuf = new BigInt64Array(length);
|
|
1007
|
+
const nullBitmap = new Uint8Array(Math.ceil(length / 8));
|
|
1008
|
+
let nullCount = 0;
|
|
1009
|
+
for (let i = 0;i < length; i++) {
|
|
1010
|
+
const v = values[i];
|
|
1011
|
+
if (v === null || v === undefined) {
|
|
1012
|
+
nullCount++;
|
|
1013
|
+
continue;
|
|
1014
|
+
}
|
|
1015
|
+
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
1016
|
+
bigBuf[i] = typeof v === "bigint" ? v : BigInt(v);
|
|
1017
|
+
}
|
|
1018
|
+
const data = new Int32Array(bigBuf.buffer);
|
|
1019
|
+
return makeData2({
|
|
1020
|
+
type,
|
|
1021
|
+
length,
|
|
1022
|
+
nullBitmap: nullCount > 0 ? nullBitmap : undefined,
|
|
1023
|
+
data,
|
|
1024
|
+
nullCount
|
|
1025
|
+
});
|
|
1026
|
+
}
|
|
1027
|
+
function buildDecimalData(values, type) {
|
|
1028
|
+
const byteWidth = type.byteWidth ?? (type.bitWidth ? type.bitWidth / 8 : 16);
|
|
1029
|
+
const length = values.length;
|
|
1030
|
+
const buf = new Uint8Array(length * byteWidth);
|
|
1031
|
+
const nullBitmap = new Uint8Array(Math.ceil(length / 8));
|
|
1032
|
+
let nullCount = 0;
|
|
1033
|
+
for (let i = 0;i < length; i++) {
|
|
1034
|
+
const val = values[i];
|
|
1035
|
+
if (val === null || val === undefined) {
|
|
1036
|
+
nullCount++;
|
|
1037
|
+
continue;
|
|
1038
|
+
}
|
|
1039
|
+
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
1040
|
+
let bytes;
|
|
1041
|
+
if (val instanceof Uint8Array) {
|
|
1042
|
+
bytes = val;
|
|
1043
|
+
} else if (ArrayBuffer.isView(val)) {
|
|
1044
|
+
const view = val;
|
|
1045
|
+
bytes = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
1046
|
+
} else {
|
|
1047
|
+
bytes = bigIntToDecimalBytes(toBig(val), byteWidth);
|
|
1048
|
+
}
|
|
1049
|
+
buf.set(bytes.subarray(0, byteWidth), i * byteWidth);
|
|
1050
|
+
}
|
|
1051
|
+
return makeData2({
|
|
1052
|
+
type,
|
|
1053
|
+
length,
|
|
1054
|
+
nullBitmap: nullCount > 0 ? nullBitmap : undefined,
|
|
1055
|
+
data: new Uint32Array(buf.buffer, buf.byteOffset, buf.byteLength / 4),
|
|
1056
|
+
nullCount
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
function toBig(v) {
|
|
1060
|
+
return typeof v === "bigint" ? v : BigInt(Math.trunc(Number(v)));
|
|
1061
|
+
}
|
|
1062
|
+
function bigIntToDecimalBytes(value, byteWidth) {
|
|
1063
|
+
const bytes = new Uint8Array(byteWidth);
|
|
1064
|
+
let v = value;
|
|
1065
|
+
if (v < 0n)
|
|
1066
|
+
v = (1n << BigInt(byteWidth * 8)) + v;
|
|
1067
|
+
for (let i = 0;i < byteWidth; i++) {
|
|
1068
|
+
bytes[i] = Number(v & 0xffn);
|
|
1069
|
+
v >>= 8n;
|
|
1070
|
+
}
|
|
1071
|
+
return bytes;
|
|
1072
|
+
}
|
|
1073
|
+
function buildListData(values, listType) {
|
|
1074
|
+
const childField = listType.children[0];
|
|
1075
|
+
const numRows = values.length;
|
|
1076
|
+
const offsets = new Int32Array(numRows + 1);
|
|
1077
|
+
const allItems = [];
|
|
1078
|
+
const nullBitmap = new Uint8Array(Math.ceil(numRows / 8));
|
|
1079
|
+
let nullCount = 0;
|
|
1080
|
+
for (let i = 0;i < numRows; i++) {
|
|
1081
|
+
offsets[i] = allItems.length;
|
|
1082
|
+
const row = values[i];
|
|
1083
|
+
if (row == null) {
|
|
1084
|
+
nullCount++;
|
|
1085
|
+
} else {
|
|
1086
|
+
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
1087
|
+
const items = Array.isArray(row) ? row : typeof row[Symbol.iterator] === "function" ? Array.from(row) : null;
|
|
1088
|
+
if (items)
|
|
1089
|
+
for (const item of items)
|
|
1090
|
+
allItems.push(item);
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
offsets[numRows] = allItems.length;
|
|
1094
|
+
const childData = allItems.length > 0 ? buildColumnData(allItems, childField.type) : emptyDataForType(childField.type);
|
|
1095
|
+
return makeData2({
|
|
1096
|
+
type: listType,
|
|
1097
|
+
length: numRows,
|
|
1098
|
+
nullCount,
|
|
1099
|
+
nullBitmap: nullCount > 0 ? nullBitmap : undefined,
|
|
1100
|
+
child: childData,
|
|
1101
|
+
offset: 0,
|
|
1102
|
+
valueOffsets: offsets
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
function buildMapData(values, mapType) {
|
|
1106
|
+
const numRows = values.length;
|
|
1107
|
+
const entriesField = mapType.children[0];
|
|
1108
|
+
const keyField = entriesField.type.children[0];
|
|
1109
|
+
const valueField = entriesField.type.children[1];
|
|
1110
|
+
const offsets = new Int32Array(numRows + 1);
|
|
1111
|
+
const allKeys = [];
|
|
1112
|
+
const allValues = [];
|
|
1113
|
+
const nullBitmap = new Uint8Array(Math.ceil(numRows / 8));
|
|
1114
|
+
let nullCount = 0;
|
|
1115
|
+
for (let i = 0;i < numRows; i++) {
|
|
1116
|
+
offsets[i] = allKeys.length;
|
|
1117
|
+
const row = values[i];
|
|
1118
|
+
if (row == null) {
|
|
1119
|
+
nullCount++;
|
|
1120
|
+
} else {
|
|
1121
|
+
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
1122
|
+
const pairs = Array.isArray(row) ? row : row instanceof Map ? Array.from(row.entries()) : typeof row[Symbol.iterator] === "function" ? Array.from(row) : typeof row === "object" ? Object.entries(row) : [];
|
|
1123
|
+
for (const [k, v] of pairs) {
|
|
1124
|
+
allKeys.push(k);
|
|
1125
|
+
allValues.push(v);
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1129
|
+
offsets[numRows] = allKeys.length;
|
|
1130
|
+
const keyData = allKeys.length > 0 ? buildColumnData(allKeys, keyField.type) : emptyDataForType(keyField.type);
|
|
1131
|
+
const valueData = allValues.length > 0 ? buildColumnData(allValues, valueField.type) : emptyDataForType(valueField.type);
|
|
1132
|
+
const entriesData = makeData2({
|
|
1133
|
+
type: entriesField.type,
|
|
1134
|
+
length: allKeys.length,
|
|
1135
|
+
children: [keyData, valueData],
|
|
1136
|
+
nullCount: 0
|
|
1137
|
+
});
|
|
1138
|
+
return makeData2({
|
|
1139
|
+
type: mapType,
|
|
1140
|
+
length: numRows,
|
|
1141
|
+
nullCount,
|
|
1142
|
+
nullBitmap: nullCount > 0 ? nullBitmap : undefined,
|
|
1143
|
+
child: entriesData,
|
|
1144
|
+
offset: 0,
|
|
1145
|
+
valueOffsets: offsets
|
|
1146
|
+
});
|
|
1147
|
+
}
|
|
1148
|
+
function buildStructData(values, structType) {
|
|
1149
|
+
const childFields = structType.children;
|
|
1150
|
+
const numRows = values.length;
|
|
1151
|
+
const nullBitmap = new Uint8Array(Math.ceil(numRows / 8));
|
|
1152
|
+
let nullCount = 0;
|
|
1153
|
+
const childArrays = childFields.map(() => []);
|
|
1154
|
+
for (let i = 0;i < numRows; i++) {
|
|
1155
|
+
const row = values[i];
|
|
1156
|
+
if (row == null) {
|
|
1157
|
+
nullCount++;
|
|
1158
|
+
for (let c = 0;c < childFields.length; c++)
|
|
1159
|
+
childArrays[c].push(null);
|
|
1160
|
+
} else {
|
|
1161
|
+
nullBitmap[i >> 3] |= 1 << (i & 7);
|
|
1162
|
+
for (let c = 0;c < childFields.length; c++) {
|
|
1163
|
+
const name = childFields[c].name;
|
|
1164
|
+
childArrays[c].push(row[name] ?? row[c] ?? null);
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
const children = childFields.map((cf, idx) => buildColumnData(childArrays[idx], cf.type));
|
|
1169
|
+
return makeData2({
|
|
1170
|
+
type: structType,
|
|
1171
|
+
length: numRows,
|
|
1172
|
+
nullCount,
|
|
1173
|
+
nullBitmap: nullCount > 0 ? nullBitmap : undefined,
|
|
1174
|
+
children
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
function emptyDataForType(type) {
|
|
1178
|
+
if (DataType2.isList(type)) {
|
|
1179
|
+
return makeData2({
|
|
1180
|
+
type,
|
|
1181
|
+
length: 0,
|
|
1182
|
+
nullCount: 0,
|
|
1183
|
+
child: emptyDataForType(type.children[0].type),
|
|
1184
|
+
valueOffsets: new Int32Array([0])
|
|
1185
|
+
});
|
|
1186
|
+
}
|
|
1187
|
+
if (DataType2.isMap(type)) {
|
|
1188
|
+
return makeData2({
|
|
1189
|
+
type,
|
|
1190
|
+
length: 0,
|
|
1191
|
+
nullCount: 0,
|
|
1192
|
+
child: emptyDataForType(type.children[0].type),
|
|
1193
|
+
valueOffsets: new Int32Array([0])
|
|
1194
|
+
});
|
|
1195
|
+
}
|
|
1196
|
+
if (DataType2.isStruct(type)) {
|
|
1197
|
+
const children = type.children.map((cf) => emptyDataForType(cf.type));
|
|
1198
|
+
return makeData2({ type, length: 0, nullCount: 0, children });
|
|
1199
|
+
}
|
|
1200
|
+
return makeData2({ type, length: 0, nullCount: 0 });
|
|
1201
|
+
}
|
|
1202
|
+
function readCanonicalValue(type, column, index) {
|
|
1203
|
+
const col = column;
|
|
1204
|
+
const data = col?.data?.[0];
|
|
1205
|
+
return readFromData(type, col, data, index);
|
|
1206
|
+
}
|
|
1207
|
+
function isValid(col, data, index) {
|
|
1208
|
+
if (typeof col?.isValid === "function")
|
|
1209
|
+
return col.isValid(index);
|
|
1210
|
+
const bitmap = data?.nullBitmap;
|
|
1211
|
+
if (bitmap && bitmap.length > 0) {
|
|
1212
|
+
return (bitmap[index >> 3] >> (index & 7) & 1) === 1;
|
|
1213
|
+
}
|
|
1214
|
+
return true;
|
|
1215
|
+
}
|
|
1216
|
+
function readFromData(type, col, data, index) {
|
|
1217
|
+
if (!isValid(col, data, index))
|
|
1218
|
+
return null;
|
|
1219
|
+
const tid = type.typeId;
|
|
1220
|
+
switch (tid) {
|
|
1221
|
+
case 1:
|
|
1222
|
+
return null;
|
|
1223
|
+
case 6:
|
|
1224
|
+
return col.get(index);
|
|
1225
|
+
case 2: {
|
|
1226
|
+
const bw = type.bitWidth ?? 32;
|
|
1227
|
+
const v = data?.values?.[index];
|
|
1228
|
+
if (bw === 64)
|
|
1229
|
+
return typeof v === "bigint" ? v : BigInt(v);
|
|
1230
|
+
return Number(v);
|
|
1231
|
+
}
|
|
1232
|
+
case 3:
|
|
1233
|
+
return Number(data?.values?.[index]);
|
|
1234
|
+
case 5:
|
|
1235
|
+
case 20:
|
|
1236
|
+
return String(col.get(index));
|
|
1237
|
+
case 4:
|
|
1238
|
+
case 19:
|
|
1239
|
+
case 15:
|
|
1240
|
+
return toUint8(col.get(index));
|
|
1241
|
+
case 7:
|
|
1242
|
+
return decimalToBigInt(type, data, index);
|
|
1243
|
+
case 8: {
|
|
1244
|
+
const v = data?.values?.[index];
|
|
1245
|
+
if (type.unit === DateUnit2.DAY)
|
|
1246
|
+
return Number(v);
|
|
1247
|
+
return typeof v === "bigint" ? v : BigInt(v);
|
|
1248
|
+
}
|
|
1249
|
+
case 9: {
|
|
1250
|
+
const v = data?.values?.[index];
|
|
1251
|
+
const bw = type.bitWidth ?? 32;
|
|
1252
|
+
if (bw === 64)
|
|
1253
|
+
return typeof v === "bigint" ? v : BigInt(v);
|
|
1254
|
+
return Number(v);
|
|
1255
|
+
}
|
|
1256
|
+
case 10:
|
|
1257
|
+
case 18: {
|
|
1258
|
+
const v = data?.values?.[index];
|
|
1259
|
+
return typeof v === "bigint" ? v : BigInt(v);
|
|
1260
|
+
}
|
|
1261
|
+
case 13:
|
|
1262
|
+
return readStruct(type, col, index);
|
|
1263
|
+
case 14:
|
|
1264
|
+
return readUnion(type, col, data, index);
|
|
1265
|
+
case 12:
|
|
1266
|
+
case 16:
|
|
1267
|
+
return readList(type, col, data, index);
|
|
1268
|
+
case 17:
|
|
1269
|
+
return readMap(type, col, data, index);
|
|
1270
|
+
case -1:
|
|
1271
|
+
return readDictionary(type, col, data, index);
|
|
1272
|
+
default:
|
|
1273
|
+
return col.get(index);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
function toUint8(v) {
|
|
1277
|
+
if (v == null)
|
|
1278
|
+
return null;
|
|
1279
|
+
if (v instanceof Uint8Array)
|
|
1280
|
+
return v;
|
|
1281
|
+
if (ArrayBuffer.isView(v)) {
|
|
1282
|
+
const view = v;
|
|
1283
|
+
return new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
|
|
1284
|
+
}
|
|
1285
|
+
return v;
|
|
1286
|
+
}
|
|
1287
|
+
function decimalToBigInt(type, data, index) {
|
|
1288
|
+
const byteWidth = type.byteWidth ?? (type.bitWidth ? type.bitWidth / 8 : 16);
|
|
1289
|
+
const u32 = data.values;
|
|
1290
|
+
const wordsPerElem = byteWidth / 4;
|
|
1291
|
+
const start = index * wordsPerElem;
|
|
1292
|
+
const u8 = new Uint8Array(byteWidth);
|
|
1293
|
+
for (let w = 0;w < wordsPerElem; w++) {
|
|
1294
|
+
const word = u32[start + w] >>> 0;
|
|
1295
|
+
u8[w * 4] = word & 255;
|
|
1296
|
+
u8[w * 4 + 1] = word >>> 8 & 255;
|
|
1297
|
+
u8[w * 4 + 2] = word >>> 16 & 255;
|
|
1298
|
+
u8[w * 4 + 3] = word >>> 24 & 255;
|
|
1299
|
+
}
|
|
1300
|
+
return decimalBytesToBigInt(u8);
|
|
1301
|
+
}
|
|
1302
|
+
function decimalBytesToBigInt(u8) {
|
|
1303
|
+
let bi = 0n;
|
|
1304
|
+
for (let i = u8.length - 1;i >= 0; i--)
|
|
1305
|
+
bi = bi << 8n | BigInt(u8[i]);
|
|
1306
|
+
if (u8[u8.length - 1] & 128)
|
|
1307
|
+
bi -= 1n << BigInt(u8.length * 8);
|
|
1308
|
+
return bi;
|
|
1309
|
+
}
|
|
1310
|
+
function readStruct(type, col, index) {
|
|
1311
|
+
const children = type.children;
|
|
1312
|
+
const out = {};
|
|
1313
|
+
for (let c = 0;c < children.length; c++) {
|
|
1314
|
+
const cf = children[c];
|
|
1315
|
+
const childVec = typeof col.getChildAt === "function" ? col.getChildAt(c) : col.children?.[c];
|
|
1316
|
+
if (!childVec) {
|
|
1317
|
+
out[cf.name] = null;
|
|
1318
|
+
continue;
|
|
1319
|
+
}
|
|
1320
|
+
out[cf.name] = readCanonicalValue(cf.type, childVec, index);
|
|
1321
|
+
}
|
|
1322
|
+
return out;
|
|
1323
|
+
}
|
|
1324
|
+
function readUnion(type, col, data, index) {
|
|
1325
|
+
const children = type.children;
|
|
1326
|
+
const typeIds = data?.typeIds;
|
|
1327
|
+
const tcode = typeIds ? typeIds[index] : children.length > 0 ? 0 : -1;
|
|
1328
|
+
const map2 = type.typeIdToChildIndex;
|
|
1329
|
+
const childIdx = map2 && map2[tcode] !== undefined ? map2[tcode] : tcode;
|
|
1330
|
+
const childField = children[childIdx];
|
|
1331
|
+
if (!childField)
|
|
1332
|
+
return { tag: null, value: null };
|
|
1333
|
+
const offsets = data?.valueOffsets;
|
|
1334
|
+
const childRow = offsets ? offsets[index] : index;
|
|
1335
|
+
const childVec = typeof col.getChildAt === "function" ? col.getChildAt(childIdx) : col.children?.[childIdx];
|
|
1336
|
+
const value = childVec ? readCanonicalValue(childField.type, childVec, childRow) : null;
|
|
1337
|
+
return { tag: childField.name, value };
|
|
1338
|
+
}
|
|
1339
|
+
function readList(type, col, data, index) {
|
|
1340
|
+
const childField = type.children[0];
|
|
1341
|
+
const childVec = typeof col.getChildAt === "function" ? col.getChildAt(0) : col.children?.[0];
|
|
1342
|
+
const offsets = data?.valueOffsets;
|
|
1343
|
+
let start, end;
|
|
1344
|
+
if (offsets) {
|
|
1345
|
+
start = offsets[index];
|
|
1346
|
+
end = offsets[index + 1];
|
|
1347
|
+
} else {
|
|
1348
|
+
const listSize = type.listSize ?? 0;
|
|
1349
|
+
start = index * listSize;
|
|
1350
|
+
end = start + listSize;
|
|
1351
|
+
}
|
|
1352
|
+
const out = [];
|
|
1353
|
+
for (let i = start;i < end; i++) {
|
|
1354
|
+
out.push(readCanonicalValue(childField.type, childVec, i));
|
|
1355
|
+
}
|
|
1356
|
+
return out;
|
|
1357
|
+
}
|
|
1358
|
+
function readMap(type, col, data, index) {
|
|
1359
|
+
const entriesField = type.children[0];
|
|
1360
|
+
const keyField = entriesField.type.children[0];
|
|
1361
|
+
const valueField = entriesField.type.children[1];
|
|
1362
|
+
const offsets = data?.valueOffsets;
|
|
1363
|
+
const entriesVec = typeof col.getChildAt === "function" ? col.getChildAt(0) : col.children?.[0];
|
|
1364
|
+
const keyVec = entriesVec && (typeof entriesVec.getChildAt === "function" ? entriesVec.getChildAt(0) : entriesVec.children?.[0]);
|
|
1365
|
+
const valueVec = entriesVec && (typeof entriesVec.getChildAt === "function" ? entriesVec.getChildAt(1) : entriesVec.children?.[1]);
|
|
1366
|
+
const start = offsets ? offsets[index] : 0;
|
|
1367
|
+
const end = offsets ? offsets[index + 1] : 0;
|
|
1368
|
+
const out = [];
|
|
1369
|
+
for (let i = start;i < end; i++) {
|
|
1370
|
+
out.push([
|
|
1371
|
+
readCanonicalValue(keyField.type, keyVec, i),
|
|
1372
|
+
readCanonicalValue(valueField.type, valueVec, i)
|
|
1373
|
+
]);
|
|
1374
|
+
}
|
|
1375
|
+
return out;
|
|
1376
|
+
}
|
|
1377
|
+
function readDictionary(type, col, data, index) {
|
|
1378
|
+
const valueType = type.dictionary;
|
|
1379
|
+
if (data && data.dictionary && data.values) {
|
|
1380
|
+
const idx = Number(data.values[index]);
|
|
1381
|
+
const dictVec = data.dictionary;
|
|
1382
|
+
return readCanonicalValue(valueType, dictVec, idx);
|
|
1383
|
+
}
|
|
1384
|
+
return col.get(index);
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
// src/arrow/impl-arrowjs/build.ts
|
|
1388
|
+
function columnFromArray(values, type) {
|
|
1389
|
+
return vectorFromArray2(values, type).data[0];
|
|
1390
|
+
}
|
|
1391
|
+
function batchFromRows(rows, schema2) {
|
|
1392
|
+
const a = schema2;
|
|
1393
|
+
if (rows.length === 0) {
|
|
1394
|
+
return emptyBatch(a);
|
|
1395
|
+
}
|
|
1396
|
+
const columns = {};
|
|
1397
|
+
for (const field2 of a.fields) {
|
|
1398
|
+
columns[field2.name] = rows.map((r) => r[field2.name] ?? null);
|
|
1399
|
+
}
|
|
1400
|
+
return batchFromColumns(columns, a);
|
|
1401
|
+
}
|
|
1402
|
+
function batchFromColumns(columns, schema2, repr = "rich") {
|
|
1403
|
+
const a = schema2;
|
|
1404
|
+
const numRows = a.fields.length > 0 ? columns[a.fields[0].name]?.length ?? 0 : 0;
|
|
1405
|
+
const children = a.fields.map((f) => {
|
|
1406
|
+
const values = columns[f.name];
|
|
1407
|
+
if (!values) {
|
|
1408
|
+
return makeData3({ type: f.type, length: numRows, nullCount: numRows });
|
|
1409
|
+
}
|
|
1410
|
+
const codec = codecFor(f.type);
|
|
1411
|
+
const toCanon = repr === "raw" ? codec.rawToCanonical : codec.richToCanonical;
|
|
1412
|
+
const canonical = values.map((v) => toCanon.call(codec, v));
|
|
1413
|
+
return writeCanonicalColumn(f.type, canonical);
|
|
1414
|
+
});
|
|
1415
|
+
const structType = new Struct3(a.fields);
|
|
1416
|
+
const data = makeData3({
|
|
1417
|
+
type: structType,
|
|
1418
|
+
length: numRows,
|
|
1419
|
+
children,
|
|
1420
|
+
nullCount: 0
|
|
1421
|
+
});
|
|
1422
|
+
return new RecordBatch2(a, data);
|
|
1423
|
+
}
|
|
1424
|
+
// src/arrow/impl-arrowjs/iterate.ts
|
|
1425
|
+
function* iterRows(batch, repr = "rich") {
|
|
1426
|
+
const a = batch;
|
|
1427
|
+
const codecs = a.schema.fields.map((f) => codecFor(f.type));
|
|
1428
|
+
for (let i = 0;i < a.numRows; i++) {
|
|
1429
|
+
const row = {};
|
|
1430
|
+
for (let fi = 0;fi < a.schema.fields.length; fi++) {
|
|
1431
|
+
const field2 = a.schema.fields[fi];
|
|
1432
|
+
const col = a.getChild(field2.name);
|
|
1433
|
+
if (!col) {
|
|
1434
|
+
row[field2.name] = null;
|
|
1435
|
+
continue;
|
|
1436
|
+
}
|
|
1437
|
+
const canonical = readCanonicalValue(field2.type, col, i);
|
|
1438
|
+
const codec = codecs[fi];
|
|
1439
|
+
row[field2.name] = repr === "raw" ? codec.canonicalToRaw(canonical) : codec.canonicalToRich(canonical);
|
|
1440
|
+
}
|
|
1441
|
+
yield row;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
function batchToScalarDict(batch) {
|
|
1445
|
+
if (!batch)
|
|
1446
|
+
return {};
|
|
1447
|
+
const a = batch;
|
|
1448
|
+
if (a.numRows === 0)
|
|
1449
|
+
return {};
|
|
1450
|
+
const result = {};
|
|
1451
|
+
for (const field2 of a.schema.fields) {
|
|
1452
|
+
const col = a.getChild(field2.name);
|
|
1453
|
+
if (col) {
|
|
1454
|
+
const type = field2.type;
|
|
1455
|
+
const canonical = readCanonicalValue(type, col, 0);
|
|
1456
|
+
result[field2.name] = codecFor(type).canonicalToRich(canonical);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
return result;
|
|
1460
|
+
}
|
|
1461
|
+
function decodeDictValue(value, index = 0) {
|
|
1462
|
+
if (value && typeof value === "object" && "dictionary" in value && "values" in value && typeof value.dictionary?.get === "function") {
|
|
1463
|
+
const data = value;
|
|
1464
|
+
const nullBitmap = data.nullBitmap;
|
|
1465
|
+
if (nullBitmap && nullBitmap.length > 0) {
|
|
1466
|
+
const byte = nullBitmap[index >> 3];
|
|
1467
|
+
if ((byte >> (index & 7) & 1) === 0)
|
|
1468
|
+
return null;
|
|
1469
|
+
}
|
|
1470
|
+
const idx = Number(data.values[index]);
|
|
1471
|
+
return value.dictionary.get(idx);
|
|
1472
|
+
}
|
|
1473
|
+
return value;
|
|
1474
|
+
}
|
|
1475
|
+
function batchToSecretDict(batch) {
|
|
1476
|
+
if (!batch)
|
|
1477
|
+
return {};
|
|
1478
|
+
const a = batch;
|
|
1479
|
+
if (a.numRows === 0)
|
|
1480
|
+
return {};
|
|
1481
|
+
const result = {};
|
|
1482
|
+
for (const field2 of a.schema.fields) {
|
|
1483
|
+
const col = a.getChild(field2.name);
|
|
1484
|
+
if (col) {
|
|
1485
|
+
const type = field2.type;
|
|
1486
|
+
const val = codecFor(type).canonicalToRich(readCanonicalValue(type, col, 0));
|
|
1487
|
+
let key = field2.name;
|
|
1488
|
+
let scope;
|
|
1489
|
+
if (field2.name.startsWith("secret_")) {
|
|
1490
|
+
const secretType = field2.metadata?.get?.("secret_type");
|
|
1491
|
+
if (secretType) {
|
|
1492
|
+
key = secretType;
|
|
1493
|
+
scope = field2.metadata?.get?.("scope") ?? undefined;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
if (val && typeof val === "object" && !ArrayBuffer.isView(val)) {
|
|
1497
|
+
const dict = { ...val };
|
|
1498
|
+
if (key in result) {
|
|
1499
|
+
throw new Error(`batchToSecretDict: duplicate secret_type '${key}' (scope=${scope ?? "none"}). ` + `Use scoped secrets with distinct scopes to avoid collisions.`);
|
|
1500
|
+
}
|
|
1501
|
+
result[key] = dict;
|
|
1502
|
+
if (scope) {
|
|
1503
|
+
result[`${key}:${scope}`] = dict;
|
|
1504
|
+
}
|
|
1505
|
+
} else if (val === null || val === undefined) {} else {
|
|
1506
|
+
result[key] = {};
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return result;
|
|
1511
|
+
}
|
|
1512
|
+
function safeNumber(value) {
|
|
1513
|
+
if (typeof value === "bigint") {
|
|
1514
|
+
return Number(value);
|
|
1515
|
+
}
|
|
1516
|
+
return value;
|
|
1517
|
+
}
|
|
1518
|
+
// src/arrow/impl-arrowjs/filter.ts
|
|
1519
|
+
function filterBatch(batch, mask) {
|
|
1520
|
+
const a = batch;
|
|
1521
|
+
const n = a.numRows;
|
|
1522
|
+
let passCount = 0;
|
|
1523
|
+
for (let i = 0;i < n; i++) {
|
|
1524
|
+
if (mask[i])
|
|
1525
|
+
passCount++;
|
|
1526
|
+
}
|
|
1527
|
+
if (passCount === n)
|
|
1528
|
+
return a;
|
|
1529
|
+
if (passCount === 0)
|
|
1530
|
+
return emptyBatch(a.schema);
|
|
1531
|
+
const indices = [];
|
|
1532
|
+
for (let i = 0;i < n; i++) {
|
|
1533
|
+
if (mask[i])
|
|
1534
|
+
indices.push(i);
|
|
1535
|
+
}
|
|
1536
|
+
const columns = {};
|
|
1537
|
+
for (const field2 of a.schema.fields) {
|
|
1538
|
+
const col = a.getChild(field2.name);
|
|
1539
|
+
const type = field2.type;
|
|
1540
|
+
const codec = codecFor(type);
|
|
1541
|
+
columns[field2.name] = indices.map((i) => codec.canonicalToRich(readCanonicalValue(type, col, i)));
|
|
1542
|
+
}
|
|
1543
|
+
return batchFromColumns(columns, a.schema);
|
|
1544
|
+
}
|
|
1545
|
+
// src/arrow/impl-arrowjs/project.ts
|
|
1546
|
+
import {
|
|
1547
|
+
RecordBatch as RecordBatch3,
|
|
1548
|
+
Schema as Schema3,
|
|
1549
|
+
Struct as Struct4,
|
|
1550
|
+
makeData as makeData4
|
|
1551
|
+
} from "@query-farm/apache-arrow";
|
|
1552
|
+
function validateProjectionIds(caller, projectionIds, fieldCount) {
|
|
1553
|
+
for (const id of projectionIds) {
|
|
1554
|
+
if (id < -1) {
|
|
1555
|
+
throw new Error(`${caller}: unexpected negative projection ID ${id} (only -1 for row_id is allowed)`);
|
|
1556
|
+
}
|
|
1557
|
+
if (id >= fieldCount) {
|
|
1558
|
+
console.warn(`${caller}: projection ID ${id} is out of bounds (schema has ${fieldCount} fields), ignoring`);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
return projectionIds.filter((i) => i >= 0 && i < fieldCount);
|
|
1562
|
+
}
|
|
1563
|
+
function projectSchema(projectionIds, schema2) {
|
|
1564
|
+
const a = schema2;
|
|
1565
|
+
if (!projectionIds)
|
|
1566
|
+
return a;
|
|
1567
|
+
const validIds = validateProjectionIds("projectSchema", projectionIds, a.fields.length);
|
|
1568
|
+
if (validIds.length === 0)
|
|
1569
|
+
return a;
|
|
1570
|
+
return new Schema3(validIds.map((i) => a.fields[i]));
|
|
1571
|
+
}
|
|
1572
|
+
function projectBatch(projectionIds, batch) {
|
|
1573
|
+
const a = batch;
|
|
1574
|
+
if (!projectionIds)
|
|
1575
|
+
return a;
|
|
1576
|
+
const validIds = validateProjectionIds("projectBatch", projectionIds, a.schema.fields.length);
|
|
1577
|
+
if (validIds.length === 0)
|
|
1578
|
+
return a;
|
|
1579
|
+
const projectedSchema = projectSchema(projectionIds, a.schema);
|
|
1580
|
+
const children = validIds.map((i) => {
|
|
1581
|
+
const col = a.getChildAt(i);
|
|
1582
|
+
return col.data[0];
|
|
1583
|
+
});
|
|
1584
|
+
const structType = new Struct4(projectedSchema.fields);
|
|
1585
|
+
const data = makeData4({
|
|
1586
|
+
type: structType,
|
|
1587
|
+
length: a.numRows,
|
|
1588
|
+
children,
|
|
1589
|
+
nullCount: 0
|
|
1590
|
+
});
|
|
1591
|
+
return new RecordBatch3(projectedSchema, data);
|
|
1592
|
+
}
|
|
1593
|
+
// src/arrow/impl-arrowjs/ipc.ts
|
|
1594
|
+
import {
|
|
1595
|
+
Schema as Schema4,
|
|
1596
|
+
RecordBatchStreamWriter,
|
|
1597
|
+
RecordBatchReader
|
|
1598
|
+
} from "@query-farm/apache-arrow";
|
|
1599
|
+
function serializeSchema(schema2) {
|
|
1600
|
+
const writer = new RecordBatchStreamWriter;
|
|
1601
|
+
writer.reset(undefined, schema2);
|
|
1602
|
+
writer.close();
|
|
1603
|
+
return writer.toUint8Array(true);
|
|
1604
|
+
}
|
|
1605
|
+
function deserializeSchema(bytes) {
|
|
1606
|
+
const reader = RecordBatchReader.from(bytes);
|
|
1607
|
+
const batches = [...reader];
|
|
1608
|
+
if (batches.length > 0) {
|
|
1609
|
+
return batches[0].schema;
|
|
1610
|
+
}
|
|
1611
|
+
if (reader.schema)
|
|
1612
|
+
return reader.schema;
|
|
1613
|
+
throw new Error("Cannot deserialize schema from empty IPC stream");
|
|
1614
|
+
}
|
|
1615
|
+
function serializeBatch(batch) {
|
|
1616
|
+
const a = batch;
|
|
1617
|
+
const writer = new RecordBatchStreamWriter;
|
|
1618
|
+
writer.reset(undefined, a.schema);
|
|
1619
|
+
writer._writeRecordBatch(a);
|
|
1620
|
+
writer.close();
|
|
1621
|
+
return writer.toUint8Array(true);
|
|
1622
|
+
}
|
|
1623
|
+
function deserializeBatch(bytes) {
|
|
1624
|
+
const reader = RecordBatchReader.from(bytes);
|
|
1625
|
+
const batches = [...reader];
|
|
1626
|
+
if (batches.length === 0) {
|
|
1627
|
+
const sch = reader.schema ?? new Schema4([]);
|
|
1628
|
+
return emptyBatch(sch);
|
|
1629
|
+
}
|
|
1630
|
+
return batches[0];
|
|
1631
|
+
}
|
|
1632
|
+
// src/arrow/impl-arrowjs/statistics.ts
|
|
1633
|
+
import {
|
|
1634
|
+
Field as Field3,
|
|
1635
|
+
Null,
|
|
1636
|
+
makeData as makeData5,
|
|
1637
|
+
RecordBatch as RecordBatch5,
|
|
1638
|
+
Struct as Struct5,
|
|
1639
|
+
SparseUnion,
|
|
1640
|
+
Schema as Schema5,
|
|
1641
|
+
Utf8,
|
|
1642
|
+
Bool,
|
|
1643
|
+
Int64,
|
|
1644
|
+
Uint64
|
|
1645
|
+
} from "@query-farm/apache-arrow";
|
|
1646
|
+
function typeKey(t) {
|
|
1647
|
+
const a = t;
|
|
1648
|
+
return [
|
|
1649
|
+
t.typeId,
|
|
1650
|
+
a.unit ?? "",
|
|
1651
|
+
a.bitWidth ?? "",
|
|
1652
|
+
a.precision ?? "",
|
|
1653
|
+
a.scale ?? "",
|
|
1654
|
+
a.byteWidth ?? ""
|
|
1655
|
+
].join(":");
|
|
1656
|
+
}
|
|
1657
|
+
function buildTypedColumnData(values, type) {
|
|
1658
|
+
const a = type;
|
|
1659
|
+
if (a.typeId === 1) {
|
|
1660
|
+
return makeData5({ type: a, length: values.length, nullCount: values.length });
|
|
1661
|
+
}
|
|
1662
|
+
const codec = codecFor(type);
|
|
1663
|
+
const canonical = values.map((v) => codec.richToCanonical(v));
|
|
1664
|
+
return writeCanonicalColumn(type, canonical);
|
|
1665
|
+
}
|
|
1666
|
+
function buildStatisticsBatch(stats) {
|
|
1667
|
+
if (stats.length === 0) {
|
|
1668
|
+
const nullField = new Field3("0", new Null, true);
|
|
1669
|
+
const unionType2 = new SparseUnion([0], [nullField]);
|
|
1670
|
+
const minData2 = makeData5({
|
|
1671
|
+
type: unionType2,
|
|
1672
|
+
length: 0,
|
|
1673
|
+
typeIds: new Int8Array(0),
|
|
1674
|
+
children: [makeData5({ type: new Null, length: 0, nullCount: 0 })]
|
|
1675
|
+
});
|
|
1676
|
+
const maxData2 = makeData5({
|
|
1677
|
+
type: unionType2,
|
|
1678
|
+
length: 0,
|
|
1679
|
+
typeIds: new Int8Array(0),
|
|
1680
|
+
children: [makeData5({ type: new Null, length: 0, nullCount: 0 })]
|
|
1681
|
+
});
|
|
1682
|
+
return assemble([], minData2, maxData2, [], [], [], [], [], unionType2);
|
|
1683
|
+
}
|
|
1684
|
+
const typeOrder = [];
|
|
1685
|
+
const typeIdMap = new Map;
|
|
1686
|
+
const rowTypeCodes = [];
|
|
1687
|
+
for (const s of stats) {
|
|
1688
|
+
const key = typeKey(s.arrowType);
|
|
1689
|
+
let code = typeIdMap.get(key);
|
|
1690
|
+
if (code === undefined) {
|
|
1691
|
+
code = typeOrder.length;
|
|
1692
|
+
typeIdMap.set(key, code);
|
|
1693
|
+
typeOrder.push(s.arrowType);
|
|
1694
|
+
}
|
|
1695
|
+
rowTypeCodes.push(code);
|
|
1696
|
+
}
|
|
1697
|
+
const unionFields = [];
|
|
1698
|
+
const minChildren = [];
|
|
1699
|
+
const maxChildren = [];
|
|
1700
|
+
const typeIds = [];
|
|
1701
|
+
for (const [code, arrowType] of typeOrder.entries()) {
|
|
1702
|
+
unionFields.push(new Field3(String(code), arrowType, true));
|
|
1703
|
+
typeIds.push(code);
|
|
1704
|
+
const minVals = stats.map((s, i) => rowTypeCodes[i] === code ? s.min : null);
|
|
1705
|
+
const maxVals = stats.map((s, i) => rowTypeCodes[i] === code ? s.max : null);
|
|
1706
|
+
minChildren.push(buildTypedColumnData(minVals, arrowType));
|
|
1707
|
+
maxChildren.push(buildTypedColumnData(maxVals, arrowType));
|
|
1708
|
+
}
|
|
1709
|
+
const unionType = new SparseUnion(typeIds, unionFields);
|
|
1710
|
+
const typeIdsBuf = Int8Array.from(rowTypeCodes);
|
|
1711
|
+
const minData = makeData5({
|
|
1712
|
+
type: unionType,
|
|
1713
|
+
length: stats.length,
|
|
1714
|
+
typeIds: typeIdsBuf,
|
|
1715
|
+
children: minChildren
|
|
1716
|
+
});
|
|
1717
|
+
const maxData = makeData5({
|
|
1718
|
+
type: unionType,
|
|
1719
|
+
length: stats.length,
|
|
1720
|
+
typeIds: typeIdsBuf,
|
|
1721
|
+
children: maxChildren
|
|
1722
|
+
});
|
|
1723
|
+
return assemble(stats.map((s) => s.columnName), minData, maxData, stats.map((s) => s.hasNull), stats.map((s) => s.hasNotNull), stats.map((s) => s.distinctCount == null ? null : BigInt(s.distinctCount)), stats.map((s) => s.containsUnicode), stats.map((s) => s.maxStringLength == null ? null : BigInt(s.maxStringLength)), unionType);
|
|
1724
|
+
}
|
|
1725
|
+
function assemble(columnNames, minData, maxData, hasNull, hasNotNull, distinctCount, containsUnicode, maxStringLength, unionType) {
|
|
1726
|
+
const schema2 = new Schema5([
|
|
1727
|
+
new Field3("column_name", new Utf8, false),
|
|
1728
|
+
new Field3("min", unionType, true),
|
|
1729
|
+
new Field3("max", unionType, true),
|
|
1730
|
+
new Field3("has_null", new Bool, false),
|
|
1731
|
+
new Field3("has_not_null", new Bool, false),
|
|
1732
|
+
new Field3("distinct_count", new Int64, true),
|
|
1733
|
+
new Field3("contains_unicode", new Bool, true),
|
|
1734
|
+
new Field3("max_string_length", new Uint64, true)
|
|
1735
|
+
]);
|
|
1736
|
+
const n = columnNames.length;
|
|
1737
|
+
const children = [
|
|
1738
|
+
buildTypedColumnData(columnNames, new Utf8),
|
|
1739
|
+
minData,
|
|
1740
|
+
maxData,
|
|
1741
|
+
buildTypedColumnData(hasNull, new Bool),
|
|
1742
|
+
buildTypedColumnData(hasNotNull, new Bool),
|
|
1743
|
+
buildTypedColumnData(distinctCount, new Int64),
|
|
1744
|
+
buildTypedColumnData(containsUnicode, new Bool),
|
|
1745
|
+
buildTypedColumnData(maxStringLength, new Uint64)
|
|
1746
|
+
];
|
|
1747
|
+
const structType = new Struct5(schema2.fields);
|
|
1748
|
+
const data = makeData5({ type: structType, length: n, children, nullCount: 0 });
|
|
1749
|
+
return new RecordBatch5(schema2, data);
|
|
1750
|
+
}
|
|
1751
|
+
|
|
1752
|
+
// src/arrow/impl-arrowjs/index.ts
|
|
1753
|
+
var backend = { name: "arrow-js" };
|
|
1754
|
+
// src/arrow/schema-types.ts
|
|
1755
|
+
var { TimeUnit: TimeUnit2, DateUnit: DateUnit3, IntervalUnit: IntervalUnit2, UnionMode: UnionMode2, schema: schema2 } = exports_impl_arrowjs;
|
|
1756
|
+
function field2(name, type, nullable, metadata) {
|
|
1757
|
+
return field(name, type, nullable, metadata);
|
|
1758
|
+
}
|
|
1759
|
+
var nullType2 = () => nullType();
|
|
1760
|
+
var bool2 = () => bool();
|
|
1761
|
+
var int162 = () => int16();
|
|
1762
|
+
var int322 = () => int32();
|
|
1763
|
+
var int642 = () => int64();
|
|
1764
|
+
var float642 = () => float64();
|
|
1765
|
+
var utf82 = () => utf8();
|
|
1766
|
+
var binary2 = () => binary();
|
|
1767
|
+
var UNIT_TO_TAG = {
|
|
1768
|
+
[TimeUnit.SECOND]: "s",
|
|
1769
|
+
[TimeUnit.MILLISECOND]: "ms",
|
|
1770
|
+
[TimeUnit.MICROSECOND]: "us",
|
|
1771
|
+
[TimeUnit.NANOSECOND]: "ns"
|
|
1772
|
+
};
|
|
1773
|
+
function timestamp2(unit, timezone) {
|
|
1774
|
+
return timestamp(unit, timezone ?? null);
|
|
1775
|
+
}
|
|
1776
|
+
function list2(child) {
|
|
1777
|
+
return list(child);
|
|
1778
|
+
}
|
|
1779
|
+
function struct2(children) {
|
|
1780
|
+
return struct(children);
|
|
1781
|
+
}
|
|
1782
|
+
function map2(keyField, valueField, keysSorted) {
|
|
1783
|
+
return map(keyField, valueField, keysSorted);
|
|
1784
|
+
}
|
|
1785
|
+
function dictionary2(valueType, indexType, ordered, id) {
|
|
1786
|
+
return dictionary(valueType, indexType, ordered, id);
|
|
1787
|
+
}
|
|
1788
|
+
// src/arguments/arguments.ts
|
|
1789
|
+
class Arguments {
|
|
1790
|
+
positional;
|
|
1791
|
+
named;
|
|
1792
|
+
argumentsSchema;
|
|
1793
|
+
constructor(positional = [], named = new Map, argumentsSchema = null) {
|
|
1794
|
+
this.positional = positional;
|
|
1795
|
+
this.named = named;
|
|
1796
|
+
this.argumentsSchema = argumentsSchema;
|
|
1797
|
+
}
|
|
1798
|
+
get(position, defaultValue) {
|
|
1799
|
+
if (typeof position === "number") {
|
|
1800
|
+
if (position < this.positional.length) {
|
|
1801
|
+
const val = this.positional[position];
|
|
1802
|
+
if (val === null || val === undefined) {
|
|
1803
|
+
return defaultValue !== undefined ? defaultValue : null;
|
|
1804
|
+
}
|
|
1805
|
+
return unwrapScalar(val);
|
|
1806
|
+
}
|
|
1807
|
+
if (defaultValue !== undefined)
|
|
1808
|
+
return defaultValue;
|
|
1809
|
+
throw new Error(`Positional argument ${position} not found`);
|
|
1810
|
+
}
|
|
1811
|
+
if (this.named.has(position)) {
|
|
1812
|
+
const val = this.named.get(position);
|
|
1813
|
+
if (val === null || val === undefined) {
|
|
1814
|
+
return defaultValue !== undefined ? defaultValue : null;
|
|
1815
|
+
}
|
|
1816
|
+
return unwrapScalar(val);
|
|
1817
|
+
}
|
|
1818
|
+
if (defaultValue !== undefined)
|
|
1819
|
+
return defaultValue;
|
|
1820
|
+
throw new Error(`Named argument '${position}' not found`);
|
|
1821
|
+
}
|
|
1822
|
+
get length() {
|
|
1823
|
+
return this.positional.length;
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
function unwrapScalar(val) {
|
|
1827
|
+
if (val === null || val === undefined)
|
|
1828
|
+
return null;
|
|
1829
|
+
if (typeof val !== "object")
|
|
1830
|
+
return val;
|
|
1831
|
+
if (typeof val.valueOf === "function") {
|
|
1832
|
+
let v;
|
|
1833
|
+
try {
|
|
1834
|
+
v = val.valueOf();
|
|
1835
|
+
} catch {
|
|
1836
|
+
return val;
|
|
1837
|
+
}
|
|
1838
|
+
if (typeof v === "bigint") {
|
|
1839
|
+
if (v >= Number.MIN_SAFE_INTEGER && v <= Number.MAX_SAFE_INTEGER) {
|
|
1840
|
+
return Number(v);
|
|
1841
|
+
}
|
|
1842
|
+
return v;
|
|
1843
|
+
}
|
|
1844
|
+
return v;
|
|
1845
|
+
}
|
|
1846
|
+
return val;
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
// src/types.ts
|
|
1850
|
+
var FunctionType;
|
|
1851
|
+
((FunctionType2) => {
|
|
1852
|
+
FunctionType2["SCALAR"] = "scalar";
|
|
1853
|
+
FunctionType2["TABLE"] = "table";
|
|
1854
|
+
FunctionType2["AGGREGATE"] = "aggregate";
|
|
1855
|
+
})(FunctionType ||= {});
|
|
1856
|
+
var FunctionStability;
|
|
1857
|
+
((FunctionStability2) => {
|
|
1858
|
+
FunctionStability2["CONSISTENT"] = "CONSISTENT";
|
|
1859
|
+
FunctionStability2["VOLATILE"] = "VOLATILE";
|
|
1860
|
+
FunctionStability2["CONSISTENT_WITHIN_QUERY"] = "CONSISTENT_WITHIN_QUERY";
|
|
1861
|
+
})(FunctionStability ||= {});
|
|
1862
|
+
var NullHandling;
|
|
1863
|
+
((NullHandling2) => {
|
|
1864
|
+
NullHandling2["DEFAULT"] = "DEFAULT";
|
|
1865
|
+
NullHandling2["SPECIAL"] = "SPECIAL";
|
|
1866
|
+
})(NullHandling ||= {});
|
|
1867
|
+
var OrderPreservation;
|
|
1868
|
+
((OrderPreservation2) => {
|
|
1869
|
+
OrderPreservation2["PRESERVES_ORDER"] = "PRESERVES_ORDER";
|
|
1870
|
+
OrderPreservation2["NO_ORDER_GUARANTEE"] = "NO_ORDER_GUARANTEE";
|
|
1871
|
+
OrderPreservation2["FIXED_ORDER"] = "FIXED_ORDER";
|
|
1872
|
+
})(OrderPreservation ||= {});
|
|
1873
|
+
var OrderDependence;
|
|
1874
|
+
((OrderDependence2) => {
|
|
1875
|
+
OrderDependence2["ORDER_DEPENDENT"] = "ORDER_DEPENDENT";
|
|
1876
|
+
OrderDependence2["NOT_ORDER_DEPENDENT"] = "NOT_ORDER_DEPENDENT";
|
|
1877
|
+
})(OrderDependence ||= {});
|
|
1878
|
+
var DistinctDependence;
|
|
1879
|
+
((DistinctDependence2) => {
|
|
1880
|
+
DistinctDependence2["DISTINCT_DEPENDENT"] = "DISTINCT_DEPENDENT";
|
|
1881
|
+
DistinctDependence2["NOT_DISTINCT_DEPENDENT"] = "NOT_DISTINCT_DEPENDENT";
|
|
1882
|
+
})(DistinctDependence ||= {});
|
|
1883
|
+
var TableInOutPhase;
|
|
1884
|
+
((TableInOutPhase2) => {
|
|
1885
|
+
TableInOutPhase2["INPUT"] = "INPUT";
|
|
1886
|
+
TableInOutPhase2["FINALIZE"] = "FINALIZE";
|
|
1887
|
+
TableInOutPhase2["TABLE_BUFFERING"] = "TABLE_BUFFERING";
|
|
1888
|
+
TableInOutPhase2["TABLE_BUFFERING_FINALIZE"] = "TABLE_BUFFERING_FINALIZE";
|
|
1889
|
+
})(TableInOutPhase ||= {});
|
|
1890
|
+
var VGI_ARG_KEY = "vgi_arg";
|
|
1891
|
+
var VGI_ARG_NAMED = "named";
|
|
1892
|
+
var VGI_TYPE_KEY = "vgi_type";
|
|
1893
|
+
var VGI_TYPE_TABLE = "table";
|
|
1894
|
+
var VGI_TYPE_ANY = "any";
|
|
1895
|
+
var VGI_VARARGS_KEY = "vgi_varargs";
|
|
1896
|
+
var VGI_VARARGS_TRUE = "true";
|
|
1897
|
+
var VGI_CONST_KEY = "vgi_const";
|
|
1898
|
+
var VGI_CONST_TRUE = "true";
|
|
1899
|
+
var VGI_DOC_KEY = "vgi_doc";
|
|
1900
|
+
var VGI_DEFAULT_KEY = "vgi_default";
|
|
1901
|
+
var VGI_CHOICES_KEY = "vgi_choices";
|
|
1902
|
+
var VGI_RANGE_KEY = "vgi_range";
|
|
1903
|
+
var VGI_PATTERN_KEY = "vgi_pattern";
|
|
1904
|
+
// src/util/bytes.ts
|
|
1905
|
+
function toUint8Array(val) {
|
|
1906
|
+
if (val instanceof Uint8Array)
|
|
1907
|
+
return val;
|
|
1908
|
+
if (val instanceof ArrayBuffer)
|
|
1909
|
+
return new Uint8Array(val);
|
|
1910
|
+
if (typeof Buffer !== "undefined" && Buffer.isBuffer(val))
|
|
1911
|
+
return new Uint8Array(val);
|
|
1912
|
+
if (val && val.buffer instanceof ArrayBuffer) {
|
|
1913
|
+
return new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
|
|
1914
|
+
}
|
|
1915
|
+
return new Uint8Array(0);
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
// src/protocol/serializers/shared.ts
|
|
1919
|
+
function toUint8Array2(val) {
|
|
1920
|
+
if (typeof val === "string")
|
|
1921
|
+
return new TextEncoder().encode(val);
|
|
1922
|
+
const result = toUint8Array(val);
|
|
1923
|
+
if (result.length === 0 && val != null) {
|
|
1924
|
+
throw new Error(`Cannot convert ${typeof val} to Uint8Array`);
|
|
1925
|
+
}
|
|
1926
|
+
return result;
|
|
1927
|
+
}
|
|
1928
|
+
function buildSingleRowBatch(schema3, values) {
|
|
1929
|
+
const cols = {};
|
|
1930
|
+
for (const f of schema3.fields) {
|
|
1931
|
+
let val = values[f.name];
|
|
1932
|
+
if (isInt(f.type) && f.type.bitWidth === 64 && typeof val === "number") {
|
|
1933
|
+
val = BigInt(val);
|
|
1934
|
+
}
|
|
1935
|
+
cols[f.name] = [val];
|
|
1936
|
+
}
|
|
1937
|
+
return batchFromColumns(cols, schema3);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
// src/protocol/serializers/arguments.ts
|
|
1941
|
+
function serializeArguments(args) {
|
|
1942
|
+
const structFields = [];
|
|
1943
|
+
const structValues = {};
|
|
1944
|
+
for (let i = 0;i < args.positional.length; i++) {
|
|
1945
|
+
const val = args.positional[i];
|
|
1946
|
+
const fieldName = `positional_${i}`;
|
|
1947
|
+
structFields.push(field2(fieldName, inferScalarType(val), true));
|
|
1948
|
+
structValues[fieldName] = val;
|
|
1949
|
+
}
|
|
1950
|
+
for (const [name, val] of args.named) {
|
|
1951
|
+
const fieldName = `named_${name}`;
|
|
1952
|
+
structFields.push(field2(fieldName, inferScalarType(val), true));
|
|
1953
|
+
structValues[fieldName] = val;
|
|
1954
|
+
}
|
|
1955
|
+
const structType = struct2(structFields);
|
|
1956
|
+
const sch = schema2([field2("args", structType, true)]);
|
|
1957
|
+
const structRow = {};
|
|
1958
|
+
for (const f of structFields) {
|
|
1959
|
+
let val = structValues[f.name];
|
|
1960
|
+
if (isInt(f.type) && f.type.bitWidth === 64 && typeof val === "number") {
|
|
1961
|
+
val = BigInt(val);
|
|
1962
|
+
}
|
|
1963
|
+
structRow[f.name] = val;
|
|
1964
|
+
}
|
|
1965
|
+
const batch = batchFromColumns({ args: [structRow] }, sch);
|
|
1966
|
+
return serializeBatch(batch);
|
|
1967
|
+
}
|
|
1968
|
+
function inferScalarType(val) {
|
|
1969
|
+
if (val === null || val === undefined)
|
|
1970
|
+
return nullType2();
|
|
1971
|
+
if (typeof val === "string")
|
|
1972
|
+
return utf82();
|
|
1973
|
+
if (typeof val === "boolean")
|
|
1974
|
+
return bool2();
|
|
1975
|
+
if (typeof val === "number")
|
|
1976
|
+
return int642();
|
|
1977
|
+
if (typeof val === "bigint")
|
|
1978
|
+
return int642();
|
|
1979
|
+
if (val instanceof Uint8Array || val instanceof ArrayBuffer)
|
|
1980
|
+
return binary2();
|
|
1981
|
+
return utf82();
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1984
|
+
// src/protocol/serializers/bind.ts
|
|
1985
|
+
var BIND_REQUEST_SCHEMA = schema2([
|
|
1986
|
+
field2("function_name", utf82(), false),
|
|
1987
|
+
field2("arguments", binary2(), false),
|
|
1988
|
+
field2("function_type", utf82(), false),
|
|
1989
|
+
field2("input_schema", binary2(), true),
|
|
1990
|
+
field2("settings", binary2(), true),
|
|
1991
|
+
field2("secrets", binary2(), true),
|
|
1992
|
+
field2("attach_opaque_data", binary2(), true),
|
|
1993
|
+
field2("transaction_opaque_data", binary2(), true),
|
|
1994
|
+
field2("resolved_secrets_provided", bool2(), false),
|
|
1995
|
+
field2("at_unit", utf82(), true),
|
|
1996
|
+
field2("at_value", utf82(), true)
|
|
1997
|
+
]);
|
|
1998
|
+
var COPY_FROM_STRUCT_TYPE = struct2([
|
|
1999
|
+
field2("format", utf82(), false),
|
|
2000
|
+
field2("file_path", utf82(), false),
|
|
2001
|
+
field2("expected_schema", binary2(), false)
|
|
2002
|
+
]);
|
|
2003
|
+
var COPY_FROM_FIELD = field2("copy_from", COPY_FROM_STRUCT_TYPE, true);
|
|
2004
|
+
var COPY_TO_STRUCT_TYPE = struct2([
|
|
2005
|
+
field2("format", utf82(), false),
|
|
2006
|
+
field2("file_path", utf82(), false)
|
|
2007
|
+
]);
|
|
2008
|
+
var COPY_TO_FIELD = field2("copy_to", COPY_TO_STRUCT_TYPE, true);
|
|
2009
|
+
var BIND_RESPONSE_SCHEMA = schema2([
|
|
2010
|
+
field2("output_schema", binary2(), false),
|
|
2011
|
+
field2("opaque_data", binary2(), true),
|
|
2012
|
+
field2("lookup_secret_types", list2(field2("item", utf82(), true)), false),
|
|
2013
|
+
field2("lookup_scopes", list2(field2("item", utf82(), true)), false),
|
|
2014
|
+
field2("lookup_names", list2(field2("item", utf82(), true)), false)
|
|
2015
|
+
]);
|
|
2016
|
+
function serializeBindRequest(req) {
|
|
2017
|
+
const row = {
|
|
2018
|
+
function_name: req.function_name,
|
|
2019
|
+
arguments: serializeArguments(req.arguments),
|
|
2020
|
+
function_type: req.function_type,
|
|
2021
|
+
input_schema: req.input_schema ? serializeSchema(req.input_schema) : null,
|
|
2022
|
+
settings: req.settings ? serializeBatch(req.settings) : null,
|
|
2023
|
+
secrets: req.secrets ? serializeBatch(req.secrets) : null,
|
|
2024
|
+
attach_opaque_data: req.attach_opaque_data ?? null,
|
|
2025
|
+
transaction_opaque_data: req.transaction_opaque_data ?? null,
|
|
2026
|
+
resolved_secrets_provided: req.resolved_secrets_provided ?? false,
|
|
2027
|
+
at_unit: req.at_unit ?? null,
|
|
2028
|
+
at_value: req.at_value ?? null
|
|
2029
|
+
};
|
|
2030
|
+
const extraFields = [];
|
|
2031
|
+
if (req.copy_from) {
|
|
2032
|
+
extraFields.push(COPY_FROM_FIELD);
|
|
2033
|
+
row.copy_from = {
|
|
2034
|
+
format: req.copy_from.format,
|
|
2035
|
+
file_path: req.copy_from.file_path,
|
|
2036
|
+
expected_schema: serializeSchema(req.copy_from.expected_schema)
|
|
2037
|
+
};
|
|
2038
|
+
}
|
|
2039
|
+
if (req.copy_to) {
|
|
2040
|
+
extraFields.push(COPY_TO_FIELD);
|
|
2041
|
+
row.copy_to = {
|
|
2042
|
+
format: req.copy_to.format,
|
|
2043
|
+
file_path: req.copy_to.file_path
|
|
2044
|
+
};
|
|
2045
|
+
}
|
|
2046
|
+
if (extraFields.length > 0) {
|
|
2047
|
+
const schemaWithCopy = schema2([...BIND_REQUEST_SCHEMA.fields, ...extraFields]);
|
|
2048
|
+
return buildSingleRowBatch(schemaWithCopy, row);
|
|
2049
|
+
}
|
|
2050
|
+
return buildSingleRowBatch(BIND_REQUEST_SCHEMA, row);
|
|
2051
|
+
}
|
|
2052
|
+
function deserializeBindResponse(params) {
|
|
2053
|
+
const toStrArray = (val) => {
|
|
2054
|
+
if (!val)
|
|
2055
|
+
return [];
|
|
2056
|
+
const arr = Array.isArray(val) ? val : [...val];
|
|
2057
|
+
return arr.filter((v) => v != null).map(String);
|
|
2058
|
+
};
|
|
2059
|
+
return {
|
|
2060
|
+
output_schema: deserializeSchema(toUint8Array2(params.output_schema)),
|
|
2061
|
+
opaque_data: params.opaque_data ? toUint8Array2(params.opaque_data) : null,
|
|
2062
|
+
lookup_secret_types: toStrArray(params.lookup_secret_types),
|
|
2063
|
+
lookup_scopes: toStrArray(params.lookup_scopes),
|
|
2064
|
+
lookup_names: toStrArray(params.lookup_names)
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
// src/protocol/serializers/init.ts
|
|
2068
|
+
var INIT_REQUEST_SCHEMA = schema2([
|
|
2069
|
+
field2("bind_call", binary2(), false),
|
|
2070
|
+
field2("output_schema", binary2(), false),
|
|
2071
|
+
field2("bind_opaque_data", binary2(), true),
|
|
2072
|
+
field2("projection_ids", list2(field2("item", int642(), false)), true),
|
|
2073
|
+
field2("pushdown_filters", binary2(), true),
|
|
2074
|
+
field2("join_keys", list2(field2("item", binary2(), true)), false),
|
|
2075
|
+
field2("phase", utf82(), true),
|
|
2076
|
+
field2("execution_id", binary2(), true),
|
|
2077
|
+
field2("init_opaque_data", binary2(), true),
|
|
2078
|
+
field2("order_by_column_name", utf82(), true),
|
|
2079
|
+
field2("order_by_direction", utf82(), true),
|
|
2080
|
+
field2("order_by_null_order", utf82(), true),
|
|
2081
|
+
field2("order_by_limit", int642(), true),
|
|
2082
|
+
field2("tablesample_percentage", float642(), true),
|
|
2083
|
+
field2("tablesample_seed", int642(), true),
|
|
2084
|
+
field2("finalize_state_id", binary2(), true)
|
|
2085
|
+
]);
|
|
2086
|
+
var GLOBAL_INIT_RESPONSE_SCHEMA = schema2([
|
|
2087
|
+
field2("execution_id", binary2(), false),
|
|
2088
|
+
field2("opaque_data", binary2(), true),
|
|
2089
|
+
field2("max_workers", int642(), false)
|
|
2090
|
+
]);
|
|
2091
|
+
function serializeInitRequest(req) {
|
|
2092
|
+
const bindCallBatch = serializeBindRequest(req.bind_call);
|
|
2093
|
+
const bindCallBytes = serializeBatch(bindCallBatch);
|
|
2094
|
+
const row = {
|
|
2095
|
+
bind_call: bindCallBytes,
|
|
2096
|
+
output_schema: serializeSchema(req.output_schema),
|
|
2097
|
+
bind_opaque_data: req.bind_opaque_data ?? null,
|
|
2098
|
+
projection_ids: req.projection_ids?.map((n) => BigInt(n)) ?? null,
|
|
2099
|
+
pushdown_filters: req.pushdown_filters ? serializeBatch(req.pushdown_filters) : null,
|
|
2100
|
+
join_keys: (req.join_keys ?? []).map((b) => serializeBatch(b)),
|
|
2101
|
+
phase: req.phase ?? null,
|
|
2102
|
+
execution_id: req.execution_id ?? null,
|
|
2103
|
+
init_opaque_data: req.init_opaque_data ?? null,
|
|
2104
|
+
order_by_column_name: req.order_by_column_name ?? null,
|
|
2105
|
+
order_by_direction: req.order_by_direction ?? null,
|
|
2106
|
+
order_by_null_order: req.order_by_null_order ?? null,
|
|
2107
|
+
order_by_limit: req.order_by_limit ?? null,
|
|
2108
|
+
tablesample_percentage: req.tablesample_percentage ?? null,
|
|
2109
|
+
tablesample_seed: req.tablesample_seed ?? null,
|
|
2110
|
+
finalize_state_id: req.finalize_state_id ?? null
|
|
2111
|
+
};
|
|
2112
|
+
return buildSingleRowBatch(INIT_REQUEST_SCHEMA, row);
|
|
2113
|
+
}
|
|
2114
|
+
function deserializeGlobalInitResponse(params) {
|
|
2115
|
+
return {
|
|
2116
|
+
execution_id: toUint8Array2(params.execution_id),
|
|
2117
|
+
opaque_data: params.opaque_data ? toUint8Array2(params.opaque_data) : null,
|
|
2118
|
+
max_workers: Number(params.max_workers)
|
|
2119
|
+
};
|
|
2120
|
+
}
|
|
2121
|
+
// src/errors.ts
|
|
2122
|
+
class VgiError extends Error {
|
|
2123
|
+
constructor(message) {
|
|
2124
|
+
super(message);
|
|
2125
|
+
this.name = "VgiError";
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
class RowCountMismatchError extends VgiError {
|
|
2130
|
+
constructor(expected, actual) {
|
|
2131
|
+
super(`Scalar function output row count (${actual}) does not match ` + `input row count (${expected})`);
|
|
2132
|
+
this.name = "RowCountMismatchError";
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
|
|
2136
|
+
class FunctionNotFoundError extends VgiError {
|
|
2137
|
+
constructor(name, available) {
|
|
2138
|
+
super(`Unknown function '${name}'`);
|
|
2139
|
+
this.name = "FunctionNotFoundError";
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
class CatalogReadOnlyError extends VgiError {
|
|
2144
|
+
constructor(operation) {
|
|
2145
|
+
super(`catalog is read-only: ${operation} is not supported`);
|
|
2146
|
+
this.name = "CatalogReadOnlyError";
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
class CatalogNotFoundError extends VgiError {
|
|
2151
|
+
constructor(entity, name) {
|
|
2152
|
+
super(`${entity} '${name}' not found`);
|
|
2153
|
+
this.name = "CatalogNotFoundError";
|
|
2154
|
+
}
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
class CatalogAlreadyExistsError extends VgiError {
|
|
2158
|
+
constructor(entity, name) {
|
|
2159
|
+
super(`${entity} '${name}' already exists`);
|
|
2160
|
+
this.name = "CatalogAlreadyExistsError";
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
class ArgumentValidationError extends VgiError {
|
|
2165
|
+
constructor(message) {
|
|
2166
|
+
super(message);
|
|
2167
|
+
this.name = "ArgumentValidationError";
|
|
2168
|
+
}
|
|
2169
|
+
}
|
|
2170
|
+
|
|
2171
|
+
class NoCatalogError extends VgiError {
|
|
2172
|
+
constructor() {
|
|
2173
|
+
super("No catalog is configured for this worker");
|
|
2174
|
+
this.name = "NoCatalogError";
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// src/codec/asd.ts
|
|
2179
|
+
function encodeASD(schema3, obj) {
|
|
2180
|
+
return serializeBatch(batchFromRows([obj], schema3));
|
|
2181
|
+
}
|
|
2182
|
+
function decodeASD(schema3, bytes) {
|
|
2183
|
+
const batch = deserializeBatch(bytes);
|
|
2184
|
+
if (batch.numRows === 0) {
|
|
2185
|
+
const names = schema3.fields.map((f) => f.name).join(",");
|
|
2186
|
+
throw new Error(`decodeASD: empty batch (expected 1 row for ${names})`);
|
|
2187
|
+
}
|
|
2188
|
+
const out = {};
|
|
2189
|
+
for (const field3 of schema3.fields) {
|
|
2190
|
+
const col = batch.getChild(field3.name);
|
|
2191
|
+
const raw = col ? col.get(0) : null;
|
|
2192
|
+
out[field3.name] = normalizeValue(raw, field3.type);
|
|
2193
|
+
}
|
|
2194
|
+
return out;
|
|
2195
|
+
}
|
|
2196
|
+
function normalizeValue(raw, type) {
|
|
2197
|
+
if (raw == null)
|
|
2198
|
+
return null;
|
|
2199
|
+
if (isList(type)) {
|
|
2200
|
+
const childType = type.children[0].type;
|
|
2201
|
+
const out = [];
|
|
2202
|
+
for (const item of raw)
|
|
2203
|
+
out.push(normalizeValue(item, childType));
|
|
2204
|
+
return out;
|
|
2205
|
+
}
|
|
2206
|
+
if (isMap(type)) {
|
|
2207
|
+
const out = {};
|
|
2208
|
+
if (raw[Symbol.iterator]) {
|
|
2209
|
+
for (const entry of raw) {
|
|
2210
|
+
if (Array.isArray(entry)) {
|
|
2211
|
+
out[String(entry[0])] = String(entry[1] ?? "");
|
|
2212
|
+
} else if (entry && typeof entry === "object") {
|
|
2213
|
+
const k = entry.key ?? entry[0];
|
|
2214
|
+
const v = entry.value ?? entry[1];
|
|
2215
|
+
out[String(k)] = v == null ? "" : String(v);
|
|
2216
|
+
}
|
|
2217
|
+
}
|
|
2218
|
+
} else if (typeof raw === "object") {
|
|
2219
|
+
for (const [k, v] of Object.entries(raw)) {
|
|
2220
|
+
out[String(k)] = v == null ? "" : String(v);
|
|
2221
|
+
}
|
|
2222
|
+
}
|
|
2223
|
+
return out;
|
|
2224
|
+
}
|
|
2225
|
+
if (isStruct(type)) {
|
|
2226
|
+
const childFields = type.children;
|
|
2227
|
+
const out = {};
|
|
2228
|
+
for (const cf of childFields) {
|
|
2229
|
+
out[cf.name] = normalizeValue(raw[cf.name], cf.type);
|
|
2230
|
+
}
|
|
2231
|
+
return out;
|
|
2232
|
+
}
|
|
2233
|
+
if (isDictionary(type)) {
|
|
2234
|
+
return raw == null ? null : String(raw);
|
|
2235
|
+
}
|
|
2236
|
+
if (isBinary(type)) {
|
|
2237
|
+
return toUint8Array3(raw);
|
|
2238
|
+
}
|
|
2239
|
+
if (isInt(type) && type.bitWidth === 64) {
|
|
2240
|
+
if (typeof raw === "bigint") {
|
|
2241
|
+
if (raw >= BigInt(Number.MIN_SAFE_INTEGER) && raw <= BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
2242
|
+
return Number(raw);
|
|
2243
|
+
}
|
|
2244
|
+
return raw;
|
|
2245
|
+
}
|
|
2246
|
+
return raw;
|
|
2247
|
+
}
|
|
2248
|
+
if (isBool(type)) {
|
|
2249
|
+
return Boolean(raw);
|
|
2250
|
+
}
|
|
2251
|
+
return raw;
|
|
2252
|
+
}
|
|
2253
|
+
function toUint8Array3(val) {
|
|
2254
|
+
if (val instanceof Uint8Array)
|
|
2255
|
+
return val;
|
|
2256
|
+
if (val instanceof ArrayBuffer)
|
|
2257
|
+
return new Uint8Array(val);
|
|
2258
|
+
if (val && val.buffer instanceof ArrayBuffer) {
|
|
2259
|
+
return new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
|
|
2260
|
+
}
|
|
2261
|
+
return new Uint8Array(0);
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// src/generated/vgi-protocol-schemas.ts
|
|
2265
|
+
var CatalogInfoSchema = schema2([
|
|
2266
|
+
field2("name", utf82(), false),
|
|
2267
|
+
field2("implementation_version", utf82(), true),
|
|
2268
|
+
field2("data_version_spec", utf82(), true),
|
|
2269
|
+
field2("attach_option_specs", list2(field2("item", binary2(), true)), false),
|
|
2270
|
+
field2("releases", list2(field2("item", struct2([field2("version", utf82(), false), field2("released_at", timestamp2(TimeUnit2.MICROSECOND, "UTC"), false), field2("summary", utf82(), false), field2("notes_url", utf82(), true)]), true)), false),
|
|
2271
|
+
field2("source_url", utf82(), true)
|
|
2272
|
+
]);
|
|
2273
|
+
var SchemaInfoSchema = schema2([
|
|
2274
|
+
field2("comment", utf82(), true),
|
|
2275
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2276
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2277
|
+
field2("name", utf82(), false),
|
|
2278
|
+
field2("estimated_object_count", map2(field2("key", utf82(), false), field2("value", int642(), true), false), true)
|
|
2279
|
+
]);
|
|
2280
|
+
var TableInfoSchema = schema2([
|
|
2281
|
+
field2("comment", utf82(), true),
|
|
2282
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2283
|
+
field2("name", utf82(), false),
|
|
2284
|
+
field2("schema_name", utf82(), false),
|
|
2285
|
+
field2("columns", binary2(), false),
|
|
2286
|
+
field2("not_null_constraints", list2(field2("item", int322(), true)), false),
|
|
2287
|
+
field2("unique_constraints", list2(field2("item", list2(field2("item", int322(), true)), true)), false),
|
|
2288
|
+
field2("check_constraints", list2(field2("item", utf82(), true)), false),
|
|
2289
|
+
field2("primary_key_constraints", list2(field2("item", list2(field2("item", int322(), true)), true)), false),
|
|
2290
|
+
field2("foreign_key_constraints", list2(field2("item", binary2(), true)), false),
|
|
2291
|
+
field2("supports_insert", bool2(), false),
|
|
2292
|
+
field2("supports_update", bool2(), false),
|
|
2293
|
+
field2("supports_delete", bool2(), false),
|
|
2294
|
+
field2("supports_returning", bool2(), false),
|
|
2295
|
+
field2("supports_column_statistics", bool2(), false),
|
|
2296
|
+
field2("scan_function", binary2(), false),
|
|
2297
|
+
field2("insert_function", binary2(), false),
|
|
2298
|
+
field2("update_function", binary2(), false),
|
|
2299
|
+
field2("delete_function", binary2(), false),
|
|
2300
|
+
field2("cardinality_estimate", int642(), false),
|
|
2301
|
+
field2("cardinality_max", int642(), false),
|
|
2302
|
+
field2("column_statistics", binary2(), false),
|
|
2303
|
+
field2("bind_result", binary2(), false),
|
|
2304
|
+
field2("required_filters", list2(field2("item", list2(field2("item", utf82(), true)), true)), false)
|
|
2305
|
+
]);
|
|
2306
|
+
var ViewInfoSchema = schema2([
|
|
2307
|
+
field2("comment", utf82(), true),
|
|
2308
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2309
|
+
field2("name", utf82(), false),
|
|
2310
|
+
field2("schema_name", utf82(), false),
|
|
2311
|
+
field2("definition", utf82(), false),
|
|
2312
|
+
field2("column_comments", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false)
|
|
2313
|
+
]);
|
|
2314
|
+
var FunctionInfoSchema = schema2([
|
|
2315
|
+
field2("comment", utf82(), true),
|
|
2316
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2317
|
+
field2("name", utf82(), false),
|
|
2318
|
+
field2("schema_name", utf82(), false),
|
|
2319
|
+
field2("function_type", dictionary2(utf82(), int162()), false),
|
|
2320
|
+
field2("arguments", binary2(), false),
|
|
2321
|
+
field2("output_schema", binary2(), false),
|
|
2322
|
+
field2("stability", dictionary2(utf82(), int162()), true),
|
|
2323
|
+
field2("null_handling", dictionary2(utf82(), int162()), true),
|
|
2324
|
+
field2("description", utf82(), false),
|
|
2325
|
+
field2("examples", list2(field2("item", struct2([field2("sql", utf82(), false), field2("description", utf82(), false), field2("expected_output", utf82(), true)]), true)), false),
|
|
2326
|
+
field2("categories", list2(field2("item", utf82(), true)), false),
|
|
2327
|
+
field2("projection_pushdown", bool2(), true),
|
|
2328
|
+
field2("filter_pushdown", bool2(), true),
|
|
2329
|
+
field2("sampling_pushdown", bool2(), true),
|
|
2330
|
+
field2("late_materialization", bool2(), true),
|
|
2331
|
+
field2("supported_expression_filters", list2(field2("item", utf82(), true)), false),
|
|
2332
|
+
field2("order_preservation", dictionary2(utf82(), int162()), true),
|
|
2333
|
+
field2("max_workers", int322(), false),
|
|
2334
|
+
field2("supports_batch_index", bool2(), false),
|
|
2335
|
+
field2("partition_kind", dictionary2(utf82(), int162()), false),
|
|
2336
|
+
field2("order_dependent", dictionary2(utf82(), int162()), false),
|
|
2337
|
+
field2("distinct_dependent", dictionary2(utf82(), int162()), false),
|
|
2338
|
+
field2("supports_window", bool2(), false),
|
|
2339
|
+
field2("streaming_partitioned", bool2(), false),
|
|
2340
|
+
field2("has_finalize", bool2(), false),
|
|
2341
|
+
field2("source_order_dependent", bool2(), false),
|
|
2342
|
+
field2("sink_order_dependent", bool2(), false),
|
|
2343
|
+
field2("requires_input_batch_index", bool2(), false),
|
|
2344
|
+
field2("required_settings", list2(field2("item", utf82(), true)), false),
|
|
2345
|
+
field2("required_secrets", list2(field2("item", struct2([field2("secret_type", utf82(), false), field2("scope", utf82(), true), field2("secret_name", utf82(), true)]), true)), false)
|
|
2346
|
+
]);
|
|
2347
|
+
var MacroInfoSchema = schema2([
|
|
2348
|
+
field2("comment", utf82(), true),
|
|
2349
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2350
|
+
field2("name", utf82(), false),
|
|
2351
|
+
field2("schema_name", utf82(), false),
|
|
2352
|
+
field2("macro_type", dictionary2(utf82(), int162()), false),
|
|
2353
|
+
field2("parameters", list2(field2("item", utf82(), true)), false),
|
|
2354
|
+
field2("parameter_default_values", binary2(), false),
|
|
2355
|
+
field2("definition", utf82(), false),
|
|
2356
|
+
field2("arguments_schema", binary2(), false)
|
|
2357
|
+
]);
|
|
2358
|
+
var IndexInfoSchema = schema2([
|
|
2359
|
+
field2("comment", utf82(), true),
|
|
2360
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2361
|
+
field2("name", utf82(), false),
|
|
2362
|
+
field2("schema_name", utf82(), false),
|
|
2363
|
+
field2("table_name", utf82(), false),
|
|
2364
|
+
field2("index_type", utf82(), false),
|
|
2365
|
+
field2("constraint_type", dictionary2(utf82(), int162()), false),
|
|
2366
|
+
field2("expressions", list2(field2("item", utf82(), true)), false),
|
|
2367
|
+
field2("options", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false)
|
|
2368
|
+
]);
|
|
2369
|
+
var CopyFromFormatInfoSchema = schema2([
|
|
2370
|
+
field2("comment", utf82(), true),
|
|
2371
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2372
|
+
field2("format_name", utf82(), false),
|
|
2373
|
+
field2("handler", utf82(), false),
|
|
2374
|
+
field2("options", binary2(), false),
|
|
2375
|
+
field2("direction", utf82(), false),
|
|
2376
|
+
field2("description", utf82(), false),
|
|
2377
|
+
field2("ordered", bool2(), false)
|
|
2378
|
+
]);
|
|
2379
|
+
var ScanFunctionResultSchema = schema2([
|
|
2380
|
+
field2("function_name", utf82(), false),
|
|
2381
|
+
field2("arguments", binary2(), false),
|
|
2382
|
+
field2("required_extensions", list2(field2("item", utf82(), true)), false)
|
|
2383
|
+
]);
|
|
2384
|
+
var ScanBranchesResultSchema = schema2([
|
|
2385
|
+
field2("branches", list2(field2("item", binary2(), true)), false),
|
|
2386
|
+
field2("required_extensions", list2(field2("item", utf82(), true)), false)
|
|
2387
|
+
]);
|
|
2388
|
+
var ScanBranchSchema = schema2([
|
|
2389
|
+
field2("function_name", utf82(), false),
|
|
2390
|
+
field2("arguments", binary2(), false),
|
|
2391
|
+
field2("branch_filter", utf82(), true),
|
|
2392
|
+
field2("writable", bool2(), false),
|
|
2393
|
+
field2("source_catalog", utf82(), true),
|
|
2394
|
+
field2("source_schema", utf82(), true),
|
|
2395
|
+
field2("source_table", utf82(), true)
|
|
2396
|
+
]);
|
|
2397
|
+
var AttachCatalogInfoSchema = schema2([
|
|
2398
|
+
field2("alias", utf82(), false),
|
|
2399
|
+
field2("target", utf82(), false),
|
|
2400
|
+
field2("db_type", utf82(), false),
|
|
2401
|
+
field2("options", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2402
|
+
field2("hidden", bool2(), false),
|
|
2403
|
+
field2("required", bool2(), false),
|
|
2404
|
+
field2("secret_ref", utf82(), false)
|
|
2405
|
+
]);
|
|
2406
|
+
var AggregateBindResultSchema = schema2([
|
|
2407
|
+
field2("output_schema", binary2(), false),
|
|
2408
|
+
field2("execution_id", binary2(), false)
|
|
2409
|
+
]);
|
|
2410
|
+
var AggregateCombineResultSchema = schema2([]);
|
|
2411
|
+
var AggregateDestructorResultSchema = schema2([]);
|
|
2412
|
+
var AggregateFinalizeResultSchema = schema2([
|
|
2413
|
+
field2("result_batch", binary2(), false)
|
|
2414
|
+
]);
|
|
2415
|
+
var AggregateStreamingChunkResultSchema = schema2([
|
|
2416
|
+
field2("result_batch", binary2(), false)
|
|
2417
|
+
]);
|
|
2418
|
+
var AggregateStreamingCloseResultSchema = schema2([]);
|
|
2419
|
+
var AggregateStreamingOpenResultSchema = schema2([
|
|
2420
|
+
field2("execution_id", binary2(), false)
|
|
2421
|
+
]);
|
|
2422
|
+
var AggregateUpdateResultSchema = schema2([]);
|
|
2423
|
+
var AggregateWindowResultSchema = schema2([
|
|
2424
|
+
field2("result_batch", binary2(), false)
|
|
2425
|
+
]);
|
|
2426
|
+
var AggregateWindowBatchResultSchema = schema2([
|
|
2427
|
+
field2("result_batch", binary2(), false)
|
|
2428
|
+
]);
|
|
2429
|
+
var AggregateWindowDestructorResultSchema = schema2([]);
|
|
2430
|
+
var AggregateWindowInitResultSchema = schema2([]);
|
|
2431
|
+
var BindResultSchema = schema2([
|
|
2432
|
+
field2("output_schema", binary2(), false),
|
|
2433
|
+
field2("opaque_data", binary2(), false),
|
|
2434
|
+
field2("lookup_secret_types", list2(field2("item", utf82(), true)), false),
|
|
2435
|
+
field2("lookup_scopes", list2(field2("item", utf82(), true)), false),
|
|
2436
|
+
field2("lookup_names", list2(field2("item", utf82(), true)), false)
|
|
2437
|
+
]);
|
|
2438
|
+
var CatalogAttachResultSchema = schema2([
|
|
2439
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2440
|
+
field2("supports_transactions", bool2(), false),
|
|
2441
|
+
field2("supports_time_travel", bool2(), false),
|
|
2442
|
+
field2("catalog_version_frozen", bool2(), false),
|
|
2443
|
+
field2("catalog_version", int642(), false),
|
|
2444
|
+
field2("attach_opaque_data_required", bool2(), false),
|
|
2445
|
+
field2("default_schema", utf82(), false),
|
|
2446
|
+
field2("settings", list2(field2("item", binary2(), true)), false),
|
|
2447
|
+
field2("secret_types", list2(field2("item", binary2(), true)), false),
|
|
2448
|
+
field2("attach_catalogs", list2(field2("item", binary2(), true)), false),
|
|
2449
|
+
field2("comment", utf82(), true),
|
|
2450
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), false),
|
|
2451
|
+
field2("supports_column_statistics", bool2(), false),
|
|
2452
|
+
field2("resolved_data_version", utf82(), true),
|
|
2453
|
+
field2("resolved_implementation_version", utf82(), true)
|
|
2454
|
+
]);
|
|
2455
|
+
var CatalogCatalogsResultSchema = schema2([
|
|
2456
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2457
|
+
]);
|
|
2458
|
+
var CatalogCopyFromFormatsResultSchema = schema2([
|
|
2459
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2460
|
+
]);
|
|
2461
|
+
var CatalogIndexGetResultSchema = schema2([
|
|
2462
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2463
|
+
]);
|
|
2464
|
+
var CatalogMacroGetResultSchema = schema2([
|
|
2465
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2466
|
+
]);
|
|
2467
|
+
var CatalogSchemaContentsFunctionsResultSchema = schema2([
|
|
2468
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2469
|
+
]);
|
|
2470
|
+
var CatalogSchemaContentsIndexesResultSchema = schema2([
|
|
2471
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2472
|
+
]);
|
|
2473
|
+
var CatalogSchemaContentsMacrosResultSchema = schema2([
|
|
2474
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2475
|
+
]);
|
|
2476
|
+
var CatalogSchemaContentsTablesResultSchema = schema2([
|
|
2477
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2478
|
+
]);
|
|
2479
|
+
var CatalogSchemaContentsViewsResultSchema = schema2([
|
|
2480
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2481
|
+
]);
|
|
2482
|
+
var CatalogSchemaGetResultSchema = schema2([
|
|
2483
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2484
|
+
]);
|
|
2485
|
+
var CatalogSchemasResultSchema = schema2([
|
|
2486
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2487
|
+
]);
|
|
2488
|
+
var CatalogTableGetResultSchema = schema2([
|
|
2489
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2490
|
+
]);
|
|
2491
|
+
var CatalogTransactionBeginResultSchema = schema2([
|
|
2492
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2493
|
+
]);
|
|
2494
|
+
var CatalogVersionResultSchema = schema2([
|
|
2495
|
+
field2("version", int642(), false)
|
|
2496
|
+
]);
|
|
2497
|
+
var CatalogViewGetResultSchema = schema2([
|
|
2498
|
+
field2("items", list2(field2("item", binary2(), true)), false)
|
|
2499
|
+
]);
|
|
2500
|
+
var TableBufferingCombineResultSchema = schema2([
|
|
2501
|
+
field2("finalize_state_ids", list2(field2("item", binary2(), true)), false)
|
|
2502
|
+
]);
|
|
2503
|
+
var TableBufferingDestructorResultSchema = schema2([]);
|
|
2504
|
+
var TableBufferingProcessResultSchema = schema2([
|
|
2505
|
+
field2("state_id", binary2(), false)
|
|
2506
|
+
]);
|
|
2507
|
+
var TableFunctionCardinalityResultSchema = schema2([
|
|
2508
|
+
field2("estimate", int642(), true),
|
|
2509
|
+
field2("max", int642(), true)
|
|
2510
|
+
]);
|
|
2511
|
+
var TableFunctionDynamicToStringResultSchema = schema2([
|
|
2512
|
+
field2("keys", list2(field2("item", utf82(), true)), false),
|
|
2513
|
+
field2("values", list2(field2("item", utf82(), true)), false)
|
|
2514
|
+
]);
|
|
2515
|
+
var AggregateBindParamsSchema = schema2([
|
|
2516
|
+
field2("request", binary2(), false)
|
|
2517
|
+
]);
|
|
2518
|
+
var AggregateCombineParamsSchema = schema2([
|
|
2519
|
+
field2("request", binary2(), false)
|
|
2520
|
+
]);
|
|
2521
|
+
var AggregateDestructorParamsSchema = schema2([
|
|
2522
|
+
field2("request", binary2(), false)
|
|
2523
|
+
]);
|
|
2524
|
+
var AggregateFinalizeParamsSchema = schema2([
|
|
2525
|
+
field2("request", binary2(), false)
|
|
2526
|
+
]);
|
|
2527
|
+
var AggregateStreamingChunkParamsSchema = schema2([
|
|
2528
|
+
field2("request", binary2(), false)
|
|
2529
|
+
]);
|
|
2530
|
+
var AggregateStreamingCloseParamsSchema = schema2([
|
|
2531
|
+
field2("request", binary2(), false)
|
|
2532
|
+
]);
|
|
2533
|
+
var AggregateStreamingOpenParamsSchema = schema2([
|
|
2534
|
+
field2("request", binary2(), false)
|
|
2535
|
+
]);
|
|
2536
|
+
var AggregateUpdateParamsSchema = schema2([
|
|
2537
|
+
field2("request", binary2(), false)
|
|
2538
|
+
]);
|
|
2539
|
+
var AggregateWindowParamsSchema = schema2([
|
|
2540
|
+
field2("request", binary2(), false)
|
|
2541
|
+
]);
|
|
2542
|
+
var AggregateWindowBatchParamsSchema = schema2([
|
|
2543
|
+
field2("request", binary2(), false)
|
|
2544
|
+
]);
|
|
2545
|
+
var AggregateWindowDestructorParamsSchema = schema2([
|
|
2546
|
+
field2("request", binary2(), false)
|
|
2547
|
+
]);
|
|
2548
|
+
var AggregateWindowInitParamsSchema = schema2([
|
|
2549
|
+
field2("request", binary2(), false)
|
|
2550
|
+
]);
|
|
2551
|
+
var BindParamsSchema = schema2([
|
|
2552
|
+
field2("request", binary2(), false)
|
|
2553
|
+
]);
|
|
2554
|
+
var CatalogAttachParamsSchema = schema2([
|
|
2555
|
+
field2("request", binary2(), false)
|
|
2556
|
+
]);
|
|
2557
|
+
var CatalogCatalogsParamsSchema = schema2([]);
|
|
2558
|
+
var CatalogCopyFromFormatsParamsSchema = schema2([
|
|
2559
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2560
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2561
|
+
]);
|
|
2562
|
+
var CatalogCreateParamsSchema = schema2([
|
|
2563
|
+
field2("request", binary2(), false)
|
|
2564
|
+
]);
|
|
2565
|
+
var CatalogDetachParamsSchema = schema2([
|
|
2566
|
+
field2("attach_opaque_data", binary2(), false)
|
|
2567
|
+
]);
|
|
2568
|
+
var CatalogDropParamsSchema = schema2([
|
|
2569
|
+
field2("name", utf82(), false)
|
|
2570
|
+
]);
|
|
2571
|
+
var CatalogIndexCreateParamsSchema = schema2([
|
|
2572
|
+
field2("request", binary2(), false)
|
|
2573
|
+
]);
|
|
2574
|
+
var CatalogIndexDropParamsSchema = schema2([
|
|
2575
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2576
|
+
field2("schema_name", utf82(), false),
|
|
2577
|
+
field2("name", utf82(), false),
|
|
2578
|
+
field2("ignore_not_found", bool2(), false),
|
|
2579
|
+
field2("cascade", bool2(), false),
|
|
2580
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2581
|
+
]);
|
|
2582
|
+
var CatalogIndexGetParamsSchema = schema2([
|
|
2583
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2584
|
+
field2("schema_name", utf82(), false),
|
|
2585
|
+
field2("name", utf82(), false),
|
|
2586
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2587
|
+
]);
|
|
2588
|
+
var CatalogMacroCreateParamsSchema = schema2([
|
|
2589
|
+
field2("request", binary2(), false)
|
|
2590
|
+
]);
|
|
2591
|
+
var CatalogMacroDropParamsSchema = schema2([
|
|
2592
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2593
|
+
field2("schema_name", utf82(), false),
|
|
2594
|
+
field2("name", utf82(), false),
|
|
2595
|
+
field2("ignore_not_found", bool2(), false),
|
|
2596
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2597
|
+
]);
|
|
2598
|
+
var CatalogMacroGetParamsSchema = schema2([
|
|
2599
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2600
|
+
field2("schema_name", utf82(), false),
|
|
2601
|
+
field2("name", utf82(), false),
|
|
2602
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2603
|
+
]);
|
|
2604
|
+
var CatalogSchemaContentsFunctionsParamsSchema = schema2([
|
|
2605
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2606
|
+
field2("name", utf82(), false),
|
|
2607
|
+
field2("type", dictionary2(utf82(), int162()), false),
|
|
2608
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2609
|
+
]);
|
|
2610
|
+
var CatalogSchemaContentsIndexesParamsSchema = schema2([
|
|
2611
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2612
|
+
field2("name", utf82(), false),
|
|
2613
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2614
|
+
]);
|
|
2615
|
+
var CatalogSchemaContentsMacrosParamsSchema = schema2([
|
|
2616
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2617
|
+
field2("name", utf82(), false),
|
|
2618
|
+
field2("type", dictionary2(utf82(), int162()), false),
|
|
2619
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2620
|
+
]);
|
|
2621
|
+
var CatalogSchemaContentsTablesParamsSchema = schema2([
|
|
2622
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2623
|
+
field2("name", utf82(), false),
|
|
2624
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2625
|
+
]);
|
|
2626
|
+
var CatalogSchemaContentsViewsParamsSchema = schema2([
|
|
2627
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2628
|
+
field2("name", utf82(), false),
|
|
2629
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2630
|
+
]);
|
|
2631
|
+
var CatalogSchemaCreateParamsSchema = schema2([
|
|
2632
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2633
|
+
field2("name", utf82(), false),
|
|
2634
|
+
field2("on_conflict", dictionary2(utf82(), int162()), false),
|
|
2635
|
+
field2("comment", utf82(), true),
|
|
2636
|
+
field2("tags", map2(field2("key", utf82(), false), field2("value", utf82(), true), false), true),
|
|
2637
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2638
|
+
]);
|
|
2639
|
+
var CatalogSchemaDropParamsSchema = schema2([
|
|
2640
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2641
|
+
field2("name", utf82(), false),
|
|
2642
|
+
field2("ignore_not_found", bool2(), false),
|
|
2643
|
+
field2("cascade", bool2(), false),
|
|
2644
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2645
|
+
]);
|
|
2646
|
+
var CatalogSchemaGetParamsSchema = schema2([
|
|
2647
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2648
|
+
field2("name", utf82(), false),
|
|
2649
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2650
|
+
]);
|
|
2651
|
+
var CatalogSchemasParamsSchema = schema2([
|
|
2652
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2653
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2654
|
+
]);
|
|
2655
|
+
var CatalogTableColumnAddParamsSchema = schema2([
|
|
2656
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2657
|
+
field2("schema_name", utf82(), false),
|
|
2658
|
+
field2("name", utf82(), false),
|
|
2659
|
+
field2("column_definition", binary2(), false),
|
|
2660
|
+
field2("ignore_not_found", bool2(), false),
|
|
2661
|
+
field2("if_column_not_exists", bool2(), false),
|
|
2662
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2663
|
+
]);
|
|
2664
|
+
var CatalogTableColumnCommentSetParamsSchema = schema2([
|
|
2665
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2666
|
+
field2("schema_name", utf82(), false),
|
|
2667
|
+
field2("name", utf82(), false),
|
|
2668
|
+
field2("column_name", utf82(), false),
|
|
2669
|
+
field2("comment", utf82(), true),
|
|
2670
|
+
field2("ignore_not_found", bool2(), false),
|
|
2671
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2672
|
+
]);
|
|
2673
|
+
var CatalogTableColumnDefaultDropParamsSchema = schema2([
|
|
2674
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2675
|
+
field2("schema_name", utf82(), false),
|
|
2676
|
+
field2("name", utf82(), false),
|
|
2677
|
+
field2("column_name", utf82(), false),
|
|
2678
|
+
field2("ignore_not_found", bool2(), false),
|
|
2679
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2680
|
+
]);
|
|
2681
|
+
var CatalogTableColumnDefaultSetParamsSchema = schema2([
|
|
2682
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2683
|
+
field2("schema_name", utf82(), false),
|
|
2684
|
+
field2("name", utf82(), false),
|
|
2685
|
+
field2("column_name", utf82(), false),
|
|
2686
|
+
field2("expression", utf82(), false),
|
|
2687
|
+
field2("ignore_not_found", bool2(), false),
|
|
2688
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2689
|
+
]);
|
|
2690
|
+
var CatalogTableColumnDropParamsSchema = schema2([
|
|
2691
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2692
|
+
field2("schema_name", utf82(), false),
|
|
2693
|
+
field2("name", utf82(), false),
|
|
2694
|
+
field2("column_name", utf82(), false),
|
|
2695
|
+
field2("ignore_not_found", bool2(), false),
|
|
2696
|
+
field2("if_column_exists", bool2(), false),
|
|
2697
|
+
field2("cascade", bool2(), false),
|
|
2698
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2699
|
+
]);
|
|
2700
|
+
var CatalogTableColumnRenameParamsSchema = schema2([
|
|
2701
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2702
|
+
field2("schema_name", utf82(), false),
|
|
2703
|
+
field2("name", utf82(), false),
|
|
2704
|
+
field2("column_name", utf82(), false),
|
|
2705
|
+
field2("new_column_name", utf82(), false),
|
|
2706
|
+
field2("ignore_not_found", bool2(), false),
|
|
2707
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2708
|
+
]);
|
|
2709
|
+
var CatalogTableColumnStatisticsGetParamsSchema = schema2([
|
|
2710
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2711
|
+
field2("schema_name", utf82(), false),
|
|
2712
|
+
field2("name", utf82(), false),
|
|
2713
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2714
|
+
]);
|
|
2715
|
+
var CatalogTableColumnTypeChangeParamsSchema = schema2([
|
|
2716
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2717
|
+
field2("schema_name", utf82(), false),
|
|
2718
|
+
field2("name", utf82(), false),
|
|
2719
|
+
field2("column_definition", binary2(), false),
|
|
2720
|
+
field2("expression", utf82(), true),
|
|
2721
|
+
field2("ignore_not_found", bool2(), false),
|
|
2722
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2723
|
+
]);
|
|
2724
|
+
var CatalogTableCommentSetParamsSchema = schema2([
|
|
2725
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2726
|
+
field2("schema_name", utf82(), false),
|
|
2727
|
+
field2("name", utf82(), false),
|
|
2728
|
+
field2("comment", utf82(), true),
|
|
2729
|
+
field2("ignore_not_found", bool2(), false),
|
|
2730
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2731
|
+
]);
|
|
2732
|
+
var CatalogTableCreateParamsSchema = schema2([
|
|
2733
|
+
field2("request", binary2(), false)
|
|
2734
|
+
]);
|
|
2735
|
+
var CatalogTableDeleteFunctionGetParamsSchema = schema2([
|
|
2736
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2737
|
+
field2("schema_name", utf82(), false),
|
|
2738
|
+
field2("name", utf82(), false),
|
|
2739
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2740
|
+
]);
|
|
2741
|
+
var CatalogTableDropParamsSchema = schema2([
|
|
2742
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2743
|
+
field2("schema_name", utf82(), false),
|
|
2744
|
+
field2("name", utf82(), false),
|
|
2745
|
+
field2("ignore_not_found", bool2(), false),
|
|
2746
|
+
field2("cascade", bool2(), false),
|
|
2747
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2748
|
+
]);
|
|
2749
|
+
var CatalogTableGetParamsSchema = schema2([
|
|
2750
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2751
|
+
field2("schema_name", utf82(), false),
|
|
2752
|
+
field2("name", utf82(), false),
|
|
2753
|
+
field2("at_unit", utf82(), true),
|
|
2754
|
+
field2("at_value", utf82(), true),
|
|
2755
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2756
|
+
]);
|
|
2757
|
+
var CatalogTableInsertFunctionGetParamsSchema = schema2([
|
|
2758
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2759
|
+
field2("schema_name", utf82(), false),
|
|
2760
|
+
field2("name", utf82(), false),
|
|
2761
|
+
field2("transaction_opaque_data", binary2(), true),
|
|
2762
|
+
field2("writable_branch_function_name", utf82(), true)
|
|
2763
|
+
]);
|
|
2764
|
+
var CatalogTableNotNullDropParamsSchema = schema2([
|
|
2765
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2766
|
+
field2("schema_name", utf82(), false),
|
|
2767
|
+
field2("name", utf82(), false),
|
|
2768
|
+
field2("column_name", utf82(), false),
|
|
2769
|
+
field2("ignore_not_found", bool2(), false),
|
|
2770
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2771
|
+
]);
|
|
2772
|
+
var CatalogTableNotNullSetParamsSchema = schema2([
|
|
2773
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2774
|
+
field2("schema_name", utf82(), false),
|
|
2775
|
+
field2("name", utf82(), false),
|
|
2776
|
+
field2("column_name", utf82(), false),
|
|
2777
|
+
field2("ignore_not_found", bool2(), false),
|
|
2778
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2779
|
+
]);
|
|
2780
|
+
var CatalogTableRenameParamsSchema = schema2([
|
|
2781
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2782
|
+
field2("schema_name", utf82(), false),
|
|
2783
|
+
field2("name", utf82(), false),
|
|
2784
|
+
field2("new_name", utf82(), false),
|
|
2785
|
+
field2("ignore_not_found", bool2(), false),
|
|
2786
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2787
|
+
]);
|
|
2788
|
+
var CatalogTableScanBranchesGetParamsSchema = schema2([
|
|
2789
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2790
|
+
field2("schema_name", utf82(), false),
|
|
2791
|
+
field2("name", utf82(), false),
|
|
2792
|
+
field2("at_unit", utf82(), true),
|
|
2793
|
+
field2("at_value", utf82(), true),
|
|
2794
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2795
|
+
]);
|
|
2796
|
+
var CatalogTableScanFunctionGetParamsSchema = schema2([
|
|
2797
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2798
|
+
field2("schema_name", utf82(), false),
|
|
2799
|
+
field2("name", utf82(), false),
|
|
2800
|
+
field2("at_unit", utf82(), true),
|
|
2801
|
+
field2("at_value", utf82(), true),
|
|
2802
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2803
|
+
]);
|
|
2804
|
+
var CatalogTableUpdateFunctionGetParamsSchema = schema2([
|
|
2805
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2806
|
+
field2("schema_name", utf82(), false),
|
|
2807
|
+
field2("name", utf82(), false),
|
|
2808
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2809
|
+
]);
|
|
2810
|
+
var CatalogTransactionBeginParamsSchema = schema2([
|
|
2811
|
+
field2("attach_opaque_data", binary2(), false)
|
|
2812
|
+
]);
|
|
2813
|
+
var CatalogTransactionCommitParamsSchema = schema2([
|
|
2814
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2815
|
+
field2("transaction_opaque_data", binary2(), false)
|
|
2816
|
+
]);
|
|
2817
|
+
var CatalogTransactionRollbackParamsSchema = schema2([
|
|
2818
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2819
|
+
field2("transaction_opaque_data", binary2(), false)
|
|
2820
|
+
]);
|
|
2821
|
+
var CatalogVersionParamsSchema = schema2([
|
|
2822
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2823
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2824
|
+
]);
|
|
2825
|
+
var CatalogViewCommentSetParamsSchema = schema2([
|
|
2826
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2827
|
+
field2("schema_name", utf82(), false),
|
|
2828
|
+
field2("name", utf82(), false),
|
|
2829
|
+
field2("comment", utf82(), true),
|
|
2830
|
+
field2("ignore_not_found", bool2(), false),
|
|
2831
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2832
|
+
]);
|
|
2833
|
+
var CatalogViewCreateParamsSchema = schema2([
|
|
2834
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2835
|
+
field2("schema_name", utf82(), false),
|
|
2836
|
+
field2("name", utf82(), false),
|
|
2837
|
+
field2("definition", utf82(), false),
|
|
2838
|
+
field2("on_conflict", dictionary2(utf82(), int162()), false),
|
|
2839
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2840
|
+
]);
|
|
2841
|
+
var CatalogViewDropParamsSchema = schema2([
|
|
2842
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2843
|
+
field2("schema_name", utf82(), false),
|
|
2844
|
+
field2("name", utf82(), false),
|
|
2845
|
+
field2("ignore_not_found", bool2(), false),
|
|
2846
|
+
field2("cascade", bool2(), false),
|
|
2847
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2848
|
+
]);
|
|
2849
|
+
var CatalogViewGetParamsSchema = schema2([
|
|
2850
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2851
|
+
field2("schema_name", utf82(), false),
|
|
2852
|
+
field2("name", utf82(), false),
|
|
2853
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2854
|
+
]);
|
|
2855
|
+
var CatalogViewRenameParamsSchema = schema2([
|
|
2856
|
+
field2("attach_opaque_data", binary2(), false),
|
|
2857
|
+
field2("schema_name", utf82(), false),
|
|
2858
|
+
field2("name", utf82(), false),
|
|
2859
|
+
field2("new_name", utf82(), false),
|
|
2860
|
+
field2("ignore_not_found", bool2(), false),
|
|
2861
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
2862
|
+
]);
|
|
2863
|
+
var InitParamsSchema = schema2([
|
|
2864
|
+
field2("request", binary2(), false)
|
|
2865
|
+
]);
|
|
2866
|
+
var TableBufferingCombineParamsSchema = schema2([
|
|
2867
|
+
field2("request", binary2(), false)
|
|
2868
|
+
]);
|
|
2869
|
+
var TableBufferingDestructorParamsSchema = schema2([
|
|
2870
|
+
field2("request", binary2(), false)
|
|
2871
|
+
]);
|
|
2872
|
+
var TableBufferingProcessParamsSchema = schema2([
|
|
2873
|
+
field2("request", binary2(), false)
|
|
2874
|
+
]);
|
|
2875
|
+
var TableFunctionCardinalityParamsSchema = schema2([
|
|
2876
|
+
field2("request", binary2(), false)
|
|
2877
|
+
]);
|
|
2878
|
+
var TableFunctionDynamicToStringParamsSchema = schema2([
|
|
2879
|
+
field2("request", binary2(), false)
|
|
2880
|
+
]);
|
|
2881
|
+
var TableFunctionStatisticsParamsSchema = schema2([
|
|
2882
|
+
field2("request", binary2(), false)
|
|
2883
|
+
]);
|
|
2884
|
+
|
|
2885
|
+
// src/generated/vgi-client.ts
|
|
2886
|
+
var decodeCatalogInfo = (b) => decodeASD(CatalogInfoSchema, b);
|
|
2887
|
+
var encodeFunctionInfo = (v) => encodeASD(FunctionInfoSchema, v);
|
|
2888
|
+
var decodeFunctionInfo = (b) => decodeASD(FunctionInfoSchema, b);
|
|
2889
|
+
var encodeMacroInfo = (v) => encodeASD(MacroInfoSchema, v);
|
|
2890
|
+
var decodeMacroInfo = (b) => decodeASD(MacroInfoSchema, b);
|
|
2891
|
+
var encodeSchemaInfo = (v) => encodeASD(SchemaInfoSchema, v);
|
|
2892
|
+
var decodeSchemaInfo = (b) => decodeASD(SchemaInfoSchema, b);
|
|
2893
|
+
var encodeTableInfo = (v) => encodeASD(TableInfoSchema, v);
|
|
2894
|
+
var decodeTableInfo = (b) => decodeASD(TableInfoSchema, b);
|
|
2895
|
+
var encodeViewInfo = (v) => encodeASD(ViewInfoSchema, v);
|
|
2896
|
+
var decodeViewInfo = (b) => decodeASD(ViewInfoSchema, b);
|
|
2897
|
+
// src/catalog/interface.ts
|
|
2898
|
+
function decodeScanFunctionResult(inner) {
|
|
2899
|
+
const argsBytes = inner.arguments;
|
|
2900
|
+
const positionalArguments = [];
|
|
2901
|
+
const namedArguments = {};
|
|
2902
|
+
if (argsBytes != null) {
|
|
2903
|
+
const batch = deserializeBatch(toUint8Array(argsBytes));
|
|
2904
|
+
for (const field3 of batch.schema.fields) {
|
|
2905
|
+
const col = batch.getChild(field3.name);
|
|
2906
|
+
const value = col ? col.get(0) : null;
|
|
2907
|
+
if (field3.name.startsWith("arg_")) {
|
|
2908
|
+
const idx = parseInt(field3.name.slice(4), 10);
|
|
2909
|
+
while (positionalArguments.length <= idx)
|
|
2910
|
+
positionalArguments.push(null);
|
|
2911
|
+
positionalArguments[idx] = value;
|
|
2912
|
+
} else {
|
|
2913
|
+
namedArguments[field3.name] = value;
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
const exts = inner.required_extensions;
|
|
2918
|
+
const requiredExtensions = exts == null ? [] : (Array.isArray(exts) ? exts : [...exts]).filter((v) => v != null).map(String);
|
|
2919
|
+
return {
|
|
2920
|
+
functionName: String(inner.function_name ?? ""),
|
|
2921
|
+
positionalArguments,
|
|
2922
|
+
namedArguments,
|
|
2923
|
+
requiredExtensions
|
|
2924
|
+
};
|
|
2925
|
+
}
|
|
2926
|
+
|
|
2927
|
+
// src/client/protocol.ts
|
|
2928
|
+
function wrapRequest(batch) {
|
|
2929
|
+
return { request: serializeBatch(batch) };
|
|
2930
|
+
}
|
|
2931
|
+
function unwrapResult(result) {
|
|
2932
|
+
const resultBytes = toUint8Array(result.result);
|
|
2933
|
+
const innerBatch = deserializeBatch(resultBytes);
|
|
2934
|
+
return batchToScalarDict(innerBatch);
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
// src/catalog/attach-options.ts
|
|
2938
|
+
function inferAttachOptionArrowType(value) {
|
|
2939
|
+
if (value === null)
|
|
2940
|
+
return nullType2();
|
|
2941
|
+
if (typeof value === "string")
|
|
2942
|
+
return utf82();
|
|
2943
|
+
if (typeof value === "bigint")
|
|
2944
|
+
return int642();
|
|
2945
|
+
if (typeof value === "number") {
|
|
2946
|
+
if (!Number.isFinite(value)) {
|
|
2947
|
+
throw new TypeError(`Attach option number values must be finite (got ${value}). ` + `Use a bigint for integers or a finite number for floats.`);
|
|
2948
|
+
}
|
|
2949
|
+
return float642();
|
|
2950
|
+
}
|
|
2951
|
+
if (typeof value === "boolean")
|
|
2952
|
+
return bool2();
|
|
2953
|
+
if (value instanceof Uint8Array)
|
|
2954
|
+
return binary2();
|
|
2955
|
+
throw new TypeError(`Unsupported attach option value type: ${typeof value}. ` + `Supported: string, number, bigint, boolean, null, Uint8Array.`);
|
|
2956
|
+
}
|
|
2957
|
+
function serializeAttachOptions(options) {
|
|
2958
|
+
if (!options)
|
|
2959
|
+
return null;
|
|
2960
|
+
const entries = Object.entries(options);
|
|
2961
|
+
if (entries.length === 0)
|
|
2962
|
+
return null;
|
|
2963
|
+
const fields = [];
|
|
2964
|
+
const columns = {};
|
|
2965
|
+
for (const [key, value] of entries) {
|
|
2966
|
+
const type = inferAttachOptionArrowType(value);
|
|
2967
|
+
fields.push(field2(key, type, true));
|
|
2968
|
+
columns[key] = [value];
|
|
2969
|
+
}
|
|
2970
|
+
const schema3 = schema2(fields);
|
|
2971
|
+
const batch = batchFromColumns(columns, schema3);
|
|
2972
|
+
return serializeBatch(batch);
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
// src/client/errors.ts
|
|
2976
|
+
import { RpcError } from "@query-farm/vgi-rpc";
|
|
2977
|
+
|
|
2978
|
+
class VgiClientError extends Error {
|
|
2979
|
+
remoteTraceback;
|
|
2980
|
+
errorType;
|
|
2981
|
+
constructor(message, options) {
|
|
2982
|
+
super(message, options?.cause != null ? { cause: options.cause } : undefined);
|
|
2983
|
+
this.name = "VgiClientError";
|
|
2984
|
+
if (options?.remoteTraceback)
|
|
2985
|
+
this.remoteTraceback = options.remoteTraceback;
|
|
2986
|
+
if (options?.errorType)
|
|
2987
|
+
this.errorType = options.errorType;
|
|
2988
|
+
}
|
|
2989
|
+
static fromRpcError(e) {
|
|
2990
|
+
const head = `${e.errorType}: ${e.errorMessage}`;
|
|
2991
|
+
const message = e.remoteTraceback ? `${head}
|
|
2992
|
+
|
|
2993
|
+
Remote traceback:
|
|
2994
|
+
${e.remoteTraceback}` : head;
|
|
2995
|
+
return new VgiClientError(message, {
|
|
2996
|
+
remoteTraceback: e.remoteTraceback || undefined,
|
|
2997
|
+
errorType: e.errorType,
|
|
2998
|
+
cause: e
|
|
2999
|
+
});
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
function wrapRpcWithErrorEnrichment(rpc) {
|
|
3003
|
+
return {
|
|
3004
|
+
async call(method, params) {
|
|
3005
|
+
try {
|
|
3006
|
+
return await rpc.call(method, params);
|
|
3007
|
+
} catch (e) {
|
|
3008
|
+
if (e instanceof RpcError)
|
|
3009
|
+
throw VgiClientError.fromRpcError(e);
|
|
3010
|
+
throw e;
|
|
3011
|
+
}
|
|
3012
|
+
},
|
|
3013
|
+
async stream(method, params) {
|
|
3014
|
+
try {
|
|
3015
|
+
return await rpc.stream(method, params);
|
|
3016
|
+
} catch (e) {
|
|
3017
|
+
if (e instanceof RpcError)
|
|
3018
|
+
throw VgiClientError.fromRpcError(e);
|
|
3019
|
+
throw e;
|
|
3020
|
+
}
|
|
3021
|
+
},
|
|
3022
|
+
describe: () => rpc.describe(),
|
|
3023
|
+
close: () => rpc.close()
|
|
3024
|
+
};
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
// src/client/helpers.ts
|
|
3028
|
+
function deserializeInfoList(items, deserializeFn) {
|
|
3029
|
+
if (!items)
|
|
3030
|
+
return [];
|
|
3031
|
+
const arr = Array.isArray(items) ? items : [...items];
|
|
3032
|
+
return arr.filter((b) => b != null).map((b) => deserializeFn(toUint8Array(b)));
|
|
3033
|
+
}
|
|
3034
|
+
function deserializeTags(mapVal) {
|
|
3035
|
+
const tags = {};
|
|
3036
|
+
if (!mapVal)
|
|
3037
|
+
return tags;
|
|
3038
|
+
const iterable = mapVal;
|
|
3039
|
+
if (typeof iterable[Symbol.iterator] !== "function")
|
|
3040
|
+
return tags;
|
|
3041
|
+
for (const entry of iterable) {
|
|
3042
|
+
if (Array.isArray(entry)) {
|
|
3043
|
+
tags[String(entry[0])] = String(entry[1]);
|
|
3044
|
+
} else if (entry && typeof entry === "object") {
|
|
3045
|
+
const e = entry;
|
|
3046
|
+
tags[String(e.key ?? e[0] ?? "")] = String(e.value ?? e[1] ?? "");
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
return tags;
|
|
3050
|
+
}
|
|
3051
|
+
function toAsyncIterator(input) {
|
|
3052
|
+
if (Symbol.asyncIterator in input) {
|
|
3053
|
+
return input[Symbol.asyncIterator]();
|
|
3054
|
+
}
|
|
3055
|
+
const syncIter = input[Symbol.iterator]();
|
|
3056
|
+
return {
|
|
3057
|
+
async next() {
|
|
3058
|
+
return syncIter.next();
|
|
3059
|
+
}
|
|
3060
|
+
};
|
|
3061
|
+
}
|
|
3062
|
+
|
|
3063
|
+
// src/client/client.ts
|
|
3064
|
+
class VgiClient {
|
|
3065
|
+
rpc;
|
|
3066
|
+
defaultAttachOpaqueData;
|
|
3067
|
+
constructor(rpc, options) {
|
|
3068
|
+
this.rpc = wrapRpcWithErrorEnrichment(rpc);
|
|
3069
|
+
this.defaultAttachOpaqueData = options?.attachOpaqueData ?? null;
|
|
3070
|
+
}
|
|
3071
|
+
async _doBind(functionName, functionType, args, inputSchema, settings, secrets, transactionOpaqueData, attachOpaqueData = null, onBind) {
|
|
3072
|
+
const request = {
|
|
3073
|
+
function_name: functionName,
|
|
3074
|
+
arguments: args,
|
|
3075
|
+
function_type: functionType,
|
|
3076
|
+
input_schema: inputSchema,
|
|
3077
|
+
settings: settings ?? null,
|
|
3078
|
+
secrets: secrets ?? null,
|
|
3079
|
+
attach_opaque_data: attachOpaqueData ?? this.defaultAttachOpaqueData,
|
|
3080
|
+
transaction_opaque_data: transactionOpaqueData ?? null,
|
|
3081
|
+
resolved_secrets_provided: false
|
|
3082
|
+
};
|
|
3083
|
+
const requestBatch = serializeBindRequest(request);
|
|
3084
|
+
const rpcResult = await this.rpc.call("bind", wrapRequest(requestBatch));
|
|
3085
|
+
if (!rpcResult)
|
|
3086
|
+
throw new VgiClientError("bind returned null");
|
|
3087
|
+
const inner = unwrapResult(rpcResult);
|
|
3088
|
+
const response = deserializeBindResponse(inner);
|
|
3089
|
+
if (onBind)
|
|
3090
|
+
onBind(response);
|
|
3091
|
+
return { request, response };
|
|
3092
|
+
}
|
|
3093
|
+
async _doInit(bindRequest, bindResponse, opts) {
|
|
3094
|
+
const ob = opts?.orderBy ?? null;
|
|
3095
|
+
const ts = opts?.tablesample ?? null;
|
|
3096
|
+
const initRequest = {
|
|
3097
|
+
bind_call: bindRequest,
|
|
3098
|
+
output_schema: bindResponse.output_schema,
|
|
3099
|
+
bind_opaque_data: bindResponse.opaque_data,
|
|
3100
|
+
projection_ids: opts?.projectionIds ?? null,
|
|
3101
|
+
pushdown_filters: opts?.pushdownFilters ?? null,
|
|
3102
|
+
join_keys: opts?.joinKeys ?? [],
|
|
3103
|
+
phase: opts?.phase ?? null,
|
|
3104
|
+
finalize_state_id: null,
|
|
3105
|
+
order_by_column_name: ob?.columnName ?? null,
|
|
3106
|
+
order_by_direction: ob?.direction ?? null,
|
|
3107
|
+
order_by_null_order: ob?.nullOrder ?? null,
|
|
3108
|
+
order_by_limit: ob?.limit == null ? null : BigInt(ob.limit),
|
|
3109
|
+
tablesample_percentage: ts?.percentage ?? null,
|
|
3110
|
+
tablesample_seed: ts?.seed == null ? null : BigInt(ts.seed),
|
|
3111
|
+
execution_id: opts?.executionId ?? null,
|
|
3112
|
+
init_opaque_data: null
|
|
3113
|
+
};
|
|
3114
|
+
const initBatch = serializeInitRequest(initRequest);
|
|
3115
|
+
const session = await this.rpc.stream("init", wrapRequest(initBatch));
|
|
3116
|
+
const headerDict = session.header;
|
|
3117
|
+
if (!headerDict)
|
|
3118
|
+
throw new VgiClientError("init did not return a header");
|
|
3119
|
+
const initResponse = deserializeGlobalInitResponse(headerDict);
|
|
3120
|
+
return { session, initResponse };
|
|
3121
|
+
}
|
|
3122
|
+
async* tableFunction(opts) {
|
|
3123
|
+
const args = opts.arguments ?? new Arguments;
|
|
3124
|
+
const { request: bindReq, response: bindResp } = await this._doBind(opts.functionName, "table" /* TABLE */, args, null, opts.settings ?? null, null, opts.transactionOpaqueData ?? null, opts.attachOpaqueData ?? null, opts.onBind ?? null);
|
|
3125
|
+
const { session } = await this._doInit(bindReq, bindResp, {
|
|
3126
|
+
projectionIds: opts.projectionIds,
|
|
3127
|
+
pushdownFilters: opts.pushdownFilters,
|
|
3128
|
+
orderBy: opts.orderBy,
|
|
3129
|
+
tablesample: opts.tablesample,
|
|
3130
|
+
joinKeys: opts.joinKeys
|
|
3131
|
+
});
|
|
3132
|
+
const outputSchema = bindResp.output_schema;
|
|
3133
|
+
try {
|
|
3134
|
+
for await (const rows of session) {
|
|
3135
|
+
if (rows.length > 0) {
|
|
3136
|
+
yield batchFromRows(rows, outputSchema);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
} finally {
|
|
3140
|
+
session.close();
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
async* scalarFunctionRows(opts) {
|
|
3144
|
+
const inputIter = toAsyncIterator(opts.input);
|
|
3145
|
+
const first = await inputIter.next();
|
|
3146
|
+
if (first.done) {
|
|
3147
|
+
throw new VgiClientError(`scalarFunction(${opts.functionName}): input iterator yielded no batches; ` + `at least one batch is required to determine the input schema`);
|
|
3148
|
+
}
|
|
3149
|
+
const firstBatch = first.value;
|
|
3150
|
+
const inputSchema = firstBatch.schema;
|
|
3151
|
+
const args = opts.arguments ?? new Arguments;
|
|
3152
|
+
const { request: bindReq, response: bindResp } = await this._doBind(opts.functionName, "scalar" /* SCALAR */, args, inputSchema, opts.settings ?? null, opts.secrets ?? null, opts.transactionOpaqueData ?? null, opts.attachOpaqueData ?? null, opts.onBind ?? null);
|
|
3153
|
+
const { session } = await this._doInit(bindReq, bindResp);
|
|
3154
|
+
try {
|
|
3155
|
+
const outRows = await session.exchange([...iterRows(firstBatch)]);
|
|
3156
|
+
if (outRows.length > 0)
|
|
3157
|
+
yield outRows;
|
|
3158
|
+
for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
|
|
3159
|
+
const result = await session.exchange([...iterRows(batch)]);
|
|
3160
|
+
if (result.length > 0)
|
|
3161
|
+
yield result;
|
|
3162
|
+
}
|
|
3163
|
+
} finally {
|
|
3164
|
+
session.close();
|
|
3165
|
+
}
|
|
3166
|
+
}
|
|
3167
|
+
async* scalarFunction(opts) {
|
|
3168
|
+
const inputIter = toAsyncIterator(opts.input);
|
|
3169
|
+
const first = await inputIter.next();
|
|
3170
|
+
if (first.done) {
|
|
3171
|
+
throw new VgiClientError(`scalarFunction(${opts.functionName}): input iterator yielded no batches; ` + `at least one batch is required to determine the input schema`);
|
|
3172
|
+
}
|
|
3173
|
+
const firstBatch = first.value;
|
|
3174
|
+
const inputSchema = firstBatch.schema;
|
|
3175
|
+
const args = opts.arguments ?? new Arguments;
|
|
3176
|
+
const { request: bindReq, response: bindResp } = await this._doBind(opts.functionName, "scalar" /* SCALAR */, args, inputSchema, opts.settings ?? null, opts.secrets ?? null, opts.transactionOpaqueData ?? null, opts.attachOpaqueData ?? null, opts.onBind ?? null);
|
|
3177
|
+
const { session } = await this._doInit(bindReq, bindResp);
|
|
3178
|
+
const outputSchema = bindResp.output_schema;
|
|
3179
|
+
try {
|
|
3180
|
+
const outRows = await session.exchange([...iterRows(firstBatch)]);
|
|
3181
|
+
if (outRows.length > 0)
|
|
3182
|
+
yield batchFromRows(outRows, outputSchema);
|
|
3183
|
+
for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
|
|
3184
|
+
const result = await session.exchange([...iterRows(batch)]);
|
|
3185
|
+
if (result.length > 0)
|
|
3186
|
+
yield batchFromRows(result, outputSchema);
|
|
3187
|
+
}
|
|
3188
|
+
} finally {
|
|
3189
|
+
session.close();
|
|
3190
|
+
}
|
|
3191
|
+
}
|
|
3192
|
+
async* tableInOutFunctionRows(opts) {
|
|
3193
|
+
const inputIter = toAsyncIterator(opts.input);
|
|
3194
|
+
const first = await inputIter.next();
|
|
3195
|
+
if (first.done) {
|
|
3196
|
+
throw new VgiClientError(`tableInOutFunction(${opts.functionName}): input iterator yielded no batches; ` + `at least one batch is required to determine the input schema`);
|
|
3197
|
+
}
|
|
3198
|
+
const firstBatch = first.value;
|
|
3199
|
+
const inputSchema = firstBatch.schema;
|
|
3200
|
+
const args = opts.arguments ?? new Arguments;
|
|
3201
|
+
const { request: bindReq, response: bindResp } = await this._doBind(opts.functionName, "table" /* TABLE */, args, inputSchema, opts.settings ?? null, null, opts.transactionOpaqueData ?? null, opts.attachOpaqueData ?? null, opts.onBind ?? null);
|
|
3202
|
+
const { session: inputSession, initResponse } = await this._doInit(bindReq, bindResp, {
|
|
3203
|
+
projectionIds: opts.projectionIds,
|
|
3204
|
+
pushdownFilters: opts.pushdownFilters,
|
|
3205
|
+
phase: "INPUT" /* INPUT */,
|
|
3206
|
+
orderBy: opts.orderBy,
|
|
3207
|
+
tablesample: opts.tablesample,
|
|
3208
|
+
joinKeys: opts.joinKeys
|
|
3209
|
+
});
|
|
3210
|
+
try {
|
|
3211
|
+
const outRows = await inputSession.exchange([...iterRows(firstBatch)]);
|
|
3212
|
+
if (outRows.length > 0)
|
|
3213
|
+
yield outRows;
|
|
3214
|
+
for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
|
|
3215
|
+
const result = await inputSession.exchange([...iterRows(batch)]);
|
|
3216
|
+
if (result.length > 0)
|
|
3217
|
+
yield result;
|
|
3218
|
+
}
|
|
3219
|
+
} finally {
|
|
3220
|
+
inputSession.close();
|
|
3221
|
+
}
|
|
3222
|
+
const { session: finalizeSession } = await this._doInit(bindReq, bindResp, {
|
|
3223
|
+
projectionIds: opts.projectionIds,
|
|
3224
|
+
pushdownFilters: opts.pushdownFilters,
|
|
3225
|
+
phase: "FINALIZE" /* FINALIZE */,
|
|
3226
|
+
executionId: initResponse.execution_id,
|
|
3227
|
+
orderBy: opts.orderBy,
|
|
3228
|
+
tablesample: opts.tablesample,
|
|
3229
|
+
joinKeys: opts.joinKeys
|
|
3230
|
+
});
|
|
3231
|
+
try {
|
|
3232
|
+
for await (const rows of finalizeSession) {
|
|
3233
|
+
if (rows.length > 0)
|
|
3234
|
+
yield rows;
|
|
3235
|
+
}
|
|
3236
|
+
} finally {
|
|
3237
|
+
finalizeSession.close();
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
async* tableInOutFunction(opts) {
|
|
3241
|
+
const inputIter = toAsyncIterator(opts.input);
|
|
3242
|
+
const first = await inputIter.next();
|
|
3243
|
+
if (first.done) {
|
|
3244
|
+
throw new VgiClientError(`tableInOutFunction(${opts.functionName}): input iterator yielded no batches; ` + `at least one batch is required to determine the input schema`);
|
|
3245
|
+
}
|
|
3246
|
+
const firstBatch = first.value;
|
|
3247
|
+
const inputSchema = firstBatch.schema;
|
|
3248
|
+
const args = opts.arguments ?? new Arguments;
|
|
3249
|
+
const { request: bindReq, response: bindResp } = await this._doBind(opts.functionName, "table" /* TABLE */, args, inputSchema, opts.settings ?? null, null, opts.transactionOpaqueData ?? null, opts.attachOpaqueData ?? null, opts.onBind ?? null);
|
|
3250
|
+
const { session: inputSession, initResponse } = await this._doInit(bindReq, bindResp, {
|
|
3251
|
+
projectionIds: opts.projectionIds,
|
|
3252
|
+
pushdownFilters: opts.pushdownFilters,
|
|
3253
|
+
phase: "INPUT" /* INPUT */,
|
|
3254
|
+
orderBy: opts.orderBy,
|
|
3255
|
+
tablesample: opts.tablesample,
|
|
3256
|
+
joinKeys: opts.joinKeys
|
|
3257
|
+
});
|
|
3258
|
+
const outputSchema = bindResp.output_schema;
|
|
3259
|
+
try {
|
|
3260
|
+
const outRows = await inputSession.exchange([...iterRows(firstBatch)]);
|
|
3261
|
+
if (outRows.length > 0)
|
|
3262
|
+
yield batchFromRows(outRows, outputSchema);
|
|
3263
|
+
for await (const batch of { [Symbol.asyncIterator]: () => inputIter }) {
|
|
3264
|
+
const result = await inputSession.exchange([...iterRows(batch)]);
|
|
3265
|
+
if (result.length > 0)
|
|
3266
|
+
yield batchFromRows(result, outputSchema);
|
|
3267
|
+
}
|
|
3268
|
+
} finally {
|
|
3269
|
+
inputSession.close();
|
|
3270
|
+
}
|
|
3271
|
+
const { session: finalizeSession } = await this._doInit(bindReq, bindResp, {
|
|
3272
|
+
projectionIds: opts.projectionIds,
|
|
3273
|
+
pushdownFilters: opts.pushdownFilters,
|
|
3274
|
+
phase: "FINALIZE" /* FINALIZE */,
|
|
3275
|
+
executionId: initResponse.execution_id,
|
|
3276
|
+
orderBy: opts.orderBy,
|
|
3277
|
+
tablesample: opts.tablesample,
|
|
3278
|
+
joinKeys: opts.joinKeys
|
|
3279
|
+
});
|
|
3280
|
+
try {
|
|
3281
|
+
for await (const rows of finalizeSession) {
|
|
3282
|
+
if (rows.length > 0)
|
|
3283
|
+
yield batchFromRows(rows, outputSchema);
|
|
3284
|
+
}
|
|
3285
|
+
} finally {
|
|
3286
|
+
finalizeSession.close();
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
async* tableFunctionRows(opts) {
|
|
3290
|
+
const args = opts.arguments ?? new Arguments;
|
|
3291
|
+
const { request: bindReq, response: bindResp } = await this._doBind(opts.functionName, "table" /* TABLE */, args, null, opts.settings ?? null, null, opts.transactionOpaqueData ?? null, opts.attachOpaqueData ?? null, opts.onBind ?? null);
|
|
3292
|
+
const { session } = await this._doInit(bindReq, bindResp, {
|
|
3293
|
+
projectionIds: opts.projectionIds,
|
|
3294
|
+
pushdownFilters: opts.pushdownFilters,
|
|
3295
|
+
orderBy: opts.orderBy,
|
|
3296
|
+
tablesample: opts.tablesample,
|
|
3297
|
+
joinKeys: opts.joinKeys
|
|
3298
|
+
});
|
|
3299
|
+
try {
|
|
3300
|
+
for await (const rows of session) {
|
|
3301
|
+
if (rows.length > 0)
|
|
3302
|
+
yield rows;
|
|
3303
|
+
}
|
|
3304
|
+
} finally {
|
|
3305
|
+
session.close();
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
async catalogsInfo() {
|
|
3309
|
+
const result = await this.rpc.call("catalog_catalogs", {});
|
|
3310
|
+
if (!result)
|
|
3311
|
+
return [];
|
|
3312
|
+
const inner = unwrapResult(result);
|
|
3313
|
+
return deserializeInfoList(inner.items, decodeCatalogInfo);
|
|
3314
|
+
}
|
|
3315
|
+
async catalogs() {
|
|
3316
|
+
const infos = await this.catalogsInfo();
|
|
3317
|
+
return infos.map((i) => i.name);
|
|
3318
|
+
}
|
|
3319
|
+
async catalogAttach(name, opts) {
|
|
3320
|
+
if (opts?.options != null && opts?.optionsBytes != null) {
|
|
3321
|
+
throw new VgiClientError("catalogAttach: cannot specify both `options` and `optionsBytes`");
|
|
3322
|
+
}
|
|
3323
|
+
let wireOptions;
|
|
3324
|
+
if (opts?.optionsBytes != null) {
|
|
3325
|
+
wireOptions = opts.optionsBytes.byteLength === 0 ? null : opts.optionsBytes;
|
|
3326
|
+
} else {
|
|
3327
|
+
wireOptions = serializeAttachOptions(opts?.options);
|
|
3328
|
+
}
|
|
3329
|
+
const schema3 = schema2([
|
|
3330
|
+
field2("name", utf82(), false),
|
|
3331
|
+
field2("options", binary2(), true),
|
|
3332
|
+
field2("data_version_spec", utf82(), true),
|
|
3333
|
+
field2("implementation_version", utf82(), true)
|
|
3334
|
+
]);
|
|
3335
|
+
const innerBatch = batchFromColumns({
|
|
3336
|
+
name: [name],
|
|
3337
|
+
options: [wireOptions],
|
|
3338
|
+
data_version_spec: [opts?.dataVersionSpec ?? null],
|
|
3339
|
+
implementation_version: [opts?.implementationVersion ?? null]
|
|
3340
|
+
}, schema3);
|
|
3341
|
+
const result = await this.rpc.call("catalog_attach", wrapRequest(innerBatch));
|
|
3342
|
+
if (!result)
|
|
3343
|
+
throw new VgiClientError("catalog_attach returned null");
|
|
3344
|
+
const inner = unwrapResult(result);
|
|
3345
|
+
return {
|
|
3346
|
+
attach_opaque_data: toUint8Array(inner.attach_opaque_data),
|
|
3347
|
+
supports_transactions: inner.supports_transactions ?? false,
|
|
3348
|
+
supports_time_travel: inner.supports_time_travel ?? false,
|
|
3349
|
+
catalog_version_frozen: inner.catalog_version_frozen ?? false,
|
|
3350
|
+
catalog_version: Number(inner.catalog_version ?? 0),
|
|
3351
|
+
attach_opaque_data_required: inner.attach_opaque_data_required ?? true,
|
|
3352
|
+
default_schema: inner.default_schema ?? "main",
|
|
3353
|
+
settings: inner.settings ? (Array.isArray(inner.settings) ? inner.settings : [...inner.settings]).map(toUint8Array) : [],
|
|
3354
|
+
secret_types: inner.secret_types ? (Array.isArray(inner.secret_types) ? inner.secret_types : [...inner.secret_types]).map(toUint8Array) : [],
|
|
3355
|
+
attach_catalogs: inner.attach_catalogs ? (Array.isArray(inner.attach_catalogs) ? inner.attach_catalogs : [...inner.attach_catalogs]).map(toUint8Array) : [],
|
|
3356
|
+
comment: inner.comment ?? null,
|
|
3357
|
+
tags: deserializeTags(inner.tags),
|
|
3358
|
+
supports_column_statistics: inner.supports_column_statistics ?? false,
|
|
3359
|
+
resolved_data_version: inner.resolved_data_version ?? null,
|
|
3360
|
+
resolved_implementation_version: inner.resolved_implementation_version ?? null
|
|
3361
|
+
};
|
|
3362
|
+
}
|
|
3363
|
+
async catalogDetach(attachOpaqueData) {
|
|
3364
|
+
await this.rpc.call("catalog_detach", { attach_opaque_data: attachOpaqueData });
|
|
3365
|
+
}
|
|
3366
|
+
async catalogCreate(name, onConflict, options) {
|
|
3367
|
+
let wireOptions;
|
|
3368
|
+
if (options == null) {
|
|
3369
|
+
wireOptions = null;
|
|
3370
|
+
} else if (options instanceof Uint8Array) {
|
|
3371
|
+
wireOptions = options.byteLength === 0 ? null : options;
|
|
3372
|
+
} else {
|
|
3373
|
+
if (options.options != null && options.optionsBytes != null) {
|
|
3374
|
+
throw new VgiClientError("catalogCreate: cannot specify both `options` and `optionsBytes`");
|
|
3375
|
+
}
|
|
3376
|
+
if (options.optionsBytes != null) {
|
|
3377
|
+
wireOptions = options.optionsBytes.byteLength === 0 ? null : options.optionsBytes;
|
|
3378
|
+
} else {
|
|
3379
|
+
wireOptions = serializeAttachOptions(options.options);
|
|
3380
|
+
}
|
|
3381
|
+
}
|
|
3382
|
+
await this.rpc.call("catalog_create", {
|
|
3383
|
+
name,
|
|
3384
|
+
on_conflict: onConflict,
|
|
3385
|
+
options: wireOptions
|
|
3386
|
+
});
|
|
3387
|
+
}
|
|
3388
|
+
async catalogDrop(name) {
|
|
3389
|
+
await this.rpc.call("catalog_drop", { name });
|
|
3390
|
+
}
|
|
3391
|
+
async catalogVersion(attachOpaqueData, transactionOpaqueData) {
|
|
3392
|
+
const result = await this.rpc.call("catalog_version", {
|
|
3393
|
+
attach_opaque_data: attachOpaqueData,
|
|
3394
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3395
|
+
});
|
|
3396
|
+
if (!result)
|
|
3397
|
+
throw new VgiClientError("catalog_version returned null");
|
|
3398
|
+
const inner = unwrapResult(result);
|
|
3399
|
+
return Number(inner.version ?? 0);
|
|
3400
|
+
}
|
|
3401
|
+
async transactionBegin(attachOpaqueData) {
|
|
3402
|
+
const result = await this.rpc.call("catalog_transaction_begin", {
|
|
3403
|
+
attach_opaque_data: attachOpaqueData
|
|
3404
|
+
});
|
|
3405
|
+
if (!result)
|
|
3406
|
+
throw new VgiClientError("transaction_begin returned null");
|
|
3407
|
+
const inner = unwrapResult(result);
|
|
3408
|
+
if (!inner.transaction_opaque_data) {
|
|
3409
|
+
throw new VgiClientError("transaction_begin returned no transaction_opaque_data");
|
|
3410
|
+
}
|
|
3411
|
+
return toUint8Array(inner.transaction_opaque_data);
|
|
3412
|
+
}
|
|
3413
|
+
async transactionCommit(attachOpaqueData, transactionOpaqueData) {
|
|
3414
|
+
await this.rpc.call("catalog_transaction_commit", {
|
|
3415
|
+
attach_opaque_data: attachOpaqueData,
|
|
3416
|
+
transaction_opaque_data: transactionOpaqueData
|
|
3417
|
+
});
|
|
3418
|
+
}
|
|
3419
|
+
async transactionRollback(attachOpaqueData, transactionOpaqueData) {
|
|
3420
|
+
await this.rpc.call("catalog_transaction_rollback", {
|
|
3421
|
+
attach_opaque_data: attachOpaqueData,
|
|
3422
|
+
transaction_opaque_data: transactionOpaqueData
|
|
3423
|
+
});
|
|
3424
|
+
}
|
|
3425
|
+
async schemas(attachOpaqueData, transactionOpaqueData) {
|
|
3426
|
+
const result = await this.rpc.call("catalog_schemas", {
|
|
3427
|
+
attach_opaque_data: attachOpaqueData,
|
|
3428
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3429
|
+
});
|
|
3430
|
+
if (!result)
|
|
3431
|
+
return [];
|
|
3432
|
+
const inner = unwrapResult(result);
|
|
3433
|
+
return deserializeInfoList(inner.items, decodeSchemaInfo);
|
|
3434
|
+
}
|
|
3435
|
+
async schemaGet(attachOpaqueData, name, transactionOpaqueData) {
|
|
3436
|
+
const result = await this.rpc.call("catalog_schema_get", {
|
|
3437
|
+
attach_opaque_data: attachOpaqueData,
|
|
3438
|
+
name,
|
|
3439
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3440
|
+
});
|
|
3441
|
+
if (!result)
|
|
3442
|
+
return null;
|
|
3443
|
+
const inner = unwrapResult(result);
|
|
3444
|
+
const items = deserializeInfoList(inner.items, decodeSchemaInfo);
|
|
3445
|
+
return items.length > 0 ? items[0] : null;
|
|
3446
|
+
}
|
|
3447
|
+
async schemaCreate(attachOpaqueData, name, opts) {
|
|
3448
|
+
const tagsMap = opts?.tags ? new Map(Object.entries(opts.tags)) : null;
|
|
3449
|
+
await this.rpc.call("catalog_schema_create", {
|
|
3450
|
+
attach_opaque_data: attachOpaqueData,
|
|
3451
|
+
name,
|
|
3452
|
+
on_conflict: opts?.onConflict ?? "error",
|
|
3453
|
+
comment: opts?.comment ?? null,
|
|
3454
|
+
tags: tagsMap,
|
|
3455
|
+
transaction_opaque_data: opts?.transactionOpaqueData ?? null
|
|
3456
|
+
});
|
|
3457
|
+
}
|
|
3458
|
+
async schemaDrop(attachOpaqueData, name, ignoreNotFound, cascade, transactionOpaqueData) {
|
|
3459
|
+
await this.rpc.call("catalog_schema_drop", {
|
|
3460
|
+
attach_opaque_data: attachOpaqueData,
|
|
3461
|
+
name,
|
|
3462
|
+
ignore_not_found: ignoreNotFound ?? false,
|
|
3463
|
+
cascade: cascade ?? false,
|
|
3464
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3465
|
+
});
|
|
3466
|
+
}
|
|
3467
|
+
async schemaContentsTables(attachOpaqueData, name, transactionOpaqueData) {
|
|
3468
|
+
const result = await this.rpc.call("catalog_schema_contents_tables", {
|
|
3469
|
+
attach_opaque_data: attachOpaqueData,
|
|
3470
|
+
name,
|
|
3471
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3472
|
+
});
|
|
3473
|
+
if (!result)
|
|
3474
|
+
return [];
|
|
3475
|
+
const inner = unwrapResult(result);
|
|
3476
|
+
return deserializeInfoList(inner.items, decodeTableInfo);
|
|
3477
|
+
}
|
|
3478
|
+
async schemaContentsViews(attachOpaqueData, name, transactionOpaqueData) {
|
|
3479
|
+
const result = await this.rpc.call("catalog_schema_contents_views", {
|
|
3480
|
+
attach_opaque_data: attachOpaqueData,
|
|
3481
|
+
name,
|
|
3482
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3483
|
+
});
|
|
3484
|
+
if (!result)
|
|
3485
|
+
return [];
|
|
3486
|
+
const inner = unwrapResult(result);
|
|
3487
|
+
return deserializeInfoList(inner.items, decodeViewInfo);
|
|
3488
|
+
}
|
|
3489
|
+
async schemaContentsFunctions(attachOpaqueData, name, type, transactionOpaqueData) {
|
|
3490
|
+
const result = await this.rpc.call("catalog_schema_contents_functions", {
|
|
3491
|
+
attach_opaque_data: attachOpaqueData,
|
|
3492
|
+
name,
|
|
3493
|
+
type,
|
|
3494
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3495
|
+
});
|
|
3496
|
+
if (!result)
|
|
3497
|
+
return [];
|
|
3498
|
+
const inner = unwrapResult(result);
|
|
3499
|
+
return deserializeInfoList(inner.items, decodeFunctionInfo);
|
|
3500
|
+
}
|
|
3501
|
+
async tableGet(attachOpaqueData, schemaName, name, transactionOpaqueData) {
|
|
3502
|
+
const result = await this.rpc.call("catalog_table_get", {
|
|
3503
|
+
attach_opaque_data: attachOpaqueData,
|
|
3504
|
+
schema_name: schemaName,
|
|
3505
|
+
name,
|
|
3506
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3507
|
+
});
|
|
3508
|
+
if (!result)
|
|
3509
|
+
return null;
|
|
3510
|
+
const inner = unwrapResult(result);
|
|
3511
|
+
const items = deserializeInfoList(inner.items, decodeTableInfo);
|
|
3512
|
+
return items.length > 0 ? items[0] : null;
|
|
3513
|
+
}
|
|
3514
|
+
async tableCreate(attachOpaqueData, schemaName, name, columns, onConflict, notNullConstraints, uniqueConstraints, checkConstraints, transactionOpaqueData) {
|
|
3515
|
+
await this.rpc.call("catalog_table_create", {
|
|
3516
|
+
attach_opaque_data: attachOpaqueData,
|
|
3517
|
+
schema_name: schemaName,
|
|
3518
|
+
name,
|
|
3519
|
+
columns,
|
|
3520
|
+
on_conflict: onConflict,
|
|
3521
|
+
not_null_constraints: notNullConstraints ?? null,
|
|
3522
|
+
unique_constraints: uniqueConstraints ?? null,
|
|
3523
|
+
check_constraints: checkConstraints ?? null,
|
|
3524
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3525
|
+
});
|
|
3526
|
+
}
|
|
3527
|
+
async tableDrop(attachOpaqueData, schemaName, name, ignoreNotFound, cascade, transactionOpaqueData) {
|
|
3528
|
+
await this.rpc.call("catalog_table_drop", {
|
|
3529
|
+
attach_opaque_data: attachOpaqueData,
|
|
3530
|
+
schema_name: schemaName,
|
|
3531
|
+
name,
|
|
3532
|
+
ignore_not_found: ignoreNotFound ?? false,
|
|
3533
|
+
cascade: cascade ?? false,
|
|
3534
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3535
|
+
});
|
|
3536
|
+
}
|
|
3537
|
+
async tableScanFunctionGet(attachOpaqueData, schemaName, name, atUnit, atValue, transactionOpaqueData) {
|
|
3538
|
+
const result = await this.rpc.call("catalog_table_scan_function_get", {
|
|
3539
|
+
attach_opaque_data: attachOpaqueData,
|
|
3540
|
+
schema_name: schemaName,
|
|
3541
|
+
name,
|
|
3542
|
+
at_unit: atUnit ?? null,
|
|
3543
|
+
at_value: atValue ?? null,
|
|
3544
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3545
|
+
});
|
|
3546
|
+
if (!result)
|
|
3547
|
+
throw new VgiClientError("table_scan_function_get returned null");
|
|
3548
|
+
return decodeScanFunctionResult(unwrapResult(result));
|
|
3549
|
+
}
|
|
3550
|
+
async tableCommentSet(attachOpaqueData, schemaName, name, comment, ignoreNotFound, transactionOpaqueData) {
|
|
3551
|
+
await this.rpc.call("catalog_table_comment_set", {
|
|
3552
|
+
attach_opaque_data: attachOpaqueData,
|
|
3553
|
+
schema_name: schemaName,
|
|
3554
|
+
name,
|
|
3555
|
+
comment: comment ?? null,
|
|
3556
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3557
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3558
|
+
});
|
|
3559
|
+
}
|
|
3560
|
+
async tableRename(attachOpaqueData, schemaName, name, newName, ignoreNotFound, transactionOpaqueData) {
|
|
3561
|
+
await this.rpc.call("catalog_table_rename", {
|
|
3562
|
+
attach_opaque_data: attachOpaqueData,
|
|
3563
|
+
schema_name: schemaName,
|
|
3564
|
+
name,
|
|
3565
|
+
new_name: newName,
|
|
3566
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3567
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3568
|
+
});
|
|
3569
|
+
}
|
|
3570
|
+
async tableColumnAdd(attachOpaqueData, schemaName, name, columnName, columnType, defaultValue, ignoreNotFound, transactionOpaqueData) {
|
|
3571
|
+
await this.rpc.call("catalog_table_column_add", {
|
|
3572
|
+
attach_opaque_data: attachOpaqueData,
|
|
3573
|
+
schema_name: schemaName,
|
|
3574
|
+
name,
|
|
3575
|
+
column_name: columnName,
|
|
3576
|
+
column_type: columnType,
|
|
3577
|
+
default_value: defaultValue ?? null,
|
|
3578
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3579
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3580
|
+
});
|
|
3581
|
+
}
|
|
3582
|
+
async tableColumnDrop(attachOpaqueData, schemaName, name, columnName, ignoreNotFound, transactionOpaqueData) {
|
|
3583
|
+
await this.rpc.call("catalog_table_column_drop", {
|
|
3584
|
+
attach_opaque_data: attachOpaqueData,
|
|
3585
|
+
schema_name: schemaName,
|
|
3586
|
+
name,
|
|
3587
|
+
column_name: columnName,
|
|
3588
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3589
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3590
|
+
});
|
|
3591
|
+
}
|
|
3592
|
+
async tableColumnRename(attachOpaqueData, schemaName, name, columnName, newName, ignoreNotFound, transactionOpaqueData) {
|
|
3593
|
+
await this.rpc.call("catalog_table_column_rename", {
|
|
3594
|
+
attach_opaque_data: attachOpaqueData,
|
|
3595
|
+
schema_name: schemaName,
|
|
3596
|
+
name,
|
|
3597
|
+
column_name: columnName,
|
|
3598
|
+
new_name: newName,
|
|
3599
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3600
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3601
|
+
});
|
|
3602
|
+
}
|
|
3603
|
+
async tableColumnDefaultSet(attachOpaqueData, schemaName, name, columnName, defaultValue, ignoreNotFound, transactionOpaqueData) {
|
|
3604
|
+
await this.rpc.call("catalog_table_column_default_set", {
|
|
3605
|
+
attach_opaque_data: attachOpaqueData,
|
|
3606
|
+
schema_name: schemaName,
|
|
3607
|
+
name,
|
|
3608
|
+
column_name: columnName,
|
|
3609
|
+
default_value: defaultValue,
|
|
3610
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3611
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3612
|
+
});
|
|
3613
|
+
}
|
|
3614
|
+
async tableColumnDefaultDrop(attachOpaqueData, schemaName, name, columnName, ignoreNotFound, transactionOpaqueData) {
|
|
3615
|
+
await this.rpc.call("catalog_table_column_default_drop", {
|
|
3616
|
+
attach_opaque_data: attachOpaqueData,
|
|
3617
|
+
schema_name: schemaName,
|
|
3618
|
+
name,
|
|
3619
|
+
column_name: columnName,
|
|
3620
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3621
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3622
|
+
});
|
|
3623
|
+
}
|
|
3624
|
+
async tableColumnTypeChange(attachOpaqueData, schemaName, name, columnDefinition, expression, ignoreNotFound, transactionOpaqueData) {
|
|
3625
|
+
await this.rpc.call("catalog_table_column_type_change", {
|
|
3626
|
+
attach_opaque_data: attachOpaqueData,
|
|
3627
|
+
schema_name: schemaName,
|
|
3628
|
+
name,
|
|
3629
|
+
column_definition: columnDefinition,
|
|
3630
|
+
expression: expression ?? null,
|
|
3631
|
+
ignore_not_found: ignoreNotFound ?? false,
|
|
3632
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3633
|
+
});
|
|
3634
|
+
}
|
|
3635
|
+
async tableNotNullSet(attachOpaqueData, schemaName, name, columnName, ignoreNotFound, transactionOpaqueData) {
|
|
3636
|
+
await this.rpc.call("catalog_table_not_null_set", {
|
|
3637
|
+
attach_opaque_data: attachOpaqueData,
|
|
3638
|
+
schema_name: schemaName,
|
|
3639
|
+
name,
|
|
3640
|
+
column_name: columnName,
|
|
3641
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3642
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3643
|
+
});
|
|
3644
|
+
}
|
|
3645
|
+
async tableNotNullDrop(attachOpaqueData, schemaName, name, columnName, ignoreNotFound, transactionOpaqueData) {
|
|
3646
|
+
await this.rpc.call("catalog_table_not_null_drop", {
|
|
3647
|
+
attach_opaque_data: attachOpaqueData,
|
|
3648
|
+
schema_name: schemaName,
|
|
3649
|
+
name,
|
|
3650
|
+
column_name: columnName,
|
|
3651
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3652
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3653
|
+
});
|
|
3654
|
+
}
|
|
3655
|
+
async viewGet(attachOpaqueData, schemaName, name, transactionOpaqueData) {
|
|
3656
|
+
const result = await this.rpc.call("catalog_view_get", {
|
|
3657
|
+
attach_opaque_data: attachOpaqueData,
|
|
3658
|
+
schema_name: schemaName,
|
|
3659
|
+
name,
|
|
3660
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3661
|
+
});
|
|
3662
|
+
if (!result)
|
|
3663
|
+
return null;
|
|
3664
|
+
const inner = unwrapResult(result);
|
|
3665
|
+
const items = deserializeInfoList(inner.items, decodeViewInfo);
|
|
3666
|
+
return items.length > 0 ? items[0] : null;
|
|
3667
|
+
}
|
|
3668
|
+
async viewCreate(attachOpaqueData, schemaName, name, definition, onConflict, transactionOpaqueData) {
|
|
3669
|
+
await this.rpc.call("catalog_view_create", {
|
|
3670
|
+
attach_opaque_data: attachOpaqueData,
|
|
3671
|
+
schema_name: schemaName,
|
|
3672
|
+
name,
|
|
3673
|
+
definition,
|
|
3674
|
+
on_conflict: onConflict,
|
|
3675
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3676
|
+
});
|
|
3677
|
+
}
|
|
3678
|
+
async viewDrop(attachOpaqueData, schemaName, name, ignoreNotFound, cascade, transactionOpaqueData) {
|
|
3679
|
+
await this.rpc.call("catalog_view_drop", {
|
|
3680
|
+
attach_opaque_data: attachOpaqueData,
|
|
3681
|
+
schema_name: schemaName,
|
|
3682
|
+
name,
|
|
3683
|
+
ignore_not_found: ignoreNotFound ?? false,
|
|
3684
|
+
cascade: cascade ?? false,
|
|
3685
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3688
|
+
async viewRename(attachOpaqueData, schemaName, name, newName, ignoreNotFound, transactionOpaqueData) {
|
|
3689
|
+
await this.rpc.call("catalog_view_rename", {
|
|
3690
|
+
attach_opaque_data: attachOpaqueData,
|
|
3691
|
+
schema_name: schemaName,
|
|
3692
|
+
name,
|
|
3693
|
+
new_name: newName,
|
|
3694
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3695
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3696
|
+
});
|
|
3697
|
+
}
|
|
3698
|
+
async viewCommentSet(attachOpaqueData, schemaName, name, comment, ignoreNotFound, transactionOpaqueData) {
|
|
3699
|
+
await this.rpc.call("catalog_view_comment_set", {
|
|
3700
|
+
attach_opaque_data: attachOpaqueData,
|
|
3701
|
+
schema_name: schemaName,
|
|
3702
|
+
name,
|
|
3703
|
+
comment: comment ?? null,
|
|
3704
|
+
ignore_not_found: ignoreNotFound ?? null,
|
|
3705
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3706
|
+
});
|
|
3707
|
+
}
|
|
3708
|
+
async macroGet(attachOpaqueData, schemaName, name, transactionOpaqueData) {
|
|
3709
|
+
const result = await this.rpc.call("catalog_macro_get", {
|
|
3710
|
+
attach_opaque_data: attachOpaqueData,
|
|
3711
|
+
schema_name: schemaName,
|
|
3712
|
+
name,
|
|
3713
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3714
|
+
});
|
|
3715
|
+
if (!result)
|
|
3716
|
+
return null;
|
|
3717
|
+
const inner = unwrapResult(result);
|
|
3718
|
+
const items = deserializeInfoList(inner.items, decodeMacroInfo);
|
|
3719
|
+
return items.length > 0 ? items[0] : null;
|
|
3720
|
+
}
|
|
3721
|
+
async schemaContentsMacros(attachOpaqueData, name, type, transactionOpaqueData) {
|
|
3722
|
+
const result = await this.rpc.call("catalog_schema_contents_macros", {
|
|
3723
|
+
attach_opaque_data: attachOpaqueData,
|
|
3724
|
+
name,
|
|
3725
|
+
type,
|
|
3726
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3727
|
+
});
|
|
3728
|
+
if (!result)
|
|
3729
|
+
return [];
|
|
3730
|
+
const inner = unwrapResult(result);
|
|
3731
|
+
return deserializeInfoList(inner.items, decodeMacroInfo);
|
|
3732
|
+
}
|
|
3733
|
+
async macroCreate(attachOpaqueData, schemaName, name, macroType, parameters, definition, onConflict, parameterDefaultValues, argumentsSchema, transactionOpaqueData) {
|
|
3734
|
+
const schema3 = schema2([
|
|
3735
|
+
field2("attach_opaque_data", binary2(), true),
|
|
3736
|
+
field2("schema_name", utf82(), false),
|
|
3737
|
+
field2("name", utf82(), false),
|
|
3738
|
+
field2("macro_type", utf82(), false),
|
|
3739
|
+
field2("parameters", list2(field2("item", utf82(), false)), false),
|
|
3740
|
+
field2("definition", utf82(), false),
|
|
3741
|
+
field2("on_conflict", utf82(), false),
|
|
3742
|
+
field2("parameter_default_values", binary2(), true),
|
|
3743
|
+
field2("arguments_schema", binary2(), true),
|
|
3744
|
+
field2("transaction_opaque_data", binary2(), true)
|
|
3745
|
+
]);
|
|
3746
|
+
const innerBatch = batchFromColumns({
|
|
3747
|
+
attach_opaque_data: [attachOpaqueData],
|
|
3748
|
+
schema_name: [schemaName],
|
|
3749
|
+
name: [name],
|
|
3750
|
+
macro_type: [macroType],
|
|
3751
|
+
parameters: [parameters],
|
|
3752
|
+
definition: [definition],
|
|
3753
|
+
on_conflict: [onConflict],
|
|
3754
|
+
parameter_default_values: [parameterDefaultValues ?? null],
|
|
3755
|
+
arguments_schema: [argumentsSchema ?? null],
|
|
3756
|
+
transaction_opaque_data: [transactionOpaqueData ?? null]
|
|
3757
|
+
}, schema3);
|
|
3758
|
+
await this.rpc.call("catalog_macro_create", wrapRequest(innerBatch));
|
|
3759
|
+
}
|
|
3760
|
+
async macroDrop(attachOpaqueData, schemaName, name, ignoreNotFound, transactionOpaqueData) {
|
|
3761
|
+
await this.rpc.call("catalog_macro_drop", {
|
|
3762
|
+
attach_opaque_data: attachOpaqueData,
|
|
3763
|
+
schema_name: schemaName,
|
|
3764
|
+
name,
|
|
3765
|
+
ignore_not_found: ignoreNotFound ?? false,
|
|
3766
|
+
transaction_opaque_data: transactionOpaqueData ?? null
|
|
3767
|
+
});
|
|
3768
|
+
}
|
|
3769
|
+
close() {
|
|
3770
|
+
this.rpc.close();
|
|
3771
|
+
}
|
|
3772
|
+
}
|
|
3773
|
+
// src/arguments/argument-spec.ts
|
|
3774
|
+
function argumentSpecSortKey(spec) {
|
|
3775
|
+
if (typeof spec.position === "number") {
|
|
3776
|
+
return [0, spec.position];
|
|
3777
|
+
}
|
|
3778
|
+
return [1, spec.position];
|
|
3779
|
+
}
|
|
3780
|
+
function argumentSpecsToSchema(specs) {
|
|
3781
|
+
const sorted = [...specs].sort((a, b) => {
|
|
3782
|
+
const ka = argumentSpecSortKey(a);
|
|
3783
|
+
const kb = argumentSpecSortKey(b);
|
|
3784
|
+
if (ka[0] !== kb[0])
|
|
3785
|
+
return ka[0] - kb[0];
|
|
3786
|
+
if (typeof ka[1] === "number" && typeof kb[1] === "number") {
|
|
3787
|
+
return ka[1] - kb[1];
|
|
3788
|
+
}
|
|
3789
|
+
return String(ka[1]).localeCompare(String(kb[1]));
|
|
3790
|
+
});
|
|
3791
|
+
const fields = [];
|
|
3792
|
+
for (const spec of sorted) {
|
|
3793
|
+
const metadata = new Map;
|
|
3794
|
+
if (typeof spec.position === "string") {
|
|
3795
|
+
metadata.set(VGI_ARG_KEY, VGI_ARG_NAMED);
|
|
3796
|
+
}
|
|
3797
|
+
if (spec.isTableInput) {
|
|
3798
|
+
metadata.set(VGI_TYPE_KEY, VGI_TYPE_TABLE);
|
|
3799
|
+
} else if (spec.isAnyType) {
|
|
3800
|
+
metadata.set(VGI_TYPE_KEY, VGI_TYPE_ANY);
|
|
3801
|
+
}
|
|
3802
|
+
if (spec.isVarargs) {
|
|
3803
|
+
metadata.set(VGI_VARARGS_KEY, VGI_VARARGS_TRUE);
|
|
3804
|
+
}
|
|
3805
|
+
if (spec.isConst) {
|
|
3806
|
+
metadata.set(VGI_CONST_KEY, VGI_CONST_TRUE);
|
|
3807
|
+
}
|
|
3808
|
+
if (spec.doc) {
|
|
3809
|
+
metadata.set(VGI_DOC_KEY, spec.doc);
|
|
3810
|
+
}
|
|
3811
|
+
if (spec.defaultJson !== undefined) {
|
|
3812
|
+
metadata.set(VGI_DEFAULT_KEY, spec.defaultJson);
|
|
3813
|
+
}
|
|
3814
|
+
if (spec.choicesJson !== undefined) {
|
|
3815
|
+
metadata.set(VGI_CHOICES_KEY, spec.choicesJson);
|
|
3816
|
+
}
|
|
3817
|
+
if (spec.rangeNotation !== undefined) {
|
|
3818
|
+
metadata.set(VGI_RANGE_KEY, spec.rangeNotation);
|
|
3819
|
+
}
|
|
3820
|
+
if (spec.pattern !== undefined) {
|
|
3821
|
+
metadata.set(VGI_PATTERN_KEY, spec.pattern);
|
|
3822
|
+
}
|
|
3823
|
+
const field3 = field2(spec.name, spec.arrowType, true, metadata.size > 0 ? metadata : undefined);
|
|
3824
|
+
fields.push(field3);
|
|
3825
|
+
}
|
|
3826
|
+
return schema2(fields);
|
|
3827
|
+
}
|
|
3828
|
+
function schemaToArgumentSpecs(schema3) {
|
|
3829
|
+
const specs = [];
|
|
3830
|
+
let positionIndex = 0;
|
|
3831
|
+
for (const field3 of schema3.fields) {
|
|
3832
|
+
const metadata = field3.metadata;
|
|
3833
|
+
const isNamed = metadata.get(VGI_ARG_KEY) === VGI_ARG_NAMED;
|
|
3834
|
+
const position = isNamed ? field3.name : positionIndex++;
|
|
3835
|
+
const vgiType = metadata.get(VGI_TYPE_KEY);
|
|
3836
|
+
const isTableInput = vgiType === VGI_TYPE_TABLE;
|
|
3837
|
+
const isAnyType = vgiType === VGI_TYPE_ANY;
|
|
3838
|
+
const isVarargs = metadata.get(VGI_VARARGS_KEY) === VGI_VARARGS_TRUE;
|
|
3839
|
+
const isConst = metadata.get(VGI_CONST_KEY) === VGI_CONST_TRUE;
|
|
3840
|
+
const doc = metadata.get(VGI_DOC_KEY) ?? "";
|
|
3841
|
+
const defaultJson = metadata.get(VGI_DEFAULT_KEY);
|
|
3842
|
+
const choicesJson = metadata.get(VGI_CHOICES_KEY);
|
|
3843
|
+
const rangeNotation = metadata.get(VGI_RANGE_KEY);
|
|
3844
|
+
const pattern = metadata.get(VGI_PATTERN_KEY);
|
|
3845
|
+
specs.push({
|
|
3846
|
+
name: field3.name,
|
|
3847
|
+
position,
|
|
3848
|
+
arrowType: field3.type,
|
|
3849
|
+
isTableInput,
|
|
3850
|
+
isAnyType,
|
|
3851
|
+
isVarargs,
|
|
3852
|
+
isConst,
|
|
3853
|
+
doc,
|
|
3854
|
+
defaultJson,
|
|
3855
|
+
choicesJson,
|
|
3856
|
+
rangeNotation,
|
|
3857
|
+
pattern
|
|
3858
|
+
});
|
|
3859
|
+
}
|
|
3860
|
+
return specs;
|
|
3861
|
+
}
|
|
1
3862
|
export {
|
|
2
3863
|
toUint8Array,
|
|
3
3864
|
serializeSchema,
|
|
@@ -45,4 +3906,4 @@ export {
|
|
|
45
3906
|
ArgumentValidationError
|
|
46
3907
|
};
|
|
47
3908
|
|
|
48
|
-
//# debugId=
|
|
3909
|
+
//# debugId=02E1D95AF7E1275C64756E2164756E21
|