@loaders.gl/arrow 4.0.3 → 4.1.0-alpha.1

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 (114) hide show
  1. package/dist/arrow-loader.d.ts +6 -3
  2. package/dist/arrow-loader.d.ts.map +1 -1
  3. package/dist/arrow-loader.js +9 -1
  4. package/dist/arrow-loader.js.map +1 -1
  5. package/dist/arrow-worker.js +272 -537
  6. package/dist/dist.dev.js +2399 -269
  7. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +33 -1
  8. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
  9. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +146 -17
  10. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
  11. package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts +13 -0
  12. package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +1 -0
  13. package/dist/geoarrow/{convert-geoarrow-to-geojson.js → convert-geoarrow-to-geojson-geometry.js} +36 -25
  14. package/dist/geoarrow/convert-geoarrow-to-geojson-geometry.js.map +1 -0
  15. package/dist/geoarrow-loader.d.ts +19 -0
  16. package/dist/geoarrow-loader.d.ts.map +1 -0
  17. package/dist/geoarrow-loader.js +23 -0
  18. package/dist/geoarrow-loader.js.map +1 -0
  19. package/dist/geoarrow-writer.d.ts +9 -0
  20. package/dist/geoarrow-writer.d.ts.map +1 -0
  21. package/dist/geoarrow-writer.js +19 -0
  22. package/dist/geoarrow-writer.js.map +1 -0
  23. package/dist/index.cjs +481 -255
  24. package/dist/index.d.ts +9 -12
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +7 -13
  27. package/dist/index.js.map +1 -1
  28. package/dist/lib/arrow-table-batch.d.ts.map +1 -1
  29. package/dist/lib/arrow-table-batch.js.map +1 -1
  30. package/dist/lib/encode-arrow.d.ts.map +1 -1
  31. package/dist/lib/encode-arrow.js.map +1 -1
  32. package/dist/lib/encode-geoarrow.d.ts +15 -0
  33. package/dist/lib/encode-geoarrow.d.ts.map +1 -0
  34. package/dist/lib/encode-geoarrow.js +22 -0
  35. package/dist/lib/encode-geoarrow.js.map +1 -0
  36. package/dist/{lib → parsers}/parse-arrow-in-batches.d.ts +1 -1
  37. package/dist/parsers/parse-arrow-in-batches.d.ts.map +1 -0
  38. package/dist/parsers/parse-arrow-in-batches.js.map +1 -0
  39. package/dist/parsers/parse-arrow-sync.d.ts +6 -0
  40. package/dist/parsers/parse-arrow-sync.d.ts.map +1 -0
  41. package/dist/parsers/parse-arrow-sync.js +28 -0
  42. package/dist/parsers/parse-arrow-sync.js.map +1 -0
  43. package/dist/parsers/parse-geoarrow-in-batches.d.ts +6 -0
  44. package/dist/parsers/parse-geoarrow-in-batches.d.ts.map +1 -0
  45. package/dist/parsers/parse-geoarrow-in-batches.js +5 -0
  46. package/dist/parsers/parse-geoarrow-in-batches.js.map +1 -0
  47. package/dist/parsers/parse-geoarrow-sync.d.ts +6 -0
  48. package/dist/parsers/parse-geoarrow-sync.d.ts.map +1 -0
  49. package/dist/parsers/parse-geoarrow-sync.js +14 -0
  50. package/dist/parsers/parse-geoarrow-sync.js.map +1 -0
  51. package/dist/tables/convert-arrow-to-columnar-table.d.ts +8 -0
  52. package/dist/tables/convert-arrow-to-columnar-table.d.ts.map +1 -0
  53. package/dist/tables/convert-arrow-to-columnar-table.js +15 -0
  54. package/dist/tables/convert-arrow-to-columnar-table.js.map +1 -0
  55. package/dist/tables/convert-arrow-to-geojson-table.d.ts +16 -0
  56. package/dist/tables/convert-arrow-to-geojson-table.d.ts.map +1 -0
  57. package/dist/tables/convert-arrow-to-geojson-table.js +39 -0
  58. package/dist/tables/convert-arrow-to-geojson-table.js.map +1 -0
  59. package/dist/tables/convert-columnar-to-row-table.d.ts +7 -0
  60. package/dist/tables/convert-columnar-to-row-table.d.ts.map +1 -0
  61. package/dist/tables/convert-columnar-to-row-table.js +19 -0
  62. package/dist/tables/convert-columnar-to-row-table.js.map +1 -0
  63. package/dist/triangulate-on-worker.d.ts +36 -0
  64. package/dist/triangulate-on-worker.d.ts.map +1 -0
  65. package/dist/triangulate-on-worker.js +14 -0
  66. package/dist/triangulate-on-worker.js.map +1 -0
  67. package/dist/triangulation-worker.js +887 -0
  68. package/dist/workers/arrow-worker.js +1 -1
  69. package/dist/workers/arrow-worker.js.map +1 -1
  70. package/dist/workers/triangulation-worker-node.d.ts +2 -0
  71. package/dist/workers/triangulation-worker-node.d.ts.map +1 -0
  72. package/dist/workers/triangulation-worker-node.js +2 -0
  73. package/dist/workers/triangulation-worker-node.js.map +1 -0
  74. package/dist/workers/triangulation-worker.d.ts +2 -0
  75. package/dist/workers/triangulation-worker.d.ts.map +1 -0
  76. package/dist/workers/triangulation-worker.js +26 -0
  77. package/dist/workers/triangulation-worker.js.map +1 -0
  78. package/package.json +20 -12
  79. package/src/arrow-loader.ts +25 -3
  80. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +247 -23
  81. package/src/geoarrow/{convert-geoarrow-to-geojson.ts → convert-geoarrow-to-geojson-geometry.ts} +58 -44
  82. package/src/geoarrow-loader.ts +51 -0
  83. package/src/geoarrow-writer.ts +41 -0
  84. package/src/index.ts +31 -37
  85. package/src/lib/arrow-table-batch.ts +3 -0
  86. package/src/lib/encode-arrow.ts +3 -0
  87. package/src/lib/encode-geoarrow.ts +45 -0
  88. package/src/{lib → parsers}/parse-arrow-in-batches.ts +4 -2
  89. package/src/parsers/parse-arrow-sync.ts +43 -0
  90. package/src/parsers/parse-geoarrow-in-batches.ts +15 -0
  91. package/src/parsers/parse-geoarrow-sync.ts +22 -0
  92. package/src/tables/convert-arrow-to-columnar-table.ts +30 -0
  93. package/src/tables/convert-arrow-to-geojson-table.ts +65 -0
  94. package/src/tables/convert-columnar-to-row-table.ts +30 -0
  95. package/src/triangulate-on-worker.ts +47 -0
  96. package/src/workers/arrow-worker.ts +1 -1
  97. package/src/workers/triangulation-worker-node.ts +4 -0
  98. package/src/workers/triangulation-worker.ts +39 -0
  99. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts +0 -19
  100. package/dist/geoarrow/convert-geoarrow-to-geojson.d.ts.map +0 -1
  101. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +0 -1
  102. package/dist/lib/parse-arrow-in-batches.d.ts.map +0 -1
  103. package/dist/lib/parse-arrow-in-batches.js.map +0 -1
  104. package/dist/lib/parse-arrow-sync.d.ts +0 -5
  105. package/dist/lib/parse-arrow-sync.d.ts.map +0 -1
  106. package/dist/lib/parse-arrow-sync.js +0 -21
  107. package/dist/lib/parse-arrow-sync.js.map +0 -1
  108. package/dist/tables/convert-arrow-to-table.d.ts +0 -21
  109. package/dist/tables/convert-arrow-to-table.d.ts.map +0 -1
  110. package/dist/tables/convert-arrow-to-table.js +0 -37
  111. package/dist/tables/convert-arrow-to-table.js.map +0 -1
  112. package/src/lib/parse-arrow-sync.ts +0 -35
  113. package/src/tables/convert-arrow-to-table.ts +0 -68
  114. /package/dist/{lib → parsers}/parse-arrow-in-batches.js +0 -0
