@lancedb/lancedb 0.13.1-beta.0 → 0.14.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEVELOPMENT.md +42 -0
- package/package.json +12 -9
- package/dist/arrow.d.ts +0 -248
- package/dist/arrow.js +0 -743
- package/dist/connection.d.ts +0 -188
- package/dist/connection.js +0 -149
- package/dist/embedding/embedding_function.d.ts +0 -90
- package/dist/embedding/embedding_function.js +0 -133
- package/dist/embedding/index.d.ts +0 -27
- package/dist/embedding/index.js +0 -112
- package/dist/embedding/openai.d.ts +0 -18
- package/dist/embedding/openai.js +0 -105
- package/dist/embedding/registry.d.ts +0 -55
- package/dist/embedding/registry.js +0 -151
- package/dist/embedding/transformers.d.ts +0 -37
- package/dist/embedding/transformers.js +0 -148
- package/dist/index.d.ts +0 -54
- package/dist/index.js +0 -55
- package/dist/indices.d.ts +0 -429
- package/dist/indices.js +0 -131
- package/dist/merge.d.ts +0 -54
- package/dist/merge.js +0 -64
- package/dist/native.d.ts +0 -328
- package/dist/native.js +0 -330
- package/dist/query.d.ts +0 -324
- package/dist/query.js +0 -544
- package/dist/sanitize.d.ts +0 -31
- package/dist/sanitize.js +0 -437
- package/dist/table.d.ts +0 -425
- package/dist/table.js +0 -276
- package/dist/util.d.ts +0 -13
- package/dist/util.js +0 -65
package/dist/sanitize.js
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
// Copyright 2023 LanceDB Developers.
|
|
3
|
-
//
|
|
4
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
// you may not use this file except in compliance with the License.
|
|
6
|
-
// You may obtain a copy of the License at
|
|
7
|
-
//
|
|
8
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
//
|
|
10
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
// See the License for the specific language governing permissions and
|
|
14
|
-
// limitations under the License.
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.sanitizeMetadata = sanitizeMetadata;
|
|
17
|
-
exports.sanitizeInt = sanitizeInt;
|
|
18
|
-
exports.sanitizeFloat = sanitizeFloat;
|
|
19
|
-
exports.sanitizeDecimal = sanitizeDecimal;
|
|
20
|
-
exports.sanitizeDate = sanitizeDate;
|
|
21
|
-
exports.sanitizeTime = sanitizeTime;
|
|
22
|
-
exports.sanitizeTimestamp = sanitizeTimestamp;
|
|
23
|
-
exports.sanitizeTypedTimestamp = sanitizeTypedTimestamp;
|
|
24
|
-
exports.sanitizeInterval = sanitizeInterval;
|
|
25
|
-
exports.sanitizeList = sanitizeList;
|
|
26
|
-
exports.sanitizeStruct = sanitizeStruct;
|
|
27
|
-
exports.sanitizeUnion = sanitizeUnion;
|
|
28
|
-
exports.sanitizeTypedUnion = sanitizeTypedUnion;
|
|
29
|
-
exports.sanitizeFixedSizeBinary = sanitizeFixedSizeBinary;
|
|
30
|
-
exports.sanitizeFixedSizeList = sanitizeFixedSizeList;
|
|
31
|
-
exports.sanitizeMap = sanitizeMap;
|
|
32
|
-
exports.sanitizeDuration = sanitizeDuration;
|
|
33
|
-
exports.sanitizeDictionary = sanitizeDictionary;
|
|
34
|
-
exports.sanitizeType = sanitizeType;
|
|
35
|
-
exports.sanitizeField = sanitizeField;
|
|
36
|
-
exports.sanitizeSchema = sanitizeSchema;
|
|
37
|
-
exports.sanitizeTable = sanitizeTable;
|
|
38
|
-
// The utilities in this file help sanitize data from the user's arrow
|
|
39
|
-
// library into the types expected by vectordb's arrow library. Node
|
|
40
|
-
// generally allows for mulitple versions of the same library (and sometimes
|
|
41
|
-
// even multiple copies of the same version) to be installed at the same
|
|
42
|
-
// time. However, arrow-js uses instanceof which expected that the input
|
|
43
|
-
// comes from the exact same library instance. This is not always the case
|
|
44
|
-
// and so we must sanitize the input to ensure that it is compatible.
|
|
45
|
-
const apache_arrow_1 = require("apache-arrow");
|
|
46
|
-
const arrow_1 = require("./arrow");
|
|
47
|
-
function sanitizeMetadata(metadataLike) {
|
|
48
|
-
if (metadataLike === undefined || metadataLike === null) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
if (!(metadataLike instanceof Map)) {
|
|
52
|
-
throw Error("Expected metadata, if present, to be a Map<string, string>");
|
|
53
|
-
}
|
|
54
|
-
for (const item of metadataLike) {
|
|
55
|
-
if (!(typeof item[0] === "string" || !(typeof item[1] === "string"))) {
|
|
56
|
-
throw Error("Expected metadata, if present, to be a Map<string, string> but it had non-string keys or values");
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return metadataLike;
|
|
60
|
-
}
|
|
61
|
-
function sanitizeInt(typeLike) {
|
|
62
|
-
if (!("bitWidth" in typeLike) ||
|
|
63
|
-
typeof typeLike.bitWidth !== "number" ||
|
|
64
|
-
!("isSigned" in typeLike) ||
|
|
65
|
-
typeof typeLike.isSigned !== "boolean") {
|
|
66
|
-
throw Error("Expected an Int Type to have a `bitWidth` and `isSigned` property");
|
|
67
|
-
}
|
|
68
|
-
return new arrow_1.Int(typeLike.isSigned, typeLike.bitWidth);
|
|
69
|
-
}
|
|
70
|
-
function sanitizeFloat(typeLike) {
|
|
71
|
-
if (!("precision" in typeLike) || typeof typeLike.precision !== "number") {
|
|
72
|
-
throw Error("Expected a Float Type to have a `precision` property");
|
|
73
|
-
}
|
|
74
|
-
return new arrow_1.Float(typeLike.precision);
|
|
75
|
-
}
|
|
76
|
-
function sanitizeDecimal(typeLike) {
|
|
77
|
-
if (!("scale" in typeLike) ||
|
|
78
|
-
typeof typeLike.scale !== "number" ||
|
|
79
|
-
!("precision" in typeLike) ||
|
|
80
|
-
typeof typeLike.precision !== "number" ||
|
|
81
|
-
!("bitWidth" in typeLike) ||
|
|
82
|
-
typeof typeLike.bitWidth !== "number") {
|
|
83
|
-
throw Error("Expected a Decimal Type to have `scale`, `precision`, and `bitWidth` properties");
|
|
84
|
-
}
|
|
85
|
-
return new arrow_1.Decimal(typeLike.scale, typeLike.precision, typeLike.bitWidth);
|
|
86
|
-
}
|
|
87
|
-
function sanitizeDate(typeLike) {
|
|
88
|
-
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
89
|
-
throw Error("Expected a Date type to have a `unit` property");
|
|
90
|
-
}
|
|
91
|
-
return new arrow_1.Date_(typeLike.unit);
|
|
92
|
-
}
|
|
93
|
-
function sanitizeTime(typeLike) {
|
|
94
|
-
if (!("unit" in typeLike) ||
|
|
95
|
-
typeof typeLike.unit !== "number" ||
|
|
96
|
-
!("bitWidth" in typeLike) ||
|
|
97
|
-
typeof typeLike.bitWidth !== "number") {
|
|
98
|
-
throw Error("Expected a Time type to have `unit` and `bitWidth` properties");
|
|
99
|
-
}
|
|
100
|
-
return new arrow_1.Time(typeLike.unit, typeLike.bitWidth);
|
|
101
|
-
}
|
|
102
|
-
function sanitizeTimestamp(typeLike) {
|
|
103
|
-
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
104
|
-
throw Error("Expected a Timestamp type to have a `unit` property");
|
|
105
|
-
}
|
|
106
|
-
let timezone = null;
|
|
107
|
-
if ("timezone" in typeLike && typeof typeLike.timezone === "string") {
|
|
108
|
-
timezone = typeLike.timezone;
|
|
109
|
-
}
|
|
110
|
-
return new arrow_1.Timestamp(typeLike.unit, timezone);
|
|
111
|
-
}
|
|
112
|
-
function sanitizeTypedTimestamp(typeLike,
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
114
|
-
Datatype) {
|
|
115
|
-
let timezone = null;
|
|
116
|
-
if ("timezone" in typeLike && typeof typeLike.timezone === "string") {
|
|
117
|
-
timezone = typeLike.timezone;
|
|
118
|
-
}
|
|
119
|
-
return new Datatype(timezone);
|
|
120
|
-
}
|
|
121
|
-
function sanitizeInterval(typeLike) {
|
|
122
|
-
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
123
|
-
throw Error("Expected an Interval type to have a `unit` property");
|
|
124
|
-
}
|
|
125
|
-
return new arrow_1.Interval(typeLike.unit);
|
|
126
|
-
}
|
|
127
|
-
function sanitizeList(typeLike) {
|
|
128
|
-
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
129
|
-
throw Error("Expected a List type to have an array-like `children` property");
|
|
130
|
-
}
|
|
131
|
-
if (typeLike.children.length !== 1) {
|
|
132
|
-
throw Error("Expected a List type to have exactly one child");
|
|
133
|
-
}
|
|
134
|
-
return new arrow_1.List(sanitizeField(typeLike.children[0]));
|
|
135
|
-
}
|
|
136
|
-
function sanitizeStruct(typeLike) {
|
|
137
|
-
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
138
|
-
throw Error("Expected a Struct type to have an array-like `children` property");
|
|
139
|
-
}
|
|
140
|
-
return new arrow_1.Struct(typeLike.children.map((child) => sanitizeField(child)));
|
|
141
|
-
}
|
|
142
|
-
function sanitizeUnion(typeLike) {
|
|
143
|
-
if (!("typeIds" in typeLike) ||
|
|
144
|
-
!("mode" in typeLike) ||
|
|
145
|
-
typeof typeLike.mode !== "number") {
|
|
146
|
-
throw Error("Expected a Union type to have `typeIds` and `mode` properties");
|
|
147
|
-
}
|
|
148
|
-
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
149
|
-
throw Error("Expected a Union type to have an array-like `children` property");
|
|
150
|
-
}
|
|
151
|
-
return new arrow_1.Union(typeLike.mode,
|
|
152
|
-
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
153
|
-
typeLike.typeIds, typeLike.children.map((child) => sanitizeField(child)));
|
|
154
|
-
}
|
|
155
|
-
function sanitizeTypedUnion(typeLike,
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
157
|
-
UnionType) {
|
|
158
|
-
if (!("typeIds" in typeLike)) {
|
|
159
|
-
throw Error("Expected a DenseUnion/SparseUnion type to have a `typeIds` property");
|
|
160
|
-
}
|
|
161
|
-
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
162
|
-
throw Error("Expected a DenseUnion/SparseUnion type to have an array-like `children` property");
|
|
163
|
-
}
|
|
164
|
-
return new UnionType(typeLike.typeIds, typeLike.children.map((child) => sanitizeField(child)));
|
|
165
|
-
}
|
|
166
|
-
function sanitizeFixedSizeBinary(typeLike) {
|
|
167
|
-
if (!("byteWidth" in typeLike) || typeof typeLike.byteWidth !== "number") {
|
|
168
|
-
throw Error("Expected a FixedSizeBinary type to have a `byteWidth` property");
|
|
169
|
-
}
|
|
170
|
-
return new arrow_1.FixedSizeBinary(typeLike.byteWidth);
|
|
171
|
-
}
|
|
172
|
-
function sanitizeFixedSizeList(typeLike) {
|
|
173
|
-
if (!("listSize" in typeLike) || typeof typeLike.listSize !== "number") {
|
|
174
|
-
throw Error("Expected a FixedSizeList type to have a `listSize` property");
|
|
175
|
-
}
|
|
176
|
-
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
177
|
-
throw Error("Expected a FixedSizeList type to have an array-like `children` property");
|
|
178
|
-
}
|
|
179
|
-
if (typeLike.children.length !== 1) {
|
|
180
|
-
throw Error("Expected a FixedSizeList type to have exactly one child");
|
|
181
|
-
}
|
|
182
|
-
return new arrow_1.FixedSizeList(typeLike.listSize, sanitizeField(typeLike.children[0]));
|
|
183
|
-
}
|
|
184
|
-
function sanitizeMap(typeLike) {
|
|
185
|
-
if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
|
|
186
|
-
throw Error("Expected a Map type to have an array-like `children` property");
|
|
187
|
-
}
|
|
188
|
-
if (!("keysSorted" in typeLike) || typeof typeLike.keysSorted !== "boolean") {
|
|
189
|
-
throw Error("Expected a Map type to have a `keysSorted` property");
|
|
190
|
-
}
|
|
191
|
-
return new arrow_1.Map_(
|
|
192
|
-
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
193
|
-
typeLike.children.map((field) => sanitizeField(field)), typeLike.keysSorted);
|
|
194
|
-
}
|
|
195
|
-
function sanitizeDuration(typeLike) {
|
|
196
|
-
if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
|
|
197
|
-
throw Error("Expected a Duration type to have a `unit` property");
|
|
198
|
-
}
|
|
199
|
-
return new arrow_1.Duration(typeLike.unit);
|
|
200
|
-
}
|
|
201
|
-
function sanitizeDictionary(typeLike) {
|
|
202
|
-
if (!("id" in typeLike) || typeof typeLike.id !== "number") {
|
|
203
|
-
throw Error("Expected a Dictionary type to have an `id` property");
|
|
204
|
-
}
|
|
205
|
-
if (!("indices" in typeLike) || typeof typeLike.indices !== "object") {
|
|
206
|
-
throw Error("Expected a Dictionary type to have an `indices` property");
|
|
207
|
-
}
|
|
208
|
-
if (!("dictionary" in typeLike) || typeof typeLike.dictionary !== "object") {
|
|
209
|
-
throw Error("Expected a Dictionary type to have an `dictionary` property");
|
|
210
|
-
}
|
|
211
|
-
if (!("isOrdered" in typeLike) || typeof typeLike.isOrdered !== "boolean") {
|
|
212
|
-
throw Error("Expected a Dictionary type to have an `isOrdered` property");
|
|
213
|
-
}
|
|
214
|
-
return new arrow_1.Dictionary(sanitizeType(typeLike.dictionary), sanitizeType(typeLike.indices), typeLike.id, typeLike.isOrdered);
|
|
215
|
-
}
|
|
216
|
-
// biome-ignore lint/suspicious/noExplicitAny: skip
|
|
217
|
-
function sanitizeType(typeLike) {
|
|
218
|
-
if (typeof typeLike !== "object" || typeLike === null) {
|
|
219
|
-
throw Error("Expected a Type but object was null/undefined");
|
|
220
|
-
}
|
|
221
|
-
if (!("typeId" in typeLike) ||
|
|
222
|
-
!(typeof typeLike.typeId !== "function" ||
|
|
223
|
-
typeof typeLike.typeId !== "number")) {
|
|
224
|
-
throw Error("Expected a Type to have a typeId property");
|
|
225
|
-
}
|
|
226
|
-
let typeId;
|
|
227
|
-
if (typeof typeLike.typeId === "function") {
|
|
228
|
-
typeId = typeLike.typeId();
|
|
229
|
-
}
|
|
230
|
-
else if (typeof typeLike.typeId === "number") {
|
|
231
|
-
typeId = typeLike.typeId;
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
throw Error("Type's typeId property was not a function or number");
|
|
235
|
-
}
|
|
236
|
-
switch (typeId) {
|
|
237
|
-
case arrow_1.Type.NONE:
|
|
238
|
-
throw Error("Received a Type with a typeId of NONE");
|
|
239
|
-
case arrow_1.Type.Null:
|
|
240
|
-
return new arrow_1.Null();
|
|
241
|
-
case arrow_1.Type.Int:
|
|
242
|
-
return sanitizeInt(typeLike);
|
|
243
|
-
case arrow_1.Type.Float:
|
|
244
|
-
return sanitizeFloat(typeLike);
|
|
245
|
-
case arrow_1.Type.Binary:
|
|
246
|
-
return new arrow_1.Binary();
|
|
247
|
-
case arrow_1.Type.Utf8:
|
|
248
|
-
return new arrow_1.Utf8();
|
|
249
|
-
case arrow_1.Type.Bool:
|
|
250
|
-
return new arrow_1.Bool();
|
|
251
|
-
case arrow_1.Type.Decimal:
|
|
252
|
-
return sanitizeDecimal(typeLike);
|
|
253
|
-
case arrow_1.Type.Date:
|
|
254
|
-
return sanitizeDate(typeLike);
|
|
255
|
-
case arrow_1.Type.Time:
|
|
256
|
-
return sanitizeTime(typeLike);
|
|
257
|
-
case arrow_1.Type.Timestamp:
|
|
258
|
-
return sanitizeTimestamp(typeLike);
|
|
259
|
-
case arrow_1.Type.Interval:
|
|
260
|
-
return sanitizeInterval(typeLike);
|
|
261
|
-
case arrow_1.Type.List:
|
|
262
|
-
return sanitizeList(typeLike);
|
|
263
|
-
case arrow_1.Type.Struct:
|
|
264
|
-
return sanitizeStruct(typeLike);
|
|
265
|
-
case arrow_1.Type.Union:
|
|
266
|
-
return sanitizeUnion(typeLike);
|
|
267
|
-
case arrow_1.Type.FixedSizeBinary:
|
|
268
|
-
return sanitizeFixedSizeBinary(typeLike);
|
|
269
|
-
case arrow_1.Type.FixedSizeList:
|
|
270
|
-
return sanitizeFixedSizeList(typeLike);
|
|
271
|
-
case arrow_1.Type.Map:
|
|
272
|
-
return sanitizeMap(typeLike);
|
|
273
|
-
case arrow_1.Type.Duration:
|
|
274
|
-
return sanitizeDuration(typeLike);
|
|
275
|
-
case arrow_1.Type.Dictionary:
|
|
276
|
-
return sanitizeDictionary(typeLike);
|
|
277
|
-
case arrow_1.Type.Int8:
|
|
278
|
-
return new arrow_1.Int8();
|
|
279
|
-
case arrow_1.Type.Int16:
|
|
280
|
-
return new arrow_1.Int16();
|
|
281
|
-
case arrow_1.Type.Int32:
|
|
282
|
-
return new arrow_1.Int32();
|
|
283
|
-
case arrow_1.Type.Int64:
|
|
284
|
-
return new arrow_1.Int64();
|
|
285
|
-
case arrow_1.Type.Uint8:
|
|
286
|
-
return new arrow_1.Uint8();
|
|
287
|
-
case arrow_1.Type.Uint16:
|
|
288
|
-
return new arrow_1.Uint16();
|
|
289
|
-
case arrow_1.Type.Uint32:
|
|
290
|
-
return new arrow_1.Uint32();
|
|
291
|
-
case arrow_1.Type.Uint64:
|
|
292
|
-
return new arrow_1.Uint64();
|
|
293
|
-
case arrow_1.Type.Float16:
|
|
294
|
-
return new arrow_1.Float16();
|
|
295
|
-
case arrow_1.Type.Float32:
|
|
296
|
-
return new arrow_1.Float32();
|
|
297
|
-
case arrow_1.Type.Float64:
|
|
298
|
-
return new arrow_1.Float64();
|
|
299
|
-
case arrow_1.Type.DateMillisecond:
|
|
300
|
-
return new arrow_1.DateMillisecond();
|
|
301
|
-
case arrow_1.Type.DateDay:
|
|
302
|
-
return new arrow_1.DateDay();
|
|
303
|
-
case arrow_1.Type.TimeNanosecond:
|
|
304
|
-
return new arrow_1.TimeNanosecond();
|
|
305
|
-
case arrow_1.Type.TimeMicrosecond:
|
|
306
|
-
return new arrow_1.TimeMicrosecond();
|
|
307
|
-
case arrow_1.Type.TimeMillisecond:
|
|
308
|
-
return new arrow_1.TimeMillisecond();
|
|
309
|
-
case arrow_1.Type.TimeSecond:
|
|
310
|
-
return new arrow_1.TimeSecond();
|
|
311
|
-
case arrow_1.Type.TimestampNanosecond:
|
|
312
|
-
return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampNanosecond);
|
|
313
|
-
case arrow_1.Type.TimestampMicrosecond:
|
|
314
|
-
return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampMicrosecond);
|
|
315
|
-
case arrow_1.Type.TimestampMillisecond:
|
|
316
|
-
return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampMillisecond);
|
|
317
|
-
case arrow_1.Type.TimestampSecond:
|
|
318
|
-
return sanitizeTypedTimestamp(typeLike, arrow_1.TimestampSecond);
|
|
319
|
-
case arrow_1.Type.DenseUnion:
|
|
320
|
-
return sanitizeTypedUnion(typeLike, arrow_1.DenseUnion);
|
|
321
|
-
case arrow_1.Type.SparseUnion:
|
|
322
|
-
return sanitizeTypedUnion(typeLike, arrow_1.SparseUnion);
|
|
323
|
-
case arrow_1.Type.IntervalDayTime:
|
|
324
|
-
return new arrow_1.IntervalDayTime();
|
|
325
|
-
case arrow_1.Type.IntervalYearMonth:
|
|
326
|
-
return new arrow_1.IntervalYearMonth();
|
|
327
|
-
case arrow_1.Type.DurationNanosecond:
|
|
328
|
-
return new arrow_1.DurationNanosecond();
|
|
329
|
-
case arrow_1.Type.DurationMicrosecond:
|
|
330
|
-
return new arrow_1.DurationMicrosecond();
|
|
331
|
-
case arrow_1.Type.DurationMillisecond:
|
|
332
|
-
return new arrow_1.DurationMillisecond();
|
|
333
|
-
case arrow_1.Type.DurationSecond:
|
|
334
|
-
return new arrow_1.DurationSecond();
|
|
335
|
-
default:
|
|
336
|
-
throw new Error("Unrecoginized type id in schema: " + typeId);
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function sanitizeField(fieldLike) {
|
|
340
|
-
if (fieldLike instanceof arrow_1.Field) {
|
|
341
|
-
return fieldLike;
|
|
342
|
-
}
|
|
343
|
-
if (typeof fieldLike !== "object" || fieldLike === null) {
|
|
344
|
-
throw Error("Expected a Field but object was null/undefined");
|
|
345
|
-
}
|
|
346
|
-
if (!("type" in fieldLike) ||
|
|
347
|
-
!("name" in fieldLike) ||
|
|
348
|
-
!("nullable" in fieldLike)) {
|
|
349
|
-
throw Error("The field passed in is missing a `type`/`name`/`nullable` property");
|
|
350
|
-
}
|
|
351
|
-
const type = sanitizeType(fieldLike.type);
|
|
352
|
-
const name = fieldLike.name;
|
|
353
|
-
if (!(typeof name === "string")) {
|
|
354
|
-
throw Error("The field passed in had a non-string `name` property");
|
|
355
|
-
}
|
|
356
|
-
const nullable = fieldLike.nullable;
|
|
357
|
-
if (!(typeof nullable === "boolean")) {
|
|
358
|
-
throw Error("The field passed in had a non-boolean `nullable` property");
|
|
359
|
-
}
|
|
360
|
-
let metadata;
|
|
361
|
-
if ("metadata" in fieldLike) {
|
|
362
|
-
metadata = sanitizeMetadata(fieldLike.metadata);
|
|
363
|
-
}
|
|
364
|
-
return new arrow_1.Field(name, type, nullable, metadata);
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Convert something schemaLike into a Schema instance
|
|
368
|
-
*
|
|
369
|
-
* This method is often needed even when the caller is using a Schema
|
|
370
|
-
* instance because they might be using a different instance of apache-arrow
|
|
371
|
-
* than lancedb is using.
|
|
372
|
-
*/
|
|
373
|
-
function sanitizeSchema(schemaLike) {
|
|
374
|
-
if (schemaLike instanceof arrow_1.Schema) {
|
|
375
|
-
return schemaLike;
|
|
376
|
-
}
|
|
377
|
-
if (typeof schemaLike !== "object" || schemaLike === null) {
|
|
378
|
-
throw Error("Expected a Schema but object was null/undefined");
|
|
379
|
-
}
|
|
380
|
-
if (!("fields" in schemaLike)) {
|
|
381
|
-
throw Error("The schema passed in does not appear to be a schema (no 'fields' property)");
|
|
382
|
-
}
|
|
383
|
-
let metadata;
|
|
384
|
-
if ("metadata" in schemaLike) {
|
|
385
|
-
metadata = sanitizeMetadata(schemaLike.metadata);
|
|
386
|
-
}
|
|
387
|
-
if (!Array.isArray(schemaLike.fields)) {
|
|
388
|
-
throw Error("The schema passed in had a 'fields' property but it was not an array");
|
|
389
|
-
}
|
|
390
|
-
const sanitizedFields = schemaLike.fields.map((field) => sanitizeField(field));
|
|
391
|
-
return new arrow_1.Schema(sanitizedFields, metadata);
|
|
392
|
-
}
|
|
393
|
-
function sanitizeTable(tableLike) {
|
|
394
|
-
if (tableLike instanceof arrow_1.Table) {
|
|
395
|
-
return tableLike;
|
|
396
|
-
}
|
|
397
|
-
if (typeof tableLike !== "object" || tableLike === null) {
|
|
398
|
-
throw Error("Expected a Table but object was null/undefined");
|
|
399
|
-
}
|
|
400
|
-
if (!("schema" in tableLike)) {
|
|
401
|
-
throw Error("The table passed in does not appear to be a table (no 'schema' property)");
|
|
402
|
-
}
|
|
403
|
-
if (!("batches" in tableLike)) {
|
|
404
|
-
throw Error("The table passed in does not appear to be a table (no 'columns' property)");
|
|
405
|
-
}
|
|
406
|
-
const schema = sanitizeSchema(tableLike.schema);
|
|
407
|
-
const batches = tableLike.batches.map(sanitizeRecordBatch);
|
|
408
|
-
return new arrow_1.Table(schema, batches);
|
|
409
|
-
}
|
|
410
|
-
function sanitizeRecordBatch(batchLike) {
|
|
411
|
-
if (batchLike instanceof arrow_1.RecordBatch) {
|
|
412
|
-
return batchLike;
|
|
413
|
-
}
|
|
414
|
-
if (typeof batchLike !== "object" || batchLike === null) {
|
|
415
|
-
throw Error("Expected a RecordBatch but object was null/undefined");
|
|
416
|
-
}
|
|
417
|
-
if (!("schema" in batchLike)) {
|
|
418
|
-
throw Error("The record batch passed in does not appear to be a record batch (no 'schema' property)");
|
|
419
|
-
}
|
|
420
|
-
if (!("data" in batchLike)) {
|
|
421
|
-
throw Error("The record batch passed in does not appear to be a record batch (no 'data' property)");
|
|
422
|
-
}
|
|
423
|
-
const schema = sanitizeSchema(batchLike.schema);
|
|
424
|
-
const data = sanitizeData(batchLike.data);
|
|
425
|
-
return new arrow_1.RecordBatch(schema, data);
|
|
426
|
-
}
|
|
427
|
-
function sanitizeData(dataLike) {
|
|
428
|
-
if (dataLike instanceof apache_arrow_1.Data) {
|
|
429
|
-
return dataLike;
|
|
430
|
-
}
|
|
431
|
-
return new apache_arrow_1.Data(dataLike.type, dataLike.offset, dataLike.length, dataLike.nullCount, {
|
|
432
|
-
[apache_arrow_1.BufferType.OFFSET]: dataLike.valueOffsets,
|
|
433
|
-
[apache_arrow_1.BufferType.DATA]: dataLike.values,
|
|
434
|
-
[apache_arrow_1.BufferType.VALIDITY]: dataLike.nullBitmap,
|
|
435
|
-
[apache_arrow_1.BufferType.TYPE]: dataLike.typeIds,
|
|
436
|
-
});
|
|
437
|
-
}
|