@lancedb/lancedb 0.7.1 → 0.9.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.
Files changed (92) hide show
  1. package/dist/arrow.d.ts +2 -3
  2. package/dist/arrow.js +2 -27
  3. package/dist/connection.d.ts +9 -0
  4. package/dist/connection.js +16 -2
  5. package/dist/embedding/embedding_function.d.ts +11 -0
  6. package/dist/embedding/embedding_function.js +28 -7
  7. package/dist/embedding/index.d.ts +2 -1
  8. package/dist/embedding/index.js +7 -6
  9. package/dist/embedding/openai.d.ts +1 -1
  10. package/dist/embedding/registry.d.ts +9 -7
  11. package/dist/embedding/registry.js +24 -6
  12. package/dist/embedding/transformers.d.ts +37 -0
  13. package/dist/embedding/transformers.js +147 -0
  14. package/dist/index.d.ts +1 -1
  15. package/dist/query.js +15 -9
  16. package/dist/remote/client.d.ts +1 -1
  17. package/dist/remote/client.js +6 -8
  18. package/dist/remote/connection.d.ts +2 -3
  19. package/dist/remote/connection.js +2 -2
  20. package/dist/sanitize.js +4 -2
  21. package/dist/table.d.ts +3 -0
  22. package/dist/table.js +1 -1
  23. package/package.json +17 -13
  24. package/Cargo.toml +0 -28
  25. package/biome.json +0 -158
  26. package/build.rs +0 -5
  27. package/dist/native.d.ts +0 -208
  28. package/examples/ann_indexes.ts +0 -49
  29. package/examples/basic.ts +0 -149
  30. package/examples/embedding.ts +0 -83
  31. package/examples/filtering.ts +0 -34
  32. package/examples/jsconfig.json +0 -27
  33. package/examples/package-lock.json +0 -79
  34. package/examples/package.json +0 -18
  35. package/examples/search.ts +0 -37
  36. package/jest.config.js +0 -7
  37. package/lancedb/arrow.ts +0 -947
  38. package/lancedb/connection.ts +0 -333
  39. package/lancedb/embedding/embedding_function.ts +0 -194
  40. package/lancedb/embedding/index.ts +0 -113
  41. package/lancedb/embedding/openai.ts +0 -113
  42. package/lancedb/embedding/registry.ts +0 -188
  43. package/lancedb/index.ts +0 -142
  44. package/lancedb/indices.ts +0 -203
  45. package/lancedb/merge.ts +0 -70
  46. package/lancedb/query.ts +0 -507
  47. package/lancedb/remote/client.ts +0 -221
  48. package/lancedb/remote/connection.ts +0 -201
  49. package/lancedb/remote/index.ts +0 -3
  50. package/lancedb/remote/table.ts +0 -226
  51. package/lancedb/sanitize.ts +0 -588
  52. package/lancedb/table.ts +0 -669
  53. package/lancedb/util.ts +0 -69
  54. package/native.d.ts +0 -208
  55. package/nodejs-artifacts/arrow.d.ts +0 -250
  56. package/nodejs-artifacts/arrow.js +0 -768
  57. package/nodejs-artifacts/connection.d.ts +0 -171
  58. package/nodejs-artifacts/connection.js +0 -135
  59. package/nodejs-artifacts/embedding/embedding_function.d.ts +0 -79
  60. package/nodejs-artifacts/embedding/embedding_function.js +0 -112
  61. package/nodejs-artifacts/embedding/index.d.ts +0 -28
  62. package/nodejs-artifacts/embedding/index.js +0 -114
  63. package/nodejs-artifacts/embedding/openai.d.ts +0 -18
  64. package/nodejs-artifacts/embedding/openai.js +0 -105
  65. package/nodejs-artifacts/embedding/registry.d.ts +0 -53
  66. package/nodejs-artifacts/embedding/registry.js +0 -127
  67. package/nodejs-artifacts/index.d.ts +0 -55
  68. package/nodejs-artifacts/index.js +0 -57
  69. package/nodejs-artifacts/indices.d.ts +0 -165
  70. package/nodejs-artifacts/indices.js +0 -71
  71. package/nodejs-artifacts/merge.d.ts +0 -54
  72. package/nodejs-artifacts/merge.js +0 -64
  73. package/nodejs-artifacts/native.d.ts +0 -208
  74. package/nodejs-artifacts/native.js +0 -330
  75. package/nodejs-artifacts/query.d.ts +0 -283
  76. package/nodejs-artifacts/query.js +0 -448
  77. package/nodejs-artifacts/remote/client.d.ts +0 -28
  78. package/nodejs-artifacts/remote/client.js +0 -172
  79. package/nodejs-artifacts/remote/connection.d.ts +0 -25
  80. package/nodejs-artifacts/remote/connection.js +0 -110
  81. package/nodejs-artifacts/remote/index.d.ts +0 -3
  82. package/nodejs-artifacts/remote/index.js +0 -9
  83. package/nodejs-artifacts/remote/table.d.ts +0 -42
  84. package/nodejs-artifacts/remote/table.js +0 -179
  85. package/nodejs-artifacts/sanitize.d.ts +0 -31
  86. package/nodejs-artifacts/sanitize.js +0 -436
  87. package/nodejs-artifacts/table.d.ts +0 -395
  88. package/nodejs-artifacts/table.js +0 -230
  89. package/nodejs-artifacts/util.d.ts +0 -14
  90. package/nodejs-artifacts/util.js +0 -65
  91. package/tsconfig.json +0 -25
  92. package/typedoc.json +0 -10