@@ -6,6 +6,9 @@
6
6
  __defProp(target, name, { get: all[name], enumerable: true });
7
7
  };
8
8
 
9
+ // ../worker-utils/src/lib/node/worker_threads-browser.ts
10
+ var parentPort = null;
11
+
9
12
  // ../worker-utils/src/lib/worker-utils/get-transfer-list.ts
10
13
  function getTransferList(object, recursive = true, transfers) {
11
14
  const transfersSet = transfers || /* @__PURE__ */ new Set();
@@ -43,19 +46,6 @@
43
46
 
44
47
  // ../worker-utils/src/lib/worker-farm/worker-body.ts
45
48
  async function getParentPort() {
46
- let parentPort;
47
- try {
48
- eval("globalThis.parentPort = require('worker_threads').parentPort");
49
- parentPort = globalThis.parentPort;
50
- } catch {
51
- try {
52
- eval("globalThis.workerThreadsPromise = import('worker_threads')");
53
- const workerThreads = await globalThis.workerThreadsPromise;
54
- parentPort = workerThreads.parentPort;
55
- } catch (error) {
56
- console.error(error.message);
57
- }
58
- }
59
49
  return parentPort;
60
50
  }
61
51
  var onMessageWrapperMap = /* @__PURE__ */ new Map();
@@ -213,375 +203,6 @@
213
203
  return await parser(data, { ...options }, context, loader);
214
204
  }
215
205
 
216
- // ../schema/src/lib/table/batches/base-table-batch-aggregator.ts
217
- var DEFAULT_ROW_COUNT = 100;
218
- var BaseTableBatchAggregator = class {
219
- constructor(schema, options) {
220
- this.length = 0;
221
- this.rows = null;
222
- this.cursor = 0;
223
- this._headers = [];
224
- this.options = options;
225
- this.schema = schema;
226
- if (!Array.isArray(schema)) {
227
- this._headers = [];
228
- for (const key in schema) {
229
- this._headers[schema[key].index] = schema[key].name;
230
- }
231
- }
232
- }
233
- rowCount() {
234
- return this.length;
235
- }
236
- addArrayRow(row, cursor) {
237
- if (Number.isFinite(cursor)) {
238
- this.cursor = cursor;
239
- }
240
- this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
241
- this.rows[this.length] = row;
242
- this.length++;
243
- }
244
- addObjectRow(row, cursor) {
245
- if (Number.isFinite(cursor)) {
246
- this.cursor = cursor;
247
- }
248
- this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
249
- this.rows[this.length] = row;
250
- this.length++;
251
- }
252
- getBatch() {
253
- let rows = this.rows;
254
- if (!rows) {
255
- return null;
256
- }
257
- rows = rows.slice(0, this.length);
258
- this.rows = null;
259
- const batch = {
260
- shape: this.options.shape,
261
- batchType: "data",
262
- data: rows,
263
- length: this.length,
264
- schema: this.schema,
265
- cursor: this.cursor
266
- };
267
- return batch;
268
- }
269
- };
270
-
271
- // ../schema/src/lib/table/simple-table/row-utils.ts
272
- function convertToObjectRow(arrayRow, headers) {
273
- if (!arrayRow) {
274
- throw new Error("null row");
275
- }
276
- if (!headers) {
277
- throw new Error("no headers");
278
- }
279
- const objectRow = {};
280
- for (let i = 0; i < headers.length; i++) {
281
- objectRow[headers[i]] = arrayRow[i];
282
- }
283
- return objectRow;
284
- }
285
- function convertToArrayRow(objectRow, headers) {
286
- if (!objectRow) {
287
- throw new Error("null row");
288
- }
289
- if (!headers) {
290
- throw new Error("no headers");
291
- }
292
- const arrayRow = new Array(headers.length);
293
- for (let i = 0; i < headers.length; i++) {
294
- arrayRow[i] = objectRow[headers[i]];
295
- }
296
- return arrayRow;
297
- }
298
-
299
- // ../schema/src/lib/table/batches/row-table-batch-aggregator.ts
300
- var DEFAULT_ROW_COUNT2 = 100;
301
- var RowTableBatchAggregator = class {
302
- constructor(schema, options) {
303
- this.length = 0;
304
- this.objectRows = null;
305
- this.arrayRows = null;
306
- this.cursor = 0;
307
- this._headers = [];
308
- this.options = options;
309
- this.schema = schema;
310
- if (!Array.isArray(schema)) {
311
- this._headers = [];
312
- for (const key in schema) {
313
- this._headers[schema[key].index] = schema[key].name;
314
- }
315
- }
316
- }
317
- rowCount() {
318
- return this.length;
319
- }
320
- addArrayRow(row, cursor) {
321
- if (Number.isFinite(cursor)) {
322
- this.cursor = cursor;
323
- }
324
- switch (this.options.shape) {
325
- case "object-row-table":
326
- const rowObject = convertToObjectRow(row, this._headers);
327
- this.addObjectRow(rowObject, cursor);
328
- break;
329
- case "array-row-table":
330
- this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT2);
331
- this.arrayRows[this.length] = row;
332
- this.length++;
333
- break;
334
- }
335
- }
336
- addObjectRow(row, cursor) {
337
- if (Number.isFinite(cursor)) {
338
- this.cursor = cursor;
339
- }
340
- switch (this.options.shape) {
341
- case "array-row-table":
342
- const rowArray = convertToArrayRow(row, this._headers);
343
- this.addArrayRow(rowArray, cursor);
344
- break;
345
- case "object-row-table":
346
- this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT2);
347
- this.objectRows[this.length] = row;
348
- this.length++;
349
- break;
350
- }
351
- }
352
- getBatch() {
353
- let rows = this.arrayRows || this.objectRows;
354
- if (!rows) {
355
- return null;
356
- }
357
- rows = rows.slice(0, this.length);
358
- this.arrayRows = null;
359
- this.objectRows = null;
360
- return {
361
- shape: this.options.shape,
362
- batchType: "data",
363
- data: rows,
364
- length: this.length,
365
- schema: this.schema,
366
- cursor: this.cursor
367
- };
368
- }
369
- };
370
-
371
- // ../schema/src/lib/table/batches/columnar-table-batch-aggregator.ts
372
- var DEFAULT_ROW_COUNT3 = 100;
373
- var ColumnarTableBatchAggregator = class {
374
- constructor(schema, options) {
375
- this.length = 0;
376
- this.allocated = 0;
377
- this.columns = {};
378
- this.schema = schema;
379
- this._reallocateColumns();
380
- }
381
- rowCount() {
382
- return this.length;
383
- }
384
- addArrayRow(row) {
385
- this._reallocateColumns();
386
- let i = 0;
387
- for (const fieldName in this.columns) {
388
- this.columns[fieldName][this.length] = row[i++];
389
- }
390
- this.length++;
391
- }
392
- addObjectRow(row) {
393
- this._reallocateColumns();
394
- for (const fieldName in row) {
395
- this.columns[fieldName][this.length] = row[fieldName];
396
- }
397
- this.length++;
398
- }
399
- getBatch() {
400
- this._pruneColumns();
401
- const columns = Array.isArray(this.schema) ? this.columns : {};
402
- if (!Array.isArray(this.schema)) {
403
- for (const fieldName in this.schema) {
404
- const field = this.schema[fieldName];
405
- columns[field.name] = this.columns[field.index];
406
- }
407
- }
408
- this.columns = {};
409
- const batch = {
410
- shape: "columnar-table",
411
- batchType: "data",
412
- data: columns,
413
- schema: this.schema,
414
- length: this.length
415
- };
416
- return batch;
417
- }
418
- // HELPERS
419
- _reallocateColumns() {
420
- if (this.length < this.allocated) {
421
- return;
422
- }
423
- this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT3;
424
- this.columns = {};
425
- for (const fieldName in this.schema) {
426
- const field = this.schema[fieldName];
427
- const ArrayType = field.type || Float32Array;
428
- const oldColumn = this.columns[field.index];
429
- if (oldColumn && ArrayBuffer.isView(oldColumn)) {
430
- const typedArray = new ArrayType(this.allocated);
431
- typedArray.set(oldColumn);
432
- this.columns[field.index] = typedArray;
433
- } else if (oldColumn) {
434
- oldColumn.length = this.allocated;
435
- this.columns[field.index] = oldColumn;
436
- } else {
437
- this.columns[field.index] = new ArrayType(this.allocated);
438
- }
439
- }
440
- }
441
- _pruneColumns() {
442
- for (const [columnName, column] of Object.entries(this.columns)) {
443
- this.columns[columnName] = column.slice(0, this.length);
444
- }
445
- }
446
- };
447
-
448
- // ../schema/src/lib/table/batches/table-batch-builder.ts
449
- var DEFAULT_OPTIONS = {
450
- shape: "array-row-table",
451
- batchSize: "auto",
452
- batchDebounceMs: 0,
453
- limit: 0,
454
- _limitMB: 0
455
- };
456
- var ERR_MESSAGE = "TableBatchBuilder";
457
- var TableBatchBuilder = class {
458
- constructor(schema, options) {
459
- this.aggregator = null;
460
- this.batchCount = 0;
461
- this.bytesUsed = 0;
462
- this.isChunkComplete = false;
463
- this.lastBatchEmittedMs = Date.now();
464
- this.totalLength = 0;
465
- this.totalBytes = 0;
466
- this.rowBytes = 0;
467
- this.schema = schema;
468
- this.options = { ...DEFAULT_OPTIONS, ...options };
469
- }
470
- limitReached() {
471
- if (Boolean(this.options?.limit) && this.totalLength >= this.options.limit) {
472
- return true;
473
- }
474
- if (Boolean(this.options?._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
475
- return true;
476
- }
477
- return false;
478
- }
479
- /** @deprecated Use addArrayRow or addObjectRow */
480
- addRow(row) {
481
- if (this.limitReached()) {
482
- return;
483
- }
484
- this.totalLength++;
485
- this.rowBytes = this.rowBytes || this._estimateRowMB(row);
486
- this.totalBytes += this.rowBytes;
487
- if (Array.isArray(row)) {
488
- this.addArrayRow(row);
489
- } else {
490
- this.addObjectRow(row);
491
- }
492
- }
493
- /** Add one row to the batch */
494
- addArrayRow(row) {
495
- if (!this.aggregator) {
496
- const TableBatchType = this._getTableBatchType();
497
- this.aggregator = new TableBatchType(this.schema, this.options);
498
- }
499
- this.aggregator.addArrayRow(row);
500
- }
501
- /** Add one row to the batch */
502
- addObjectRow(row) {
503
- if (!this.aggregator) {
504
- const TableBatchType = this._getTableBatchType();
505
- this.aggregator = new TableBatchType(this.schema, this.options);
506
- }
507
- this.aggregator.addObjectRow(row);
508
- }
509
- /** Mark an incoming raw memory chunk has completed */
510
- chunkComplete(chunk) {
511
- if (chunk instanceof ArrayBuffer) {
512
- this.bytesUsed += chunk.byteLength;
513
- }
514
- if (typeof chunk === "string") {
515
- this.bytesUsed += chunk.length;
516
- }
517
- this.isChunkComplete = true;
518
- }
519
- getFullBatch(options) {
520
- return this._isFull() ? this._getBatch(options) : null;
521
- }
522
- getFinalBatch(options) {
523
- return this._getBatch(options);
524
- }
525
- // INTERNAL
526
- _estimateRowMB(row) {
527
- return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
528
- }
529
- _isFull() {
530
- if (!this.aggregator || this.aggregator.rowCount() === 0) {
531
- return false;
532
- }
533
- if (this.options.batchSize === "auto") {
534
- if (!this.isChunkComplete) {
535
- return false;
536
- }
537
- } else if (this.options.batchSize > this.aggregator.rowCount()) {
538
- return false;
539
- }
540
- if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
541
- return false;
542
- }
543
- this.isChunkComplete = false;
544
- this.lastBatchEmittedMs = Date.now();
545
- return true;
546
- }
547
- /**
548
- * bytesUsed can be set via chunkComplete or via getBatch*
549
- */
550
- _getBatch(options) {
551
- if (!this.aggregator) {
552
- return null;
553
- }
554
- if (options?.bytesUsed) {
555
- this.bytesUsed = options.bytesUsed;
556
- }
557
- const normalizedBatch = this.aggregator.getBatch();
558
- normalizedBatch.count = this.batchCount;
559
- normalizedBatch.bytesUsed = this.bytesUsed;
560
- Object.assign(normalizedBatch, options);
561
- this.batchCount++;
562
- this.aggregator = null;
563
- return normalizedBatch;
564
- }
565
- _getTableBatchType() {
566
- switch (this.options.shape) {
567
- case "row-table":
568
- return BaseTableBatchAggregator;
569
- case "array-row-table":
570
- case "object-row-table":
571
- return RowTableBatchAggregator;
572
- case "columnar-table":
573
- return ColumnarTableBatchAggregator;
574
- case "arrow-table":
575
- if (!TableBatchBuilder.ArrowBatch) {
576
- throw new Error(ERR_MESSAGE);
577
- }
578
- return TableBatchBuilder.ArrowBatch;
579
- default:
580
- throw new Error(ERR_MESSAGE);
581
- }
582
- }
583
- };
584
-
585
206
  // ../schema/src/lib/table/simple-table/table-accessors.ts