@@ -1,588 +0,0 @@
1
- // Copyright 2023 LanceDB Developers.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- // The utilities in this file help sanitize data from the user's arrow
16
- // library into the types expected by vectordb's arrow library. Node
17
- // generally allows for mulitple versions of the same library (and sometimes
18
- // even multiple copies of the same version) to be installed at the same
19
- // time. However, arrow-js uses instanceof which expected that the input
20
- // comes from the exact same library instance. This is not always the case
21
- // and so we must sanitize the input to ensure that it is compatible.
22
-
23
- import { BufferType, Data } from "apache-arrow";
24
- import type { IntBitWidth, TKeys, TimeBitWidth } from "apache-arrow/type";
25
- import {
26
- Binary,
27
- Bool,
28
- DataLike,
29
- DataType,
30
- DateDay,
31
- DateMillisecond,
32
- type DateUnit,
33
- Date_,
34
- Decimal,
35
- DenseUnion,
36
- Dictionary,
37
- Duration,
38
- DurationMicrosecond,
39
- DurationMillisecond,
40
- DurationNanosecond,
41
- DurationSecond,
42
- Field,
43
- FixedSizeBinary,
44
- FixedSizeList,
45
- Float,
46
- Float16,
47
- Float32,
48
- Float64,
49
- Int,
50
- Int8,
51
- Int16,
52
- Int32,
53
- Int64,
54
- Interval,
55
- IntervalDayTime,
56
- IntervalYearMonth,
57
- List,
58
- Map_,
59
- Null,
60
- type Precision,
61
- RecordBatch,
62
- RecordBatchLike,
63
- Schema,
64
- SchemaLike,
65
- SparseUnion,
66
- Struct,
67
- Table,
68
- TableLike,
69
- Time,
70
- TimeMicrosecond,
71
- TimeMillisecond,
72
- TimeNanosecond,
73
- TimeSecond,
74
- Timestamp,
75
- TimestampMicrosecond,
76
- TimestampMillisecond,
77
- TimestampNanosecond,
78
- TimestampSecond,
79
- Type,
80
- Uint8,
81
- Uint16,
82
- Uint32,
83
- Uint64,
84
- Union,
85
- Utf8,
86
- } from "./arrow";
87
-
88
- export function sanitizeMetadata(
89
- metadataLike?: unknown,
90
- ): Map<string, string> | undefined {
91
- if (metadataLike === undefined || metadataLike === null) {
92
- return undefined;
93
- }
94
- if (!(metadataLike instanceof Map)) {
95
- throw Error("Expected metadata, if present, to be a Map<string, string>");
96
- }
97
- for (const item of metadataLike) {
98
- if (!(typeof item[0] === "string" || !(typeof item[1] === "string"))) {
99
- throw Error(
100
- "Expected metadata, if present, to be a Map<string, string> but it had non-string keys or values",
101
- );
102
- }
103
- }
104
- return metadataLike as Map<string, string>;
105
- }
106
-
107
- export function sanitizeInt(typeLike: object) {
108
- if (
109
- !("bitWidth" in typeLike) ||
110
- typeof typeLike.bitWidth !== "number" ||
111
- !("isSigned" in typeLike) ||
112
- typeof typeLike.isSigned !== "boolean"
113
- ) {
114
- throw Error(
115
- "Expected an Int Type to have a `bitWidth` and `isSigned` property",
116
- );
117
- }
118
- return new Int(typeLike.isSigned, typeLike.bitWidth as IntBitWidth);
119
- }
120
-
121
- export function sanitizeFloat(typeLike: object) {
122
- if (!("precision" in typeLike) || typeof typeLike.precision !== "number") {
123
- throw Error("Expected a Float Type to have a `precision` property");
124
- }
125
- return new Float(typeLike.precision as Precision);
126
- }
127
-
128
- export function sanitizeDecimal(typeLike: object) {
129
- if (
130
- !("scale" in typeLike) ||
131
- typeof typeLike.scale !== "number" ||
132
- !("precision" in typeLike) ||
133
- typeof typeLike.precision !== "number" ||
134
- !("bitWidth" in typeLike) ||
135
- typeof typeLike.bitWidth !== "number"
136
- ) {
137
- throw Error(
138
- "Expected a Decimal Type to have `scale`, `precision`, and `bitWidth` properties",
139
- );
140
- }
141
- return new Decimal(typeLike.scale, typeLike.precision, typeLike.bitWidth);
142
- }
143
-
144
- export function sanitizeDate(typeLike: object) {
145
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
146
- throw Error("Expected a Date type to have a `unit` property");
147
- }
148
- return new Date_(typeLike.unit as DateUnit);
149
- }
150
-
151
- export function sanitizeTime(typeLike: object) {
152
- if (
153
- !("unit" in typeLike) ||
154
- typeof typeLike.unit !== "number" ||
155
- !("bitWidth" in typeLike) ||
156
- typeof typeLike.bitWidth !== "number"
157
- ) {
158
- throw Error(
159
- "Expected a Time type to have `unit` and `bitWidth` properties",
160
- );
161
- }
162
- return new Time(typeLike.unit, typeLike.bitWidth as TimeBitWidth);
163
- }
164
-
165
- export function sanitizeTimestamp(typeLike: object) {
166
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
167
- throw Error("Expected a Timestamp type to have a `unit` property");
168
- }
169
- let timezone = null;
170
- if ("timezone" in typeLike && typeof typeLike.timezone === "string") {
171
- timezone = typeLike.timezone;
172
- }
173
- return new Timestamp(typeLike.unit, timezone);
174
- }
175
-
176
- export function sanitizeTypedTimestamp(
177
- typeLike: object,
178
- // eslint-disable-next-line @typescript-eslint/naming-convention
179
- Datatype:
180
- | typeof TimestampNanosecond
181
- | typeof TimestampMicrosecond
182
- | typeof TimestampMillisecond
183
- | typeof TimestampSecond,
184
- ) {
185
- let timezone = null;
186
- if ("timezone" in typeLike && typeof typeLike.timezone === "string") {
187
- timezone = typeLike.timezone;
188
- }
189
- return new Datatype(timezone);
190
- }
191
-
192
- export function sanitizeInterval(typeLike: object) {
193
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
194
- throw Error("Expected an Interval type to have a `unit` property");
195
- }
196
- return new Interval(typeLike.unit);
197
- }
198
-
199
- export function sanitizeList(typeLike: object) {
200
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
201
- throw Error(
202
- "Expected a List type to have an array-like `children` property",
203
- );
204
- }
205
- if (typeLike.children.length !== 1) {
206
- throw Error("Expected a List type to have exactly one child");
207
- }
208
- return new List(sanitizeField(typeLike.children[0]));
209
- }
210
-
211
- export function sanitizeStruct(typeLike: object) {
212
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
213
- throw Error(
214
- "Expected a Struct type to have an array-like `children` property",
215
- );
216
- }
217
- return new Struct(typeLike.children.map((child) => sanitizeField(child)));
218
- }
219
-
220
- export function sanitizeUnion(typeLike: object) {
221
- if (
222
- !("typeIds" in typeLike) ||
223
- !("mode" in typeLike) ||
224
- typeof typeLike.mode !== "number"
225
- ) {
226
- throw Error(
227
- "Expected a Union type to have `typeIds` and `mode` properties",
228
- );
229
- }
230
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
231
- throw Error(
232
- "Expected a Union type to have an array-like `children` property",
233
- );
234
- }
235
-
236
- return new Union(
237
- typeLike.mode,
238
- // biome-ignore lint/suspicious/noExplicitAny: skip
239
- typeLike.typeIds as any,
240
- typeLike.children.map((child) => sanitizeField(child)),
241
- );
242
- }
243
-
244
- export function sanitizeTypedUnion(
245
- typeLike: object,
246
- // eslint-disable-next-line @typescript-eslint/naming-convention
247
- UnionType: typeof DenseUnion | typeof SparseUnion,
248
- ) {
249
- if (!("typeIds" in typeLike)) {
250
- throw Error(
251
- "Expected a DenseUnion/SparseUnion type to have a `typeIds` property",
252
- );
253
- }
254
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
255
- throw Error(
256
- "Expected a DenseUnion/SparseUnion type to have an array-like `children` property",
257
- );
258
- }
259
-
260
- return new UnionType(
261
- typeLike.typeIds as Int32Array | number[],
262
- typeLike.children.map((child) => sanitizeField(child)),
263
- );
264
- }
265
-
266
- export function sanitizeFixedSizeBinary(typeLike: object) {
267
- if (!("byteWidth" in typeLike) || typeof typeLike.byteWidth !== "number") {
268
- throw Error(
269
- "Expected a FixedSizeBinary type to have a `byteWidth` property",
270
- );
271
- }
272
- return new FixedSizeBinary(typeLike.byteWidth);
273
- }
274
-
275
- export function sanitizeFixedSizeList(typeLike: object) {
276
- if (!("listSize" in typeLike) || typeof typeLike.listSize !== "number") {
277
- throw Error("Expected a FixedSizeList type to have a `listSize` property");
278
- }
279
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
280
- throw Error(
281
- "Expected a FixedSizeList type to have an array-like `children` property",
282
- );
283
- }
284
- if (typeLike.children.length !== 1) {
285
- throw Error("Expected a FixedSizeList type to have exactly one child");
286
- }
287
- return new FixedSizeList(
288
- typeLike.listSize,
289
- sanitizeField(typeLike.children[0]),
290
- );
291
- }
292
-
293
- export function sanitizeMap(typeLike: object) {
294
- if (!("children" in typeLike) || !Array.isArray(typeLike.children)) {
295
- throw Error(
296
- "Expected a Map type to have an array-like `children` property",
297
- );
298
- }
299
- if (!("keysSorted" in typeLike) || typeof typeLike.keysSorted !== "boolean") {
300
- throw Error("Expected a Map type to have a `keysSorted` property");
301
- }
302
-
303
- return new Map_(
304
- // biome-ignore lint/suspicious/noExplicitAny: skip
305
- typeLike.children.map((field) => sanitizeField(field)) as any,
306
- typeLike.keysSorted,
307
- );
308
- }
309
-
310
- export function sanitizeDuration(typeLike: object) {
311
- if (!("unit" in typeLike) || typeof typeLike.unit !== "number") {
312
- throw Error("Expected a Duration type to have a `unit` property");
313
- }
314
- return new Duration(typeLike.unit);
315
- }
316
-
317
- export function sanitizeDictionary(typeLike: object) {
318
- if (!("id" in typeLike) || typeof typeLike.id !== "number") {
319
- throw Error("Expected a Dictionary type to have an `id` property");
320
- }
321
- if (!("indices" in typeLike) || typeof typeLike.indices !== "object") {
322
- throw Error("Expected a Dictionary type to have an `indices` property");
323
- }
324
- if (!("dictionary" in typeLike) || typeof typeLike.dictionary !== "object") {
325
- throw Error("Expected a Dictionary type to have an `dictionary` property");
326
- }
327
- if (!("isOrdered" in typeLike) || typeof typeLike.isOrdered !== "boolean") {
328
- throw Error("Expected a Dictionary type to have an `isOrdered` property");
329
- }
330
- return new Dictionary(
331
- sanitizeType(typeLike.dictionary),
332
- sanitizeType(typeLike.indices) as TKeys,
333
- typeLike.id,
334
- typeLike.isOrdered,
335
- );
336
- }
337
-
338
- // biome-ignore lint/suspicious/noExplicitAny: skip
339
- export function sanitizeType(typeLike: unknown): DataType<any> {
340
- if (typeof typeLike !== "object" || typeLike === null) {
341
- throw Error("Expected a Type but object was null/undefined");
342
- }
343
- if (!("typeId" in typeLike) || !(typeof typeLike.typeId !== "function")) {
344
- throw Error("Expected a Type to have a typeId function");
345
- }
346
- let typeId: Type;
347
- if (typeof typeLike.typeId === "function") {
348
- typeId = (typeLike.typeId as () => unknown)() as Type;
349
- } else if (typeof typeLike.typeId === "number") {
350
- typeId = typeLike.typeId as Type;
351
- } else {
352
- throw Error("Type's typeId property was not a function or number");
353
- }
354
-
355
- switch (typeId) {
356
- case Type.NONE:
357
- throw Error("Received a Type with a typeId of NONE");
358
- case Type.Null:
359
- return new Null();
360
- case Type.Int:
361
- return sanitizeInt(typeLike);
362
- case Type.Float:
363
- return sanitizeFloat(typeLike);
364
- case Type.Binary:
365
- return new Binary();
366
- case Type.Utf8:
367
- return new Utf8();
368
- case Type.Bool:
369
- return new Bool();
370
- case Type.Decimal:
371
- return sanitizeDecimal(typeLike);
372
- case Type.Date:
373
- return sanitizeDate(typeLike);
374
- case Type.Time:
375
- return sanitizeTime(typeLike);
376
- case Type.Timestamp:
377
- return sanitizeTimestamp(typeLike);
378
- case Type.Interval:
379
- return sanitizeInterval(typeLike);
380
- case Type.List:
381
- return sanitizeList(typeLike);
382
- case Type.Struct:
383
- return sanitizeStruct(typeLike);
384
- case Type.Union:
385
- return sanitizeUnion(typeLike);
386
- case Type.FixedSizeBinary:
387
- return sanitizeFixedSizeBinary(typeLike);
388
- case Type.FixedSizeList:
389
- return sanitizeFixedSizeList(typeLike);
390
- case Type.Map:
391
- return sanitizeMap(typeLike);
392
- case Type.Duration:
393
- return sanitizeDuration(typeLike);
394
- case Type.Dictionary:
395
- return sanitizeDictionary(typeLike);
396
- case Type.Int8:
397
- return new Int8();
398
- case Type.Int16:
399
- return new Int16();
400
- case Type.Int32:
401
- return new Int32();
402
- case Type.Int64:
403
- return new Int64();
404
- case Type.Uint8:
405
- return new Uint8();
406
- case Type.Uint16:
407
- return new Uint16();
408
- case Type.Uint32:
409
- return new Uint32();
410
- case Type.Uint64:
411
- return new Uint64();
412
- case Type.Float16:
413
- return new Float16();
414
- case Type.Float32:
415
- return new Float32();
416
- case Type.Float64:
417
- return new Float64();
418
- case Type.DateMillisecond:
419
- return new DateMillisecond();
420
- case Type.DateDay:
421
- return new DateDay();
422
- case Type.TimeNanosecond:
423
- return new TimeNanosecond();
424
- case Type.TimeMicrosecond:
425
- return new TimeMicrosecond();
426
- case Type.TimeMillisecond:
427
- return new TimeMillisecond();
428
- case Type.TimeSecond:
429
- return new TimeSecond();
430
- case Type.TimestampNanosecond:
431
- return sanitizeTypedTimestamp(typeLike, TimestampNanosecond);
432
- case Type.TimestampMicrosecond:
433
- return sanitizeTypedTimestamp(typeLike, TimestampMicrosecond);
434
- case Type.TimestampMillisecond:
435
- return sanitizeTypedTimestamp(typeLike, TimestampMillisecond);
436
- case Type.TimestampSecond:
437
- return sanitizeTypedTimestamp(typeLike, TimestampSecond);
438
- case Type.DenseUnion:
439
- return sanitizeTypedUnion(typeLike, DenseUnion);
440
- case Type.SparseUnion:
441
- return sanitizeTypedUnion(typeLike, SparseUnion);
442
- case Type.IntervalDayTime:
443
- return new IntervalDayTime();
444
- case Type.IntervalYearMonth:
445
- return new IntervalYearMonth();
446
- case Type.DurationNanosecond:
447
- return new DurationNanosecond();
448
- case Type.DurationMicrosecond:
449
- return new DurationMicrosecond();
450
- case Type.DurationMillisecond:
451
- return new DurationMillisecond();
452
- case Type.DurationSecond:
453
- return new DurationSecond();
454
- default:
455
- throw new Error("Unrecoginized type id in schema: " + typeId);
456
- }
457
- }
458
-
459
- export function sanitizeField(fieldLike: unknown): Field {
460
- if (fieldLike instanceof Field) {
461
- return fieldLike;
462
- }
463
- if (typeof fieldLike !== "object" || fieldLike === null) {
464
- throw Error("Expected a Field but object was null/undefined");
465
- }
466
- if (
467
- !("type" in fieldLike) ||
468
- !("name" in fieldLike) ||
469
- !("nullable" in fieldLike)
470
- ) {
471
- throw Error(
472
- "The field passed in is missing a `type`/`name`/`nullable` property",
473
- );
474
- }
475
- const type = sanitizeType(fieldLike.type);
476
- const name = fieldLike.name;
477
- if (!(typeof name === "string")) {
478
- throw Error("The field passed in had a non-string `name` property");
479
- }
480
- const nullable = fieldLike.nullable;
481
- if (!(typeof nullable === "boolean")) {
482
- throw Error("The field passed in had a non-boolean `nullable` property");
483
- }
484
- let metadata;
485
- if ("metadata" in fieldLike) {
486
- metadata = sanitizeMetadata(fieldLike.metadata);
487
- }
488
- return new Field(name, type, nullable, metadata);
489
- }
490
-
491
- /**
492
- * Convert something schemaLike into a Schema instance
493
- *
494
- * This method is often needed even when the caller is using a Schema
495
- * instance because they might be using a different instance of apache-arrow
496
- * than lancedb is using.
497
- */
498
- export function sanitizeSchema(schemaLike: SchemaLike): Schema {
499
- if (schemaLike instanceof Schema) {
500
- return schemaLike;
501
- }
502
- if (typeof schemaLike !== "object" || schemaLike === null) {
503
- throw Error("Expected a Schema but object was null/undefined");
504
- }
505
- if (!("fields" in schemaLike)) {
506
- throw Error(
507
- "The schema passed in does not appear to be a schema (no 'fields' property)",
508
- );
509
- }
510
- let metadata;
511
- if ("metadata" in schemaLike) {
512
- metadata = sanitizeMetadata(schemaLike.metadata);
513
- }
514
- if (!Array.isArray(schemaLike.fields)) {
515
- throw Error(
516
- "The schema passed in had a 'fields' property but it was not an array",
517
- );
518
- }
519
- const sanitizedFields = schemaLike.fields.map((field) =>
520
- sanitizeField(field),
521
- );
522
- return new Schema(sanitizedFields, metadata);
523
- }
524
-
525
- export function sanitizeTable(tableLike: TableLike): Table {
526
- if (tableLike instanceof Table) {
527
- return tableLike;
528
- }
529
- if (typeof tableLike !== "object" || tableLike === null) {
530
- throw Error("Expected a Table but object was null/undefined");
531
- }
532
- if (!("schema" in tableLike)) {
533
- throw Error(
534
- "The table passed in does not appear to be a table (no 'schema' property)",
535
- );
536
- }
537
- if (!("batches" in tableLike)) {
538
- throw Error(
539
- "The table passed in does not appear to be a table (no 'columns' property)",
540
- );
541
- }
542
- const schema = sanitizeSchema(tableLike.schema);
543
-
544
- const batches = tableLike.batches.map(sanitizeRecordBatch);
545
- return new Table(schema, batches);
546
- }
547
-
548
- function sanitizeRecordBatch(batchLike: RecordBatchLike): RecordBatch {
549
- if (batchLike instanceof RecordBatch) {
550
- return batchLike;
551
- }
552
- if (typeof batchLike !== "object" || batchLike === null) {
553
- throw Error("Expected a RecordBatch but object was null/undefined");
554
- }
555
- if (!("schema" in batchLike)) {
556
- throw Error(
557
- "The record batch passed in does not appear to be a record batch (no 'schema' property)",
558
- );
559
- }
560
- if (!("data" in batchLike)) {
561
- throw Error(
562
- "The record batch passed in does not appear to be a record batch (no 'data' property)",
563
- );
564
- }
565
- const schema = sanitizeSchema(batchLike.schema);
566
- const data = sanitizeData(batchLike.data);
567
- return new RecordBatch(schema, data);
568
- }
569
- function sanitizeData(
570
- dataLike: DataLike,
571
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
572
- ): import("apache-arrow").Data<Struct<any>> {
573
- if (dataLike instanceof Data) {
574
- return dataLike;
575
- }
576
- return new Data(
577
- dataLike.type,
578
- dataLike.offset,
579
- dataLike.length,
580
- dataLike.nullCount,
581
- {
582
- [BufferType.OFFSET]: dataLike.valueOffsets,
583
- [BufferType.DATA]: dataLike.values,
584
- [BufferType.VALIDITY]: dataLike.nullBitmap,
585
- [BufferType.TYPE]: dataLike.typeIds,
586
- },
587
- );
588
- }