586
207
  function getTableLength(table) {
587
208
  switch (table.shape) {
@@ -952,30 +573,6 @@
952
573
  };
953
574
  }
954
575
 
955
- // src/arrow-loader.ts
956
- var VERSION = true ? "4.0.3" : "latest";
957
- var ArrowLoader = {
958
- name: "Apache Arrow",
959
- id: "arrow",
960
- module: "arrow",
961
- version: VERSION,
962
- // worker: true,
963
- category: "table",
964
- extensions: ["arrow", "feather"],
965
- mimeTypes: [
966
- "application/vnd.apache.arrow.file",
967
- "application/vnd.apache.arrow.stream",
968
- "application/octet-stream"
969
- ],
970
- binary: true,
971
- tests: ["ARROW"],
972
- options: {
973
- arrow: {
974
- shape: "columnar-table"
975
- }
976
- }
977
- };
978
-
979
576
  // ../../node_modules/tslib/tslib.es6.mjs
980
577
  function __rest(s, e) {
981
578
  var t = {};
@@ -2282,6 +1879,16 @@
2282
1879
  proto.ArrayType = Int32Array;
2283
1880
  return proto[Symbol.toStringTag] = "Date";
2284
1881
  })(Date_.prototype);
1882
+ var DateDay = class extends Date_ {
1883
+ constructor() {
1884
+ super(DateUnit.DAY);
1885
+ }
1886
+ };
1887
+ var DateMillisecond = class extends Date_ {
1888
+ constructor() {
1889
+ super(DateUnit.MILLISECOND);
1890
+ }
1891
+ };
2285
1892
  var Time_ = class extends DataType {
2286
1893
  constructor(unit, bitWidth) {
2287
1894
  super();
@@ -2310,6 +1917,26 @@
2310
1917
  proto.bitWidth = null;
2311
1918
  return proto[Symbol.toStringTag] = "Time";
2312
1919
  })(Time_.prototype);
1920
+ var TimeSecond = class extends Time_ {
1921
+ constructor() {
1922
+ super(TimeUnit.SECOND, 32);
1923
+ }
1924
+ };
1925
+ var TimeMillisecond = class extends Time_ {
1926
+ constructor() {
1927
+ super(TimeUnit.MILLISECOND, 32);
1928
+ }
1929
+ };
1930
+ var TimeMicrosecond = class extends Time_ {
1931
+ constructor() {
1932
+ super(TimeUnit.MICROSECOND, 64);
1933
+ }
1934
+ };
1935
+ var TimeNanosecond = class extends Time_ {
1936
+ constructor() {
1937
+ super(TimeUnit.NANOSECOND, 64);
1938
+ }
1939
+ };
2313
1940
  var Timestamp_ = class extends DataType {
2314
1941
  constructor(unit, timezone) {
2315
1942
  super();
@@ -2330,6 +1957,26 @@
2330
1957
  proto.ArrayType = Int32Array;
2331
1958
  return proto[Symbol.toStringTag] = "Timestamp";
2332
1959
  })(Timestamp_.prototype);
1960
+ var TimestampSecond = class extends Timestamp_ {
1961
+ constructor(timezone) {
1962
+ super(TimeUnit.SECOND, timezone);
1963
+ }
1964
+ };
1965
+ var TimestampMillisecond = class extends Timestamp_ {
1966
+ constructor(timezone) {
1967
+ super(TimeUnit.MILLISECOND, timezone);
1968
+ }
1969
+ };
1970
+ var TimestampMicrosecond = class extends Timestamp_ {
1971
+ constructor(timezone) {
1972
+ super(TimeUnit.MICROSECOND, timezone);
1973
+ }
1974
+ };
1975
+ var TimestampNanosecond = class extends Timestamp_ {
1976
+ constructor(timezone) {
1977
+ super(TimeUnit.NANOSECOND, timezone);
1978
+ }
1979
+ };
2333
1980
  var Interval_ = class extends DataType {
2334
1981
  constructor(unit) {
2335
1982
  super();
@@ -2348,6 +1995,16 @@
2348
1995
  proto.ArrayType = Int32Array;
2349
1996
  return proto[Symbol.toStringTag] = "Interval";
2350
1997
  })(Interval_.prototype);
1998
+ var IntervalDayTime = class extends Interval_ {
1999
+ constructor() {
2000
+ super(IntervalUnit.DAY_TIME);
2001
+ }
2002
+ };
2003
+ var IntervalYearMonth = class extends Interval_ {
2004
+ constructor() {
2005
+ super(IntervalUnit.YEAR_MONTH);
2006
+ }
2007
+ };
2351
2008
  var List = class extends DataType {
2352
2009
  constructor(child) {
2353
2010
  super();
@@ -4771,63 +4428,6 @@
4771
4428
  });
4772
4429
  }
4773
4430
  };
4774
- function makeVector(init) {
4775
- if (init) {
4776
- if (init instanceof Data) {
4777
- return new Vector([init]);
4778
- }
4779
- if (init instanceof Vector) {
4780
- return new Vector(init.data);
4781
- }
4782
- if (init.type instanceof DataType) {
4783
- return new Vector([makeData(init)]);
4784
- }
4785
- if (Array.isArray(init)) {
4786
- return new Vector(init.flatMap((v) => unwrapInputs(v)));
4787
- }
4788
- if (ArrayBuffer.isView(init)) {
4789
- if (init instanceof DataView) {
4790
- init = new Uint8Array(init.buffer);
4791
- }
4792
- const props = { offset: 0, length: init.length, nullCount: 0, data: init };
4793
- if (init instanceof Int8Array) {
4794
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int8() }))]);
4795
- }
4796
- if (init instanceof Int16Array) {
4797
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int16() }))]);
4798
- }
4799
- if (init instanceof Int32Array) {
4800
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int32() }))]);
4801
- }
4802
- if (init instanceof BigInt64Array) {
4803
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Int64() }))]);
4804
- }
4805
- if (init instanceof Uint8Array || init instanceof Uint8ClampedArray) {
4806
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint8() }))]);
4807
- }
4808
- if (init instanceof Uint16Array) {
4809
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint16() }))]);
4810
- }
4811
- if (init instanceof Uint32Array) {
4812
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint32() }))]);
4813
- }
4814
- if (init instanceof BigUint64Array) {
4815
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Uint64() }))]);
4816
- }
4817
- if (init instanceof Float32Array) {
4818
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Float32() }))]);
4819
- }
4820
- if (init instanceof Float64Array) {
4821
- return new Vector([makeData(Object.assign(Object.assign({}, props), { type: new Float64() }))]);
4822
- }
4823
- throw new Error("Unrecognized input");
4824
- }
4825
- }
4826
- throw new Error("Unrecognized input");
4827
- }
4828
- function unwrapInputs(x) {
4829
- return x instanceof Data ? [x] : x instanceof Vector ? x.data : makeVector(x).data;
4830
- }
4831
4431
 
4832
4432
  // ../../node_modules/apache-arrow/builder/valid.mjs
4833
4433
  function createIsValidFunction(nullValues) {
@@ -12342,13 +11942,7 @@ return true;`);
12342
11942
  RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12343
11943
  RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12344
11944
 
12345
- // src/tables/convert-arrow-to-table.ts
12346
- function convertApacheArrowToArrowTable(arrowTable) {
12347
- return {
12348
- shape: "arrow-table",
12349
- data: arrowTable
12350
- };
12351
- }
11945
+ // src/tables/convert-arrow-to-columnar-table.ts
12352
11946
  function convertArrowToColumnarTable(table) {
12353
11947
  const arrowTable = table.data;
12354
11948
  const columnarTable = {};
@@ -12359,29 +11953,207 @@ return true;`);
12359
11953
  }
12360
11954
  return {
12361
11955
  shape: "columnar-table",
11956
+ schema: table.schema,
12362
11957
  data: columnarTable
12363
11958
  };
12364
11959
  }
12365
11960
 
12366
- // src/lib/parse-arrow-sync.ts
11961
+ // src/schema/convert-arrow-schema.ts
11962
+ function serializeArrowSchema(arrowSchema) {
11963
+ return {
11964
+ fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
11965
+ metadata: serializeArrowMetadata(arrowSchema.metadata)
11966
+ };
11967
+ }
11968
+ function serializeArrowMetadata(arrowMetadata) {
11969
+ return Object.fromEntries(arrowMetadata);
11970
+ }
11971
+ function serializeArrowField(field) {
11972
+ return {
11973
+ name: field.name,
11974
+ type: serializeArrowType(field.type),
11975
+ nullable: field.nullable,
11976
+ metadata: serializeArrowMetadata(field.metadata)
11977
+ };
11978
+ }
11979
+ function serializeArrowType(arrowType) {
11980
+ switch (arrowType.constructor) {
11981
+ case Null:
11982
+ return "null";
11983
+ case Binary:
11984
+ return "binary";
11985
+ case Bool:
11986
+ return "bool";
11987
+ case Int_:
11988
+ const intType = arrowType;
11989
+ return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
11990
+ case Int8:
11991
+ return "int8";
11992
+ case Int16:
11993
+ return "int16";
11994
+ case Int32:
11995
+ return "int32";
11996
+ case Int64:
11997
+ return "int64";
11998
+ case Uint8:
11999
+ return "uint8";
12000
+ case Uint16:
12001
+ return "uint16";
12002
+ case Uint32:
12003
+ return "uint32";
12004
+ case Uint64:
12005
+ return "uint64";
12006
+ case Float:
12007
+ const precision = arrowType.precision;
12008
+ switch (precision) {
12009
+ case Precision.HALF:
12010
+ return "float16";
12011
+ case Precision.SINGLE:
12012
+ return "float32";
12013
+ case Precision.DOUBLE:
12014
+ return "float64";
12015
+ default:
12016
+ return "float16";
12017
+ }
12018
+ case Float16:
12019
+ return "float16";
12020
+ case Float32:
12021
+ return "float32";
12022
+ case Float64:
12023
+ return "float64";
12024
+ case Utf8:
12025
+ return "utf8";
12026
+ case Decimal:
12027
+ const decimal = arrowType;
12028
+ return {
12029
+ type: "decimal",
12030
+ bitWidth: decimal.bitWidth,
12031
+ precision: decimal.precision,
12032
+ scale: decimal.scale
12033
+ };
12034
+ case Date_:
12035
+ const dateUnit = arrowType.unit;
12036
+ return dateUnit === DateUnit.DAY ? "date-day" : "date-millisecond";
12037
+ case DateDay:
12038
+ return "date-day";
12039
+ case DateMillisecond:
12040
+ return "date-millisecond";
12041
+ case Time_:
12042
+ const timeUnit = arrowType.unit;
12043
+ switch (timeUnit) {
12044
+ case TimeUnit.SECOND:
12045
+ return "time-second";
12046
+ case TimeUnit.MILLISECOND:
12047
+ return "time-millisecond";
12048
+ case TimeUnit.MICROSECOND:
12049
+ return "time-microsecond";
12050
+ case TimeUnit.NANOSECOND:
12051
+ return "time-nanosecond";
12052
+ default:
12053
+ return "time-second";
12054
+ }
12055
+ case TimeMillisecond:
12056
+ return "time-millisecond";
12057
+ case TimeSecond:
12058
+ return "time-second";
12059
+ case TimeMicrosecond:
12060
+ return "time-microsecond";
12061
+ case TimeNanosecond:
12062
+ return "time-nanosecond";
12063
+ case Timestamp_:
12064
+ const timeStampUnit = arrowType.unit;
12065
+ switch (timeStampUnit) {
12066
+ case TimeUnit.SECOND:
12067
+ return "timestamp-second";
12068
+ case TimeUnit.MILLISECOND:
12069
+ return "timestamp-millisecond";
12070
+ case TimeUnit.MICROSECOND:
12071
+ return "timestamp-microsecond";
12072
+ case TimeUnit.NANOSECOND:
12073
+ return "timestamp-nanosecond";
12074
+ default:
12075
+ return "timestamp-second";
12076
+ }
12077
+ case TimestampSecond:
12078
+ return "timestamp-second";
12079
+ case TimestampMillisecond:
12080
+ return "timestamp-millisecond";
12081
+ case TimestampMicrosecond:
12082
+ return "timestamp-microsecond";
12083
+ case TimestampNanosecond:
12084
+ return "timestamp-nanosecond";
12085
+ case Interval_:
12086
+ const intervalUnit = arrowType.unit;
12087
+ switch (intervalUnit) {
12088
+ case IntervalUnit.DAY_TIME:
12089
+ return "interval-daytime";
12090
+ case IntervalUnit.YEAR_MONTH:
12091
+ return "interval-yearmonth";
12092
+ default:
12093
+ return "interval-daytime";
12094
+ }
12095
+ case IntervalDayTime:
12096
+ return "interval-daytime";
12097
+ case IntervalYearMonth:
12098
+ return "interval-yearmonth";
12099
+ case Map_:
12100
+ const mapType = arrowType;
12101
+ return {
12102
+ type: "map",
12103
+ keysSorted: mapType.keysSorted,
12104
+ children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
12105
+ };
12106
+ case List:
12107
+ const listType = arrowType;
12108
+ const listField = listType.valueField;
12109
+ return {
12110
+ type: "list",
12111
+ children: [serializeArrowField(listField)]
12112
+ };
12113
+ case FixedSizeList:
12114
+ const fixedSizeList = arrowType;
12115
+ return {
12116
+ type: "fixed-size-list",
12117
+ listSize: fixedSizeList.listSize,
12118
+ children: [serializeArrowField(fixedSizeList.children[0])]
12119
+ };
12120
+ case Struct:
12121
+ const structType = arrowType;
12122
+ return {
12123
+ type: "struct",
12124
+ children: structType.children.map((arrowField) => serializeArrowField(arrowField))
12125
+ };
12126
+ default:
12127
+ throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
12128
+ }
12129
+ }
12130
+
12131
+ // src/parsers/parse-arrow-sync.ts
12367
12132
  function parseArrowSync(arrayBuffer, options) {
12368
12133
  const apacheArrowTable = tableFromIPC([new Uint8Array(arrayBuffer)]);
12369
- const arrowTable = convertApacheArrowToArrowTable(apacheArrowTable);
12370
- const shape = options?.arrow?.shape || "arrow-table";
12134
+ const arrowTable = {
12135
+ shape: "arrow-table",
12136
+ schema: serializeArrowSchema(apacheArrowTable.schema),
12137
+ data: apacheArrowTable
12138
+ };
12139
+ const shape = options?.shape || "arrow-table";
12371
12140
  switch (shape) {
12372
12141
  case "arrow-table":
12373
12142
  return arrowTable;
12374
12143
  case "columnar-table":
12375
12144
  return convertArrowToColumnarTable(arrowTable);
12376
12145
  case "object-row-table":
12377
- const columnarTable = convertArrowToColumnarTable(arrowTable);
12146
+ let columnarTable = convertArrowToColumnarTable(arrowTable);
12378
12147
  return convertTable(columnarTable, "object-row-table");
12148
+ case "array-row-table":
12149
+ columnarTable = convertArrowToColumnarTable(arrowTable);
12150
+ return convertTable(columnarTable, "array-row-table");
12379
12151
  default:
12380
12152
  throw new Error(shape);
12381
12153
  }
12382
12154
  }
12383
12155
 
12384
- // src/lib/parse-arrow-in-batches.ts
12156
+ // src/parsers/parse-arrow-in-batches.ts
12385
12157
  function parseArrowInBatches(asyncIterator) {
12386
12158
  async function* makeArrowAsyncIterator() {
12387
12159
  const readers = RecordBatchReader.readAll(asyncIterator);
@@ -12401,73 +12173,36 @@ return true;`);
12401
12173
  return makeArrowAsyncIterator();
12402
12174
  }
12403
12175
 
12404
- // src/lib/arrow-table-batch.ts
12405
- var ArrowTableBatchAggregator = class extends ColumnarTableBatchAggregator {
12406
- constructor(schema, options) {
12407
- super(schema, options);
12408
- this.arrowSchema = null;
12409
- }
12410
- getBatch() {
12411
- const batch = super.getBatch();
12412
- if (batch) {
12413
- this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
12414
- const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
12415
- const recordBatch = new RecordBatch(
12416
- this.arrowSchema,
12417
- makeData({
12418
- type: new Struct(this.arrowSchema.fields),
12419
- children: arrowVectors.map(({ data }) => data[0])
12420
- })
12421
- );
12422
- return {
12423
- shape: "arrow-table",
12424
- batchType: "data",
12425
- data: new Table([recordBatch]),
12426
- length: batch.length
12427
- };
12176
+ // src/arrow-loader.ts
12177
+ var VERSION = true ? "4.1.0-alpha.1" : "latest";
12178
+ var ArrowWorkerLoader = {
12179
+ name: "Apache Arrow",
12180
+ id: "arrow",
12181
+ module: "arrow",
12182
+ version: VERSION,
12183
+ // worker: true,
12184
+ category: "table",
12185
+ extensions: ["arrow", "feather"],
12186
+ mimeTypes: [
12187
+ "application/vnd.apache.arrow.file",
12188
+ "application/vnd.apache.arrow.stream",
12189
+ "application/octet-stream"
12190
+ ],
12191
+ binary: true,
12192
+ tests: ["ARROW"],
12193
+ options: {
12194
+ arrow: {
12195
+ shape: "columnar-table"
12428
12196
  }
12429
- return null;
12430
12197
  }
12431
12198
  };
12432
- function getArrowSchema(schema) {
12433
- const arrowFields = [];
12434
- for (const key in schema) {
12435
- const field = schema[key];
12436
- if (field.type === Float32Array) {
12437
- const metadata = /* @__PURE__ */ new Map();
12438
- const arrowField = new Field2(field.name, new Float32(), field.nullable, metadata);
12439
- arrowFields.push(arrowField);
12440
- }
12441
- }
12442
- if (arrowFields.length === 0) {
12443
- throw new Error("No arrow convertible fields");
12444
- }
12445
- return new Schema2(arrowFields);
12446
- }
12447
- function getArrowVectors(arrowSchema, data) {
12448
- const arrowVectors = [];
12449
- for (const field of arrowSchema.fields) {
12450
- const vector = data[field.name];
12451
- if (vector instanceof Float32Array) {
12452
- const arrowVector = makeVector(vector);
12453
- arrowVectors.push(arrowVector);
12454
- }
12455
- }
12456
- if (arrowSchema.fields.length !== arrowVectors.length) {
12457
- throw new Error("Some columns not arrow convertible");
12458
- }
12459
- return arrowVectors;
12460
- }
12461
-
12462
- // src/index.ts
12463
- TableBatchBuilder.ArrowBatch = ArrowTableBatchAggregator;
12464
- var ArrowLoader2 = {
12465
- ...ArrowLoader,
12466
- parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options),
12467
- parseSync: parseArrowSync,
12199
+ var ArrowLoader = {
12200
+ ...ArrowWorkerLoader,
12201
+ parse: async (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
12202
+ parseSync: (arraybuffer, options) => parseArrowSync(arraybuffer, options?.arrow),
12468
12203
  parseInBatches: parseArrowInBatches
12469
12204
  };
12470
12205
 
12471
12206
  // src/workers/arrow-worker.ts
12472
- createLoaderWorker(ArrowLoader2);
12207
+ createLoaderWorker(ArrowLoader);
12473
12208
  })();