@loaders.gl/schema-utils 4.4.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.
- package/LICENSE +41 -0
- package/README.md +9 -0
- package/dist/dist.dev.js +14269 -0
- package/dist/dist.min.js +18 -0
- package/dist/index.cjs +2436 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.js +40 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.js +32 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts +18 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts.map +1 -0
- package/dist/lib/mesh/convert-mesh-to-table.js +60 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts +7 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts.map +1 -0
- package/dist/lib/mesh/convert-table-to-mesh.js +40 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +23 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -0
- package/dist/lib/mesh/deduce-mesh-schema.js +62 -0
- package/dist/lib/mesh/mesh-utils.d.ts +23 -0
- package/dist/lib/mesh/mesh-utils.d.ts.map +1 -0
- package/dist/lib/mesh/mesh-utils.js +46 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts +23 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts.map +1 -0
- package/dist/lib/schema/convert-arrow-schema.js +280 -0
- package/dist/lib/schema/data-type.d.ts +16 -0
- package/dist/lib/schema/data-type.d.ts.map +1 -0
- package/dist/lib/schema/data-type.js +88 -0
- package/dist/lib/schema/deduce-table-schema.d.ts +14 -0
- package/dist/lib/schema/deduce-table-schema.d.ts.map +1 -0
- package/dist/lib/schema/deduce-table-schema.js +100 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +19 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-field.js +36 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +43 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.js +4 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +12 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.js +81 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +28 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-table.js +63 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +177 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-type.js +442 -0
- package/dist/lib/table/arrow-api/enum.d.ts +92 -0
- package/dist/lib/table/arrow-api/enum.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/enum.js +97 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts +13 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/get-type-info.js +27 -0
- package/dist/lib/table/arrow-api/index.d.ts +5 -0
- package/dist/lib/table/arrow-api/index.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/index.js +7 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts +10 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.js +67 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts +25 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.js +99 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts +19 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.js +63 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts +20 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.js +83 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts +21 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.js +85 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts +24 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.js +4 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts +52 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-builder.js +148 -0
- package/dist/lib/table/batches/convert-batches.d.ts +10 -0
- package/dist/lib/table/batches/convert-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/convert-batches.js +45 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts +17 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.js +57 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts +15 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-batch-iterator.js +21 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts +9 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-from-batches.js +62 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts +24 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-arrow-table.js +150 -0
- package/dist/lib/table/tables/convert-table.d.ts +43 -0
- package/dist/lib/table/tables/convert-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-table.js +120 -0
- package/dist/lib/table/tables/make-table.d.ts +67 -0
- package/dist/lib/table/tables/make-table.d.ts.map +1 -0
- package/dist/lib/table/tables/make-table.js +101 -0
- package/dist/lib/table/tables/row-utils.d.ts +15 -0
- package/dist/lib/table/tables/row-utils.d.ts.map +1 -0
- package/dist/lib/table/tables/row-utils.js +49 -0
- package/dist/lib/table/tables/table-accessors.d.ts +68 -0
- package/dist/lib/table/tables/table-accessors.d.ts.map +1 -0
- package/dist/lib/table/tables/table-accessors.js +350 -0
- package/dist/lib/table/tables/table-column.d.ts +7 -0
- package/dist/lib/table/tables/table-column.d.ts.map +1 -0
- package/dist/lib/table/tables/table-column.js +39 -0
- package/dist/lib/table/tables/table-types.d.ts +12 -0
- package/dist/lib/table/tables/table-types.d.ts.map +1 -0
- package/dist/lib/table/tables/table-types.js +23 -0
- package/dist/lib/utils/assert.d.ts +2 -0
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +8 -0
- package/dist/lib/utils/async-queue.d.ts +18 -0
- package/dist/lib/utils/async-queue.d.ts.map +1 -0
- package/dist/lib/utils/async-queue.js +90 -0
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +4 -0
- package/package.json +52 -0
- package/src/index.ts +134 -0
- package/src/lib/arrow-utils/arrow-fixed-size-list-utils.ts +63 -0
- package/src/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.ts +48 -0
- package/src/lib/mesh/convert-mesh-to-table.ts +77 -0
- package/src/lib/mesh/convert-table-to-mesh.ts +49 -0
- package/src/lib/mesh/deduce-mesh-schema.ts +75 -0
- package/src/lib/mesh/mesh-utils.ts +64 -0
- package/src/lib/schema/convert-arrow-schema.ts +301 -0
- package/src/lib/schema/data-type.ts +103 -0
- package/src/lib/schema/deduce-table-schema.ts +119 -0
- package/src/lib/table/arrow-api/arrow-like-field.ts +53 -0
- package/src/lib/table/arrow-api/arrow-like-interface.ts +84 -0
- package/src/lib/table/arrow-api/arrow-like-schema.ts +101 -0
- package/src/lib/table/arrow-api/arrow-like-table.ts +85 -0
- package/src/lib/table/arrow-api/arrow-like-type.ts +502 -0
- package/src/lib/table/arrow-api/enum.ts +99 -0
- package/src/lib/table/arrow-api/get-type-info.ts +38 -0
- package/src/lib/table/arrow-api/index.ts +8 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator-builders.ts.disabled +190 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/arrow-table-builder.ts +112 -0
- package/src/lib/table/batch-builder/base-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/columnar-table-batch-aggregator.ts +99 -0
- package/src/lib/table/batch-builder/row-table-batch-aggregator.ts +108 -0
- package/src/lib/table/batch-builder/table-batch-aggregator.ts +28 -0
- package/src/lib/table/batch-builder/table-batch-builder.ts +185 -0
- package/src/lib/table/batches/convert-batches.ts +83 -0
- package/src/lib/table/batches/make-arrow-batch-iterator.ts +75 -0
- package/src/lib/table/batches/make-table-batch-iterator.ts +25 -0
- package/src/lib/table/batches/make-table-from-batches.ts +84 -0
- package/src/lib/table/tables/convert-arrow-table.ts +198 -0
- package/src/lib/table/tables/convert-table.ts +151 -0
- package/src/lib/table/tables/make-table.ts +127 -0
- package/src/lib/table/tables/row-utils.ts +59 -0
- package/src/lib/table/tables/table-accessors.ts +417 -0
- package/src/lib/table/tables/table-column.ts +49 -0
- package/src/lib/table/tables/table-types.ts +37 -0
- package/src/lib/utils/assert.ts +8 -0
- package/src/lib/utils/async-queue.ts +104 -0
- package/src/types/types.ts +45 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2436 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var __publicField = (obj, key, value) => {
|
|
31
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// dist/index.js
|
|
36
|
+
var dist_exports = {};
|
|
37
|
+
__export(dist_exports, {
|
|
38
|
+
ArrowLikeDataType: () => DataType,
|
|
39
|
+
ArrowLikeField: () => ArrowLikeField,
|
|
40
|
+
ArrowLikeSchema: () => ArrowLikeSchema,
|
|
41
|
+
ArrowLikeTable: () => ArrowLikeTable,
|
|
42
|
+
ArrowTableBuilder: () => ArrowTableBuilder,
|
|
43
|
+
AsyncQueue: () => AsyncQueue,
|
|
44
|
+
ColumnarTableBatchAggregator: () => ColumnarTableBatchAggregator,
|
|
45
|
+
RowTableBatchAggregator: () => RowTableBatchAggregator,
|
|
46
|
+
TableBatchBuilder: () => TableBatchBuilder,
|
|
47
|
+
convertArrowToSchema: () => convertArrowToSchema,
|
|
48
|
+
convertArrowToTable: () => convertArrowToTable,
|
|
49
|
+
convertBatch: () => convertBatch,
|
|
50
|
+
convertBatches: () => convertBatches,
|
|
51
|
+
convertMeshToTable: () => convertMeshToTable,
|
|
52
|
+
convertSchemaToArrow: () => convertSchemaToArrow,
|
|
53
|
+
convertTable: () => convertTable,
|
|
54
|
+
convertTableToArrow: () => convertTableToArrow,
|
|
55
|
+
convertTableToMesh: () => convertTableToMesh,
|
|
56
|
+
convertToArrayRow: () => convertToArrayRow,
|
|
57
|
+
convertToObjectRow: () => convertToObjectRow,
|
|
58
|
+
deduceMeshField: () => deduceMeshField,
|
|
59
|
+
deduceMeshSchema: () => deduceMeshSchema,
|
|
60
|
+
deduceTableSchema: () => deduceTableSchema,
|
|
61
|
+
deserializeArrowField: () => deserializeArrowField,
|
|
62
|
+
deserializeArrowMetadata: () => deserializeArrowMetadata,
|
|
63
|
+
deserializeArrowSchema: () => deserializeArrowSchema,
|
|
64
|
+
deserializeArrowType: () => deserializeArrowType,
|
|
65
|
+
getArrayTypeFromDataType: () => getArrayTypeFromDataType,
|
|
66
|
+
getDataTypeFromArray: () => getDataTypeFromArray,
|
|
67
|
+
getMeshBoundingBox: () => getMeshBoundingBox,
|
|
68
|
+
getMeshSize: () => getMeshSize,
|
|
69
|
+
getTableCell: () => getTableCell,
|
|
70
|
+
getTableCellAt: () => getTableCellAt,
|
|
71
|
+
getTableColumnIndex: () => getTableColumnIndex,
|
|
72
|
+
getTableColumnName: () => getTableColumnName,
|
|
73
|
+
getTableLength: () => getTableLength,
|
|
74
|
+
getTableNumCols: () => getTableNumCols,
|
|
75
|
+
getTableRowAsArray: () => getTableRowAsArray,
|
|
76
|
+
getTableRowAsObject: () => getTableRowAsObject,
|
|
77
|
+
getTableRowShape: () => getTableRowShape,
|
|
78
|
+
getTypeInfo: () => getTypeInfo,
|
|
79
|
+
isArrayRowTable: () => isArrayRowTable,
|
|
80
|
+
isArrowTable: () => isArrowTable,
|
|
81
|
+
isColumnarTable: () => isColumnarTable,
|
|
82
|
+
isGeoJSONTable: () => isGeoJSONTable,
|
|
83
|
+
isObjectRowTable: () => isObjectRowTable,
|
|
84
|
+
isTable: () => isTable,
|
|
85
|
+
makeArrayRowIterator: () => makeArrayRowIterator,
|
|
86
|
+
makeArrowRecordBatchIterator: () => makeArrowRecordBatchIterator,
|
|
87
|
+
makeArrowTableBatchIterator: () => makeArrowTableBatchIterator,
|
|
88
|
+
makeBatchFromTable: () => makeBatchFromTable,
|
|
89
|
+
makeMeshAttributeMetadata: () => makeMeshAttributeMetadata,
|
|
90
|
+
makeObjectRowIterator: () => makeObjectRowIterator,
|
|
91
|
+
makeRowIterator: () => makeRowIterator,
|
|
92
|
+
makeTableBatchIterator: () => makeTableBatchIterator,
|
|
93
|
+
makeTableFromBatches: () => makeTableFromBatches,
|
|
94
|
+
makeTableFromData: () => makeTableFromData,
|
|
95
|
+
serializeArrowField: () => serializeArrowField,
|
|
96
|
+
serializeArrowMetadata: () => serializeArrowMetadata,
|
|
97
|
+
serializeArrowSchema: () => serializeArrowSchema,
|
|
98
|
+
serializeArrowType: () => serializeArrowType
|
|
99
|
+
});
|
|
100
|
+
module.exports = __toCommonJS(dist_exports);
|
|
101
|
+
|
|
102
|
+
// dist/lib/schema/data-type.js
|
|
103
|
+
function getDataTypeFromValue(value, defaultNumberType = "float32") {
|
|
104
|
+
if (value instanceof Date) {
|
|
105
|
+
return "date-millisecond";
|
|
106
|
+
}
|
|
107
|
+
if (value instanceof Number) {
|
|
108
|
+
return defaultNumberType;
|
|
109
|
+
}
|
|
110
|
+
if (typeof value === "string") {
|
|
111
|
+
return "utf8";
|
|
112
|
+
}
|
|
113
|
+
if (value === null || value === "undefined") {
|
|
114
|
+
return "null";
|
|
115
|
+
}
|
|
116
|
+
return "null";
|
|
117
|
+
}
|
|
118
|
+
function getDataTypeFromArray(array) {
|
|
119
|
+
let type = getDataTypeFromTypedArray(array);
|
|
120
|
+
if (type !== "null") {
|
|
121
|
+
return { type, nullable: false };
|
|
122
|
+
}
|
|
123
|
+
if (array.length > 0) {
|
|
124
|
+
type = getDataTypeFromValue(array[0]);
|
|
125
|
+
return { type, nullable: true };
|
|
126
|
+
}
|
|
127
|
+
return { type: "null", nullable: true };
|
|
128
|
+
}
|
|
129
|
+
function getDataTypeFromTypedArray(array) {
|
|
130
|
+
switch (array.constructor) {
|
|
131
|
+
case Int8Array:
|
|
132
|
+
return "int8";
|
|
133
|
+
case Uint8Array:
|
|
134
|
+
case Uint8ClampedArray:
|
|
135
|
+
return "uint8";
|
|
136
|
+
case Int16Array:
|
|
137
|
+
return "int16";
|
|
138
|
+
case Uint16Array:
|
|
139
|
+
return "uint16";
|
|
140
|
+
case Int32Array:
|
|
141
|
+
return "int32";
|
|
142
|
+
case Uint32Array:
|
|
143
|
+
return "uint32";
|
|
144
|
+
case Float32Array:
|
|
145
|
+
return "float32";
|
|
146
|
+
case Float64Array:
|
|
147
|
+
return "float64";
|
|
148
|
+
default:
|
|
149
|
+
return "null";
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
function getArrayTypeFromDataType(type, nullable) {
|
|
153
|
+
if (!nullable) {
|
|
154
|
+
switch (type) {
|
|
155
|
+
case "int8":
|
|
156
|
+
return Int8Array;
|
|
157
|
+
case "uint8":
|
|
158
|
+
return Uint8Array;
|
|
159
|
+
case "int16":
|
|
160
|
+
return Int16Array;
|
|
161
|
+
case "uint16":
|
|
162
|
+
return Uint16Array;
|
|
163
|
+
case "int32":
|
|
164
|
+
return Int32Array;
|
|
165
|
+
case "uint32":
|
|
166
|
+
return Uint32Array;
|
|
167
|
+
case "float32":
|
|
168
|
+
return Float32Array;
|
|
169
|
+
case "float64":
|
|
170
|
+
return Float64Array;
|
|
171
|
+
default:
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return Array;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// dist/lib/schema/convert-arrow-schema.js
|
|
179
|
+
var arrow = __toESM(require("apache-arrow"), 1);
|
|
180
|
+
function convertArrowToSchema(arrowSchema) {
|
|
181
|
+
return serializeArrowSchema(arrowSchema);
|
|
182
|
+
}
|
|
183
|
+
function convertSchemaToArrow(schema) {
|
|
184
|
+
return deserializeArrowSchema(schema);
|
|
185
|
+
}
|
|
186
|
+
function serializeArrowSchema(arrowSchema) {
|
|
187
|
+
return {
|
|
188
|
+
fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
|
|
189
|
+
metadata: serializeArrowMetadata(arrowSchema.metadata)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function deserializeArrowSchema(schema) {
|
|
193
|
+
return new arrow.Schema(schema.fields.map((field) => deserializeArrowField(field)), deserializeArrowMetadata(schema.metadata));
|
|
194
|
+
}
|
|
195
|
+
function serializeArrowMetadata(arrowMetadata) {
|
|
196
|
+
return Object.fromEntries(arrowMetadata);
|
|
197
|
+
}
|
|
198
|
+
function deserializeArrowMetadata(metadata) {
|
|
199
|
+
return metadata ? new Map(Object.entries(metadata)) : /* @__PURE__ */ new Map();
|
|
200
|
+
}
|
|
201
|
+
function serializeArrowField(field) {
|
|
202
|
+
return {
|
|
203
|
+
name: field.name,
|
|
204
|
+
type: serializeArrowType(field.type),
|
|
205
|
+
nullable: field.nullable,
|
|
206
|
+
metadata: serializeArrowMetadata(field.metadata)
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
function deserializeArrowField(field) {
|
|
210
|
+
return new arrow.Field(field.name, deserializeArrowType(field.type), field.nullable, deserializeArrowMetadata(field.metadata));
|
|
211
|
+
}
|
|
212
|
+
function serializeArrowType(arrowType) {
|
|
213
|
+
switch (arrowType.constructor) {
|
|
214
|
+
case arrow.Null:
|
|
215
|
+
return "null";
|
|
216
|
+
case arrow.Binary:
|
|
217
|
+
return "binary";
|
|
218
|
+
case arrow.Bool:
|
|
219
|
+
return "bool";
|
|
220
|
+
case arrow.Int:
|
|
221
|
+
const intType = arrowType;
|
|
222
|
+
return `${intType.isSigned ? "u" : ""}int${intType.bitWidth}`;
|
|
223
|
+
case arrow.Int8:
|
|
224
|
+
return "int8";
|
|
225
|
+
case arrow.Int16:
|
|
226
|
+
return "int16";
|
|
227
|
+
case arrow.Int32:
|
|
228
|
+
return "int32";
|
|
229
|
+
case arrow.Int64:
|
|
230
|
+
return "int64";
|
|
231
|
+
case arrow.Uint8:
|
|
232
|
+
return "uint8";
|
|
233
|
+
case arrow.Uint16:
|
|
234
|
+
return "uint16";
|
|
235
|
+
case arrow.Uint32:
|
|
236
|
+
return "uint32";
|
|
237
|
+
case arrow.Uint64:
|
|
238
|
+
return "uint64";
|
|
239
|
+
case arrow.Float:
|
|
240
|
+
const precision = arrowType.precision;
|
|
241
|
+
switch (precision) {
|
|
242
|
+
case arrow.Precision.HALF:
|
|
243
|
+
return "float16";
|
|
244
|
+
case arrow.Precision.SINGLE:
|
|
245
|
+
return "float32";
|
|
246
|
+
case arrow.Precision.DOUBLE:
|
|
247
|
+
return "float64";
|
|
248
|
+
default:
|
|
249
|
+
return "float16";
|
|
250
|
+
}
|
|
251
|
+
case arrow.Float16:
|
|
252
|
+
return "float16";
|
|
253
|
+
case arrow.Float32:
|
|
254
|
+
return "float32";
|
|
255
|
+
case arrow.Float64:
|
|
256
|
+
return "float64";
|
|
257
|
+
case arrow.Utf8:
|
|
258
|
+
return "utf8";
|
|
259
|
+
case arrow.Decimal:
|
|
260
|
+
const decimal = arrowType;
|
|
261
|
+
return {
|
|
262
|
+
type: "decimal",
|
|
263
|
+
bitWidth: decimal.bitWidth,
|
|
264
|
+
precision: decimal.precision,
|
|
265
|
+
scale: decimal.scale
|
|
266
|
+
};
|
|
267
|
+
case arrow.Date_:
|
|
268
|
+
const dateUnit = arrowType.unit;
|
|
269
|
+
return dateUnit === arrow.DateUnit.DAY ? "date-day" : "date-millisecond";
|
|
270
|
+
case arrow.DateDay:
|
|
271
|
+
return "date-day";
|
|
272
|
+
case arrow.DateMillisecond:
|
|
273
|
+
return "date-millisecond";
|
|
274
|
+
case arrow.Time:
|
|
275
|
+
const timeUnit = arrowType.unit;
|
|
276
|
+
switch (timeUnit) {
|
|
277
|
+
case arrow.TimeUnit.SECOND:
|
|
278
|
+
return "time-second";
|
|
279
|
+
case arrow.TimeUnit.MILLISECOND:
|
|
280
|
+
return "time-millisecond";
|
|
281
|
+
case arrow.TimeUnit.MICROSECOND:
|
|
282
|
+
return "time-microsecond";
|
|
283
|
+
case arrow.TimeUnit.NANOSECOND:
|
|
284
|
+
return "time-nanosecond";
|
|
285
|
+
default:
|
|
286
|
+
return "time-second";
|
|
287
|
+
}
|
|
288
|
+
case arrow.TimeMillisecond:
|
|
289
|
+
return "time-millisecond";
|
|
290
|
+
case arrow.TimeSecond:
|
|
291
|
+
return "time-second";
|
|
292
|
+
case arrow.TimeMicrosecond:
|
|
293
|
+
return "time-microsecond";
|
|
294
|
+
case arrow.TimeNanosecond:
|
|
295
|
+
return "time-nanosecond";
|
|
296
|
+
case arrow.Timestamp:
|
|
297
|
+
const timeStampUnit = arrowType.unit;
|
|
298
|
+
switch (timeStampUnit) {
|
|
299
|
+
case arrow.TimeUnit.SECOND:
|
|
300
|
+
return "timestamp-second";
|
|
301
|
+
case arrow.TimeUnit.MILLISECOND:
|
|
302
|
+
return "timestamp-millisecond";
|
|
303
|
+
case arrow.TimeUnit.MICROSECOND:
|
|
304
|
+
return "timestamp-microsecond";
|
|
305
|
+
case arrow.TimeUnit.NANOSECOND:
|
|
306
|
+
return "timestamp-nanosecond";
|
|
307
|
+
default:
|
|
308
|
+
return "timestamp-second";
|
|
309
|
+
}
|
|
310
|
+
case arrow.TimestampSecond:
|
|
311
|
+
return "timestamp-second";
|
|
312
|
+
case arrow.TimestampMillisecond:
|
|
313
|
+
return "timestamp-millisecond";
|
|
314
|
+
case arrow.TimestampMicrosecond:
|
|
315
|
+
return "timestamp-microsecond";
|
|
316
|
+
case arrow.TimestampNanosecond:
|
|
317
|
+
return "timestamp-nanosecond";
|
|
318
|
+
case arrow.Interval:
|
|
319
|
+
const intervalUnit = arrowType.unit;
|
|
320
|
+
switch (intervalUnit) {
|
|
321
|
+
case arrow.IntervalUnit.DAY_TIME:
|
|
322
|
+
return "interval-daytime";
|
|
323
|
+
case arrow.IntervalUnit.YEAR_MONTH:
|
|
324
|
+
return "interval-yearmonth";
|
|
325
|
+
default:
|
|
326
|
+
return "interval-daytime";
|
|
327
|
+
}
|
|
328
|
+
case arrow.IntervalDayTime:
|
|
329
|
+
return "interval-daytime";
|
|
330
|
+
case arrow.IntervalYearMonth:
|
|
331
|
+
return "interval-yearmonth";
|
|
332
|
+
case arrow.Map_:
|
|
333
|
+
const mapType = arrowType;
|
|
334
|
+
return {
|
|
335
|
+
type: "map",
|
|
336
|
+
keysSorted: mapType.keysSorted,
|
|
337
|
+
children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
338
|
+
};
|
|
339
|
+
case arrow.List:
|
|
340
|
+
const listType = arrowType;
|
|
341
|
+
const listField = listType.valueField;
|
|
342
|
+
return {
|
|
343
|
+
type: "list",
|
|
344
|
+
children: [serializeArrowField(listField)]
|
|
345
|
+
};
|
|
346
|
+
case arrow.FixedSizeList:
|
|
347
|
+
const fixedSizeList = arrowType;
|
|
348
|
+
return {
|
|
349
|
+
type: "fixed-size-list",
|
|
350
|
+
listSize: fixedSizeList.listSize,
|
|
351
|
+
children: [serializeArrowField(fixedSizeList.children[0])]
|
|
352
|
+
};
|
|
353
|
+
case arrow.Struct:
|
|
354
|
+
const structType = arrowType;
|
|
355
|
+
return {
|
|
356
|
+
type: "struct",
|
|
357
|
+
children: structType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
358
|
+
};
|
|
359
|
+
default:
|
|
360
|
+
throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function deserializeArrowType(dataType) {
|
|
364
|
+
if (typeof dataType === "object") {
|
|
365
|
+
switch (dataType.type) {
|
|
366
|
+
case "decimal":
|
|
367
|
+
return new arrow.Decimal(dataType.precision, dataType.scale, dataType.bitWidth);
|
|
368
|
+
case "map":
|
|
369
|
+
let children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
370
|
+
return new arrow.Map_(children, dataType.keysSorted);
|
|
371
|
+
case "list":
|
|
372
|
+
const field = deserializeArrowField(dataType.children[0]);
|
|
373
|
+
return new arrow.List(field);
|
|
374
|
+
case "fixed-size-list":
|
|
375
|
+
const child = deserializeArrowField(dataType.children[0]);
|
|
376
|
+
return new arrow.FixedSizeList(dataType.listSize, child);
|
|
377
|
+
case "struct":
|
|
378
|
+
children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
379
|
+
return new arrow.Struct(children);
|
|
380
|
+
default:
|
|
381
|
+
throw new Error("array type not supported");
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
switch (dataType) {
|
|
385
|
+
case "null":
|
|
386
|
+
return new arrow.Null();
|
|
387
|
+
case "binary":
|
|
388
|
+
return new arrow.Binary();
|
|
389
|
+
case "bool":
|
|
390
|
+
return new arrow.Bool();
|
|
391
|
+
case "int8":
|
|
392
|
+
return new arrow.Int8();
|
|
393
|
+
case "int16":
|
|
394
|
+
return new arrow.Int16();
|
|
395
|
+
case "int32":
|
|
396
|
+
return new arrow.Int32();
|
|
397
|
+
case "int64":
|
|
398
|
+
return new arrow.Int64();
|
|
399
|
+
case "uint8":
|
|
400
|
+
return new arrow.Uint8();
|
|
401
|
+
case "uint16":
|
|
402
|
+
return new arrow.Uint16();
|
|
403
|
+
case "uint32":
|
|
404
|
+
return new arrow.Uint32();
|
|
405
|
+
case "uint64":
|
|
406
|
+
return new arrow.Uint64();
|
|
407
|
+
case "float16":
|
|
408
|
+
return new arrow.Float16();
|
|
409
|
+
case "float32":
|
|
410
|
+
return new arrow.Float32();
|
|
411
|
+
case "float64":
|
|
412
|
+
return new arrow.Float64();
|
|
413
|
+
case "utf8":
|
|
414
|
+
return new arrow.Utf8();
|
|
415
|
+
case "date-day":
|
|
416
|
+
return new arrow.DateDay();
|
|
417
|
+
case "date-millisecond":
|
|
418
|
+
return new arrow.DateMillisecond();
|
|
419
|
+
case "time-second":
|
|
420
|
+
return new arrow.TimeSecond();
|
|
421
|
+
case "time-millisecond":
|
|
422
|
+
return new arrow.TimeMillisecond();
|
|
423
|
+
case "time-microsecond":
|
|
424
|
+
return new arrow.TimeMicrosecond();
|
|
425
|
+
case "time-nanosecond":
|
|
426
|
+
return new arrow.TimeNanosecond();
|
|
427
|
+
case "timestamp-second":
|
|
428
|
+
return new arrow.TimestampSecond();
|
|
429
|
+
case "timestamp-millisecond":
|
|
430
|
+
return new arrow.TimestampMillisecond();
|
|
431
|
+
case "timestamp-microsecond":
|
|
432
|
+
return new arrow.TimestampMicrosecond();
|
|
433
|
+
case "timestamp-nanosecond":
|
|
434
|
+
return new arrow.TimestampNanosecond();
|
|
435
|
+
case "interval-daytime":
|
|
436
|
+
return new arrow.IntervalDayTime();
|
|
437
|
+
case "interval-yearmonth":
|
|
438
|
+
return new arrow.IntervalYearMonth();
|
|
439
|
+
default:
|
|
440
|
+
throw new Error("array type not supported");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// dist/lib/schema/deduce-table-schema.js
|
|
445
|
+
function deduceTableSchema(table) {
|
|
446
|
+
switch (table.shape) {
|
|
447
|
+
case "array-row-table":
|
|
448
|
+
case "object-row-table":
|
|
449
|
+
return deduceSchemaFromRows(table.data);
|
|
450
|
+
case "geojson-table":
|
|
451
|
+
return deduceSchemaFromGeoJSON(table.features);
|
|
452
|
+
case "columnar-table":
|
|
453
|
+
return deduceSchemaFromColumns(table.data);
|
|
454
|
+
case "arrow-table":
|
|
455
|
+
default:
|
|
456
|
+
throw new Error("Deduce schema");
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function deduceSchemaFromColumns(columnarTable) {
|
|
460
|
+
const fields = [];
|
|
461
|
+
for (const [columnName, column] of Object.entries(columnarTable)) {
|
|
462
|
+
const field = deduceFieldFromColumn(column, columnName);
|
|
463
|
+
fields.push(field);
|
|
464
|
+
}
|
|
465
|
+
return { fields, metadata: {} };
|
|
466
|
+
}
|
|
467
|
+
function deduceSchemaFromRows(rowTable) {
|
|
468
|
+
if (!rowTable.length) {
|
|
469
|
+
throw new Error("deduce from empty table");
|
|
470
|
+
}
|
|
471
|
+
const fields = [];
|
|
472
|
+
const row0 = rowTable[0];
|
|
473
|
+
for (const [columnName, value] of Object.entries(row0)) {
|
|
474
|
+
fields.push(deduceFieldFromValue(value, columnName));
|
|
475
|
+
}
|
|
476
|
+
return { fields, metadata: {} };
|
|
477
|
+
}
|
|
478
|
+
function deduceSchemaFromGeoJSON(features) {
|
|
479
|
+
if (!features.length) {
|
|
480
|
+
throw new Error("deduce from empty table");
|
|
481
|
+
}
|
|
482
|
+
const fields = [];
|
|
483
|
+
const row0 = features[0].properties || {};
|
|
484
|
+
for (const [columnName, value] of Object.entries(row0)) {
|
|
485
|
+
fields.push(deduceFieldFromValue(value, columnName));
|
|
486
|
+
}
|
|
487
|
+
return { fields, metadata: {} };
|
|
488
|
+
}
|
|
489
|
+
function deduceFieldFromColumn(column, name) {
|
|
490
|
+
if (ArrayBuffer.isView(column)) {
|
|
491
|
+
const type = getDataTypeFromArray(column);
|
|
492
|
+
return {
|
|
493
|
+
name,
|
|
494
|
+
type: type.type || "null",
|
|
495
|
+
nullable: type.nullable
|
|
496
|
+
// metadata: {}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
if (Array.isArray(column) && column.length > 0) {
|
|
500
|
+
const value = column[0];
|
|
501
|
+
const type = getDataTypeFromValue(value);
|
|
502
|
+
return {
|
|
503
|
+
name,
|
|
504
|
+
type,
|
|
505
|
+
nullable: true
|
|
506
|
+
// metadata: {},
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
throw new Error("empty table");
|
|
510
|
+
}
|
|
511
|
+
function deduceFieldFromValue(value, name) {
|
|
512
|
+
const type = getDataTypeFromValue(value);
|
|
513
|
+
return {
|
|
514
|
+
name,
|
|
515
|
+
type,
|
|
516
|
+
nullable: true
|
|
517
|
+
// metadata: {}
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
// dist/lib/table/tables/make-table.js
|
|
522
|
+
var arrow2 = __toESM(require("apache-arrow"), 1);
|
|
523
|
+
function makeTableFromData(data) {
|
|
524
|
+
let table;
|
|
525
|
+
switch (getTableShapeFromData(data)) {
|
|
526
|
+
case "array-row-table":
|
|
527
|
+
table = { shape: "array-row-table", data };
|
|
528
|
+
break;
|
|
529
|
+
case "object-row-table":
|
|
530
|
+
table = { shape: "object-row-table", data };
|
|
531
|
+
break;
|
|
532
|
+
case "columnar-table":
|
|
533
|
+
table = { shape: "columnar-table", data };
|
|
534
|
+
break;
|
|
535
|
+
case "arrow-table":
|
|
536
|
+
table = { shape: "arrow-table", data };
|
|
537
|
+
break;
|
|
538
|
+
default:
|
|
539
|
+
throw new Error("table");
|
|
540
|
+
}
|
|
541
|
+
const schema = deduceTableSchema(table);
|
|
542
|
+
return { ...table, schema };
|
|
543
|
+
}
|
|
544
|
+
function getTableShapeFromData(data) {
|
|
545
|
+
if (data instanceof arrow2.Table) {
|
|
546
|
+
return "arrow-table";
|
|
547
|
+
}
|
|
548
|
+
if (Array.isArray(data)) {
|
|
549
|
+
if (data.length === 0) {
|
|
550
|
+
throw new Error("cannot deduce type of empty table");
|
|
551
|
+
}
|
|
552
|
+
const firstRow = data[0];
|
|
553
|
+
if (Array.isArray(firstRow)) {
|
|
554
|
+
return "array-row-table";
|
|
555
|
+
}
|
|
556
|
+
if (firstRow && typeof firstRow === "object") {
|
|
557
|
+
return "object-row-table";
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
if (data && typeof data === "object") {
|
|
561
|
+
return "columnar-table";
|
|
562
|
+
}
|
|
563
|
+
throw new Error("invalid table");
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// dist/lib/table/tables/table-accessors.js
|
|
567
|
+
function isTable(table) {
|
|
568
|
+
var _a;
|
|
569
|
+
const shape = typeof table === "object" && (table == null ? void 0 : table.shape);
|
|
570
|
+
switch (shape) {
|
|
571
|
+
case "array-row-table":
|
|
572
|
+
case "object-row-table":
|
|
573
|
+
return Array.isArray(table.data);
|
|
574
|
+
case "geojson-table":
|
|
575
|
+
return Array.isArray(table.features);
|
|
576
|
+
case "columnar-table":
|
|
577
|
+
return table.data && typeof table.data === "object";
|
|
578
|
+
case "arrow-table":
|
|
579
|
+
return Boolean(((_a = table == null ? void 0 : table.data) == null ? void 0 : _a.numRows) !== void 0);
|
|
580
|
+
default:
|
|
581
|
+
return false;
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function getTableLength(table) {
|
|
585
|
+
switch (table.shape) {
|
|
586
|
+
case "array-row-table":
|
|
587
|
+
case "object-row-table":
|
|
588
|
+
return table.data.length;
|
|
589
|
+
case "geojson-table":
|
|
590
|
+
return table.features.length;
|
|
591
|
+
case "arrow-table":
|
|
592
|
+
const arrowTable = table.data;
|
|
593
|
+
return arrowTable.numRows;
|
|
594
|
+
case "columnar-table":
|
|
595
|
+
for (const column of Object.values(table.data)) {
|
|
596
|
+
return column.length || 0;
|
|
597
|
+
}
|
|
598
|
+
return 0;
|
|
599
|
+
default:
|
|
600
|
+
throw new Error("table");
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
function getTableNumCols(table) {
|
|
604
|
+
if (table.schema) {
|
|
605
|
+
return table.schema.fields.length;
|
|
606
|
+
}
|
|
607
|
+
if (getTableLength(table) === 0) {
|
|
608
|
+
throw new Error("empty table");
|
|
609
|
+
}
|
|
610
|
+
switch (table.shape) {
|
|
611
|
+
case "array-row-table":
|
|
612
|
+
return table.data[0].length;
|
|
613
|
+
case "object-row-table":
|
|
614
|
+
return Object.keys(table.data[0]).length;
|
|
615
|
+
case "geojson-table":
|
|
616
|
+
return Object.keys(table.features[0]).length;
|
|
617
|
+
case "columnar-table":
|
|
618
|
+
return Object.keys(table.data).length;
|
|
619
|
+
case "arrow-table":
|
|
620
|
+
const arrowTable = table.data;
|
|
621
|
+
return arrowTable.numCols;
|
|
622
|
+
default:
|
|
623
|
+
throw new Error("table");
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
function getTableCell(table, rowIndex, columnName) {
|
|
627
|
+
var _a;
|
|
628
|
+
switch (table.shape) {
|
|
629
|
+
case "array-row-table":
|
|
630
|
+
const columnIndex = getTableColumnIndex(table, columnName);
|
|
631
|
+
return table.data[rowIndex][columnIndex];
|
|
632
|
+
case "object-row-table":
|
|
633
|
+
return table.data[rowIndex][columnName];
|
|
634
|
+
case "geojson-table":
|
|
635
|
+
return table.features[rowIndex][columnName];
|
|
636
|
+
case "columnar-table":
|
|
637
|
+
const column = table.data[columnName];
|
|
638
|
+
return column[rowIndex];
|
|
639
|
+
case "arrow-table":
|
|
640
|
+
const arrowTable = table.data;
|
|
641
|
+
const arrowColumnIndex = arrowTable.schema.fields.findIndex((field) => field.name === columnName);
|
|
642
|
+
return (_a = arrowTable.getChildAt(arrowColumnIndex)) == null ? void 0 : _a.get(rowIndex);
|
|
643
|
+
default:
|
|
644
|
+
throw new Error("todo");
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function getTableCellAt(table, rowIndex, columnIndex) {
|
|
648
|
+
var _a;
|
|
649
|
+
switch (table.shape) {
|
|
650
|
+
case "array-row-table":
|
|
651
|
+
return table.data[rowIndex][columnIndex];
|
|
652
|
+
case "object-row-table":
|
|
653
|
+
const columnName1 = getTableColumnName(table, columnIndex);
|
|
654
|
+
return table.data[rowIndex][columnName1];
|
|
655
|
+
case "geojson-table":
|
|
656
|
+
const columnName2 = getTableColumnName(table, columnIndex);
|
|
657
|
+
return table.features[rowIndex][columnName2];
|
|
658
|
+
case "columnar-table":
|
|
659
|
+
const columnName3 = getTableColumnName(table, columnIndex);
|
|
660
|
+
const column = table.data[columnName3];
|
|
661
|
+
return column[rowIndex];
|
|
662
|
+
case "arrow-table":
|
|
663
|
+
const arrowTable = table.data;
|
|
664
|
+
return (_a = arrowTable.getChildAt(columnIndex)) == null ? void 0 : _a.get(rowIndex);
|
|
665
|
+
default:
|
|
666
|
+
throw new Error("todo");
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
function getTableRowShape(table) {
|
|
670
|
+
switch (table.shape) {
|
|
671
|
+
case "array-row-table":
|
|
672
|
+
case "object-row-table":
|
|
673
|
+
return table.shape;
|
|
674
|
+
case "geojson-table":
|
|
675
|
+
return "object-row-table";
|
|
676
|
+
case "columnar-table":
|
|
677
|
+
default:
|
|
678
|
+
throw new Error("Not a row table");
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
function getTableColumnIndex(table, columnName) {
|
|
682
|
+
var _a;
|
|
683
|
+
const columnIndex = (_a = table.schema) == null ? void 0 : _a.fields.findIndex((field) => field.name === columnName);
|
|
684
|
+
if (columnIndex === void 0) {
|
|
685
|
+
throw new Error(columnName);
|
|
686
|
+
}
|
|
687
|
+
return columnIndex;
|
|
688
|
+
}
|
|
689
|
+
function getTableColumnName(table, columnIndex) {
|
|
690
|
+
var _a, _b;
|
|
691
|
+
const columnName = (_b = (_a = table.schema) == null ? void 0 : _a.fields[columnIndex]) == null ? void 0 : _b.name;
|
|
692
|
+
if (!columnName) {
|
|
693
|
+
throw new Error(`${columnIndex}`);
|
|
694
|
+
}
|
|
695
|
+
return columnName;
|
|
696
|
+
}
|
|
697
|
+
function getTableRowAsObject(table, rowIndex, target, copy) {
|
|
698
|
+
switch (table.shape) {
|
|
699
|
+
case "object-row-table":
|
|
700
|
+
return copy ? Object.fromEntries(Object.entries(table.data[rowIndex])) : table.data[rowIndex];
|
|
701
|
+
case "array-row-table":
|
|
702
|
+
if (table.schema) {
|
|
703
|
+
const objectRow2 = target || {};
|
|
704
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
705
|
+
objectRow2[table.schema.fields[i].name] = table.data[rowIndex][i];
|
|
706
|
+
}
|
|
707
|
+
return objectRow2;
|
|
708
|
+
}
|
|
709
|
+
throw new Error("no schema");
|
|
710
|
+
case "geojson-table":
|
|
711
|
+
if (table.schema) {
|
|
712
|
+
const objectRow2 = target || {};
|
|
713
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
714
|
+
objectRow2[table.schema.fields[i].name] = table.features[rowIndex][i];
|
|
715
|
+
}
|
|
716
|
+
return objectRow2;
|
|
717
|
+
}
|
|
718
|
+
throw new Error("no schema");
|
|
719
|
+
case "columnar-table":
|
|
720
|
+
if (table.schema) {
|
|
721
|
+
const objectRow2 = target || {};
|
|
722
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
723
|
+
objectRow2[table.schema.fields[i].name] = table.data[table.schema.fields[i].name][rowIndex];
|
|
724
|
+
}
|
|
725
|
+
return objectRow2;
|
|
726
|
+
} else {
|
|
727
|
+
const objectRow2 = target || {};
|
|
728
|
+
for (const [name, column] of Object.entries(table.data)) {
|
|
729
|
+
objectRow2[name] = column[rowIndex];
|
|
730
|
+
}
|
|
731
|
+
return objectRow2;
|
|
732
|
+
}
|
|
733
|
+
case "arrow-table":
|
|
734
|
+
const arrowTable = table.data;
|
|
735
|
+
const objectRow = target || {};
|
|
736
|
+
const row = arrowTable.get(rowIndex);
|
|
737
|
+
const schema = arrowTable.schema;
|
|
738
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
739
|
+
objectRow[schema.fields[i].name] = row == null ? void 0 : row[schema.fields[i].name];
|
|
740
|
+
}
|
|
741
|
+
return objectRow;
|
|
742
|
+
default:
|
|
743
|
+
throw new Error("shape");
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
function getTableRowAsArray(table, rowIndex, target, copy) {
|
|
747
|
+
switch (table.shape) {
|
|
748
|
+
case "array-row-table":
|
|
749
|
+
return copy ? Array.from(table.data[rowIndex]) : table.data[rowIndex];
|
|
750
|
+
case "object-row-table":
|
|
751
|
+
if (table.schema) {
|
|
752
|
+
const arrayRow2 = target || [];
|
|
753
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
754
|
+
arrayRow2[i] = table.data[rowIndex][table.schema.fields[i].name];
|
|
755
|
+
}
|
|
756
|
+
return arrayRow2;
|
|
757
|
+
}
|
|
758
|
+
return Object.values(table.data[rowIndex]);
|
|
759
|
+
case "geojson-table":
|
|
760
|
+
if (table.schema) {
|
|
761
|
+
const arrayRow2 = target || [];
|
|
762
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
763
|
+
arrayRow2[i] = table.features[rowIndex][table.schema.fields[i].name];
|
|
764
|
+
}
|
|
765
|
+
return arrayRow2;
|
|
766
|
+
}
|
|
767
|
+
return Object.values(table.features[rowIndex]);
|
|
768
|
+
case "columnar-table":
|
|
769
|
+
if (table.schema) {
|
|
770
|
+
const arrayRow2 = target || [];
|
|
771
|
+
for (let i = 0; i < table.schema.fields.length; i++) {
|
|
772
|
+
arrayRow2[i] = table.data[table.schema.fields[i].name][rowIndex];
|
|
773
|
+
}
|
|
774
|
+
return arrayRow2;
|
|
775
|
+
} else {
|
|
776
|
+
const arrayRow2 = target || [];
|
|
777
|
+
let i = 0;
|
|
778
|
+
for (const column of Object.values(table.data)) {
|
|
779
|
+
arrayRow2[i] = column[rowIndex];
|
|
780
|
+
i++;
|
|
781
|
+
}
|
|
782
|
+
return arrayRow2;
|
|
783
|
+
}
|
|
784
|
+
case "arrow-table":
|
|
785
|
+
const arrowTable = table.data;
|
|
786
|
+
const arrayRow = target || [];
|
|
787
|
+
const row = arrowTable.get(rowIndex);
|
|
788
|
+
const schema = arrowTable.schema;
|
|
789
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
790
|
+
arrayRow[i] = row == null ? void 0 : row[schema.fields[i].name];
|
|
791
|
+
}
|
|
792
|
+
return arrayRow;
|
|
793
|
+
default:
|
|
794
|
+
throw new Error("shape");
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
function* makeRowIterator(table, shape) {
|
|
798
|
+
switch (shape) {
|
|
799
|
+
case "array-row-table":
|
|
800
|
+
yield* makeArrayRowIterator(table);
|
|
801
|
+
break;
|
|
802
|
+
case "object-row-table":
|
|
803
|
+
yield* makeObjectRowIterator(table);
|
|
804
|
+
break;
|
|
805
|
+
default:
|
|
806
|
+
throw new Error(`Unknown row type ${shape}`);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
function* makeArrayRowIterator(table, target = []) {
|
|
810
|
+
const length = getTableLength(table);
|
|
811
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
812
|
+
yield getTableRowAsArray(table, rowIndex, target);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
function* makeObjectRowIterator(table, target = {}) {
|
|
816
|
+
const length = getTableLength(table);
|
|
817
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
818
|
+
yield getTableRowAsObject(table, rowIndex, target);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// dist/lib/table/batches/make-table-from-batches.js
|
|
823
|
+
async function makeTableFromBatches(batchIterator) {
|
|
824
|
+
let arrayRows;
|
|
825
|
+
let objectRows;
|
|
826
|
+
let features;
|
|
827
|
+
let shape = null;
|
|
828
|
+
let schema;
|
|
829
|
+
for await (const batch of batchIterator) {
|
|
830
|
+
shape = shape || batch.shape;
|
|
831
|
+
schema = schema || batch.schema;
|
|
832
|
+
switch (batch.shape) {
|
|
833
|
+
case "array-row-table":
|
|
834
|
+
arrayRows = arrayRows || [];
|
|
835
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
836
|
+
const row = batch.data[rowIndex];
|
|
837
|
+
arrayRows.push(row);
|
|
838
|
+
}
|
|
839
|
+
break;
|
|
840
|
+
case "object-row-table":
|
|
841
|
+
objectRows = objectRows || [];
|
|
842
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
843
|
+
const row = batch.data[rowIndex];
|
|
844
|
+
objectRows.push(row);
|
|
845
|
+
}
|
|
846
|
+
break;
|
|
847
|
+
case "geojson-table":
|
|
848
|
+
features = features || [];
|
|
849
|
+
for (let rowIndex = 0; rowIndex < getTableLength(batch); rowIndex++) {
|
|
850
|
+
const row = batch.features[rowIndex];
|
|
851
|
+
features.push(row);
|
|
852
|
+
}
|
|
853
|
+
break;
|
|
854
|
+
case "columnar-table":
|
|
855
|
+
case "arrow-table":
|
|
856
|
+
default:
|
|
857
|
+
throw new Error("shape");
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (!shape) {
|
|
861
|
+
return null;
|
|
862
|
+
}
|
|
863
|
+
switch (shape) {
|
|
864
|
+
case "array-row-table":
|
|
865
|
+
return { shape: "array-row-table", data: arrayRows, schema };
|
|
866
|
+
case "object-row-table":
|
|
867
|
+
return { shape: "object-row-table", data: objectRows, schema };
|
|
868
|
+
case "geojson-table":
|
|
869
|
+
return { shape: "geojson-table", type: "FeatureCollection", features, schema };
|
|
870
|
+
default:
|
|
871
|
+
return null;
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
// dist/lib/table/tables/table-column.js
|
|
876
|
+
function makeColumnFromField(field, length) {
|
|
877
|
+
const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
|
|
878
|
+
return new ArrayType(length);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// dist/lib/table/tables/convert-arrow-table.js
|
|
882
|
+
var arrow4 = __toESM(require("apache-arrow"), 1);
|
|
883
|
+
|
|
884
|
+
// dist/lib/table/batches/make-arrow-batch-iterator.js
|
|
885
|
+
var arrow3 = __toESM(require("apache-arrow"), 1);
|
|
886
|
+
function* makeArrowTableBatchIterator(table, options) {
|
|
887
|
+
for (const batch of makeArrowRecordBatchIterator(table, options)) {
|
|
888
|
+
const arrowTable = new arrow3.Table([batch]);
|
|
889
|
+
yield {
|
|
890
|
+
...batch,
|
|
891
|
+
shape: "arrow-table",
|
|
892
|
+
schema: table.schema,
|
|
893
|
+
batchType: "data",
|
|
894
|
+
length: arrowTable.numRows,
|
|
895
|
+
data: arrowTable
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
function* makeArrowRecordBatchIterator(table, options) {
|
|
900
|
+
const arrowSchema = convertSchemaToArrow(table.schema);
|
|
901
|
+
const length = getTableLength(table);
|
|
902
|
+
const numColumns = getTableNumCols(table);
|
|
903
|
+
const batchSize = (options == null ? void 0 : options.batchSize) || length;
|
|
904
|
+
const builders = arrowSchema == null ? void 0 : arrowSchema.fields.map((arrowField) => arrow3.makeBuilder(arrowField));
|
|
905
|
+
const structField = new arrow3.Struct(arrowSchema.fields);
|
|
906
|
+
let batchLength = 0;
|
|
907
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
908
|
+
for (let columnIndex = 0; columnIndex < numColumns; ++columnIndex) {
|
|
909
|
+
const value = getTableCellAt(table, rowIndex, columnIndex);
|
|
910
|
+
const builder = builders[columnIndex];
|
|
911
|
+
builder.append(value);
|
|
912
|
+
batchLength++;
|
|
913
|
+
if (batchLength >= batchSize) {
|
|
914
|
+
const datas = builders.map((builder2) => builder2.flush());
|
|
915
|
+
const structData = new arrow3.Data(structField, 0, batchLength, 0, void 0, datas);
|
|
916
|
+
yield new arrow3.RecordBatch(arrowSchema, structData);
|
|
917
|
+
batchLength = 0;
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
if (batchLength > 0) {
|
|
922
|
+
const datas = builders.map((builder) => builder.flush());
|
|
923
|
+
const structData = new arrow3.Data(structField, 0, batchLength, 0, void 0, datas);
|
|
924
|
+
yield new arrow3.RecordBatch(arrowSchema, structData);
|
|
925
|
+
batchLength = 0;
|
|
926
|
+
}
|
|
927
|
+
builders.map((builder) => builder.finish());
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
// dist/lib/table/tables/convert-arrow-table.js
|
|
931
|
+
function convertTableToArrow(table, options) {
|
|
932
|
+
switch (table.shape) {
|
|
933
|
+
case "arrow-table":
|
|
934
|
+
return table.data;
|
|
935
|
+
case "columnar-table":
|
|
936
|
+
default:
|
|
937
|
+
const arrowBatchIterator = makeArrowRecordBatchIterator(table, options);
|
|
938
|
+
return new arrow4.Table(arrowBatchIterator);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
function convertArrowToTable(arrowTable, shape) {
|
|
942
|
+
switch (shape) {
|
|
943
|
+
case "arrow-table":
|
|
944
|
+
return convertArrowToArrowTable(arrowTable);
|
|
945
|
+
case "array-row-table":
|
|
946
|
+
return convertArrowToArrayRowTable(arrowTable);
|
|
947
|
+
case "object-row-table":
|
|
948
|
+
return convertArrowToObjectRowTable(arrowTable);
|
|
949
|
+
case "columnar-table":
|
|
950
|
+
return convertArrowToColumnarTable(arrowTable);
|
|
951
|
+
case "geojson-table":
|
|
952
|
+
return convertArrowToGeoJSONTable(arrowTable);
|
|
953
|
+
default:
|
|
954
|
+
throw new Error(shape);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function convertArrowToArrowTable(arrowTable) {
|
|
958
|
+
return {
|
|
959
|
+
shape: "arrow-table",
|
|
960
|
+
schema: convertArrowToSchema(arrowTable.schema),
|
|
961
|
+
data: arrowTable
|
|
962
|
+
};
|
|
963
|
+
}
|
|
964
|
+
function convertArrowToArrayRowTable(arrowTable) {
|
|
965
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
966
|
+
return convertTable(columnarTable, "array-row-table");
|
|
967
|
+
}
|
|
968
|
+
function convertArrowToObjectRowTable(arrowTable) {
|
|
969
|
+
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
970
|
+
return convertTable(columnarTable, "object-row-table");
|
|
971
|
+
}
|
|
972
|
+
function convertArrowToColumnarTable(arrowTable) {
|
|
973
|
+
const columns = {};
|
|
974
|
+
for (const field of arrowTable.schema.fields) {
|
|
975
|
+
const arrowColumn = arrowTable.getChild(field.name);
|
|
976
|
+
const values = arrowColumn == null ? void 0 : arrowColumn.toArray();
|
|
977
|
+
columns[field.name] = values;
|
|
978
|
+
}
|
|
979
|
+
const schema = convertArrowToSchema(arrowTable.schema);
|
|
980
|
+
return {
|
|
981
|
+
shape: "columnar-table",
|
|
982
|
+
schema,
|
|
983
|
+
data: columns
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
function convertArrowToGeoJSONTable(arrowTable) {
|
|
987
|
+
var _a;
|
|
988
|
+
const schema = convertArrowToSchema(arrowTable.schema);
|
|
989
|
+
const features = [];
|
|
990
|
+
for (let row = 0; row < arrowTable.numRows; row++) {
|
|
991
|
+
const properties = ((_a = arrowTable.get(row)) == null ? void 0 : _a.toJSON()) || {};
|
|
992
|
+
features.push({ type: "Feature", geometry: null, properties });
|
|
993
|
+
}
|
|
994
|
+
return {
|
|
995
|
+
shape: "geojson-table",
|
|
996
|
+
type: "FeatureCollection",
|
|
997
|
+
schema,
|
|
998
|
+
features
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// dist/lib/table/tables/convert-table.js
|
|
1003
|
+
function convertTable(table, shape) {
|
|
1004
|
+
switch (shape) {
|
|
1005
|
+
case "object-row-table":
|
|
1006
|
+
return convertToObjectRowTable(table);
|
|
1007
|
+
case "array-row-table":
|
|
1008
|
+
return convertToArrayRowTable(table);
|
|
1009
|
+
case "columnar-table":
|
|
1010
|
+
return convertToColumnarTable(table);
|
|
1011
|
+
case "arrow-table":
|
|
1012
|
+
return convertToArrowTable(table);
|
|
1013
|
+
default:
|
|
1014
|
+
throw new Error(shape);
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
function convertToColumnarTable(table) {
|
|
1018
|
+
var _a;
|
|
1019
|
+
const schema = table.schema || deduceTableSchema(table);
|
|
1020
|
+
const fields = ((_a = table.schema) == null ? void 0 : _a.fields) || [];
|
|
1021
|
+
if (table.shape === "columnar-table") {
|
|
1022
|
+
return { ...table, schema };
|
|
1023
|
+
}
|
|
1024
|
+
const length = getTableLength(table);
|
|
1025
|
+
const columns = {};
|
|
1026
|
+
for (const field of fields) {
|
|
1027
|
+
const column = makeColumnFromField(field, length);
|
|
1028
|
+
columns[field.name] = column;
|
|
1029
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
1030
|
+
column[rowIndex] = getTableCell(table, rowIndex, field.name);
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
return {
|
|
1034
|
+
shape: "columnar-table",
|
|
1035
|
+
schema,
|
|
1036
|
+
data: columns
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
function convertToArrayRowTable(table) {
|
|
1040
|
+
if (table.shape === "array-row-table") {
|
|
1041
|
+
return table;
|
|
1042
|
+
}
|
|
1043
|
+
const length = getTableLength(table);
|
|
1044
|
+
const data = new Array(length);
|
|
1045
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
1046
|
+
data[rowIndex] = getTableRowAsArray(table, rowIndex);
|
|
1047
|
+
}
|
|
1048
|
+
return {
|
|
1049
|
+
shape: "array-row-table",
|
|
1050
|
+
schema: table.schema,
|
|
1051
|
+
data
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
function convertToObjectRowTable(table) {
|
|
1055
|
+
if (table.shape === "object-row-table") {
|
|
1056
|
+
return table;
|
|
1057
|
+
}
|
|
1058
|
+
const length = getTableLength(table);
|
|
1059
|
+
const data = new Array(length);
|
|
1060
|
+
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
1061
|
+
data[rowIndex] = getTableRowAsObject(table, rowIndex);
|
|
1062
|
+
}
|
|
1063
|
+
return {
|
|
1064
|
+
shape: "object-row-table",
|
|
1065
|
+
schema: table.schema,
|
|
1066
|
+
data
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
function convertToArrowTable(table) {
|
|
1070
|
+
const arrowTable = convertTableToArrow(table);
|
|
1071
|
+
return {
|
|
1072
|
+
shape: "arrow-table",
|
|
1073
|
+
schema: table.schema,
|
|
1074
|
+
data: arrowTable
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
|
|
1078
|
+
// dist/lib/table/tables/row-utils.js
|
|
1079
|
+
function convertToObjectRow(arrayRow, headers) {
|
|
1080
|
+
if (!arrayRow) {
|
|
1081
|
+
throw new Error("null row");
|
|
1082
|
+
}
|
|
1083
|
+
const objectRow = {};
|
|
1084
|
+
if (headers) {
|
|
1085
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1086
|
+
objectRow[headers[i]] = arrayRow[i];
|
|
1087
|
+
}
|
|
1088
|
+
} else {
|
|
1089
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
1090
|
+
const columnName = `column-${i}`;
|
|
1091
|
+
objectRow[columnName] = arrayRow[i];
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
return objectRow;
|
|
1095
|
+
}
|
|
1096
|
+
function convertToArrayRow(objectRow, headers) {
|
|
1097
|
+
if (!objectRow) {
|
|
1098
|
+
throw new Error("null row");
|
|
1099
|
+
}
|
|
1100
|
+
if (headers) {
|
|
1101
|
+
const arrayRow = new Array(headers.length);
|
|
1102
|
+
for (let i = 0; i < headers.length; i++) {
|
|
1103
|
+
arrayRow[i] = objectRow[headers[i]];
|
|
1104
|
+
}
|
|
1105
|
+
return arrayRow;
|
|
1106
|
+
}
|
|
1107
|
+
return Object.values(objectRow);
|
|
1108
|
+
}
|
|
1109
|
+
function inferHeadersFromArrayRow(arrayRow) {
|
|
1110
|
+
const headers = [];
|
|
1111
|
+
for (let i = 0; i < arrayRow.length; i++) {
|
|
1112
|
+
const columnName = `column-${i}`;
|
|
1113
|
+
headers.push(columnName);
|
|
1114
|
+
}
|
|
1115
|
+
return headers;
|
|
1116
|
+
}
|
|
1117
|
+
function inferHeadersFromObjectRow(row) {
|
|
1118
|
+
return Object.keys(row);
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
// dist/lib/table/batches/make-table-batch-iterator.js
|
|
1122
|
+
function* makeTableBatchIterator(table) {
|
|
1123
|
+
yield makeBatchFromTable(table);
|
|
1124
|
+
}
|
|
1125
|
+
function makeBatchFromTable(table) {
|
|
1126
|
+
return { ...table, length: getTableLength(table), batchType: "data" };
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
// dist/lib/table/batches/convert-batches.js
|
|
1130
|
+
function convertBatch(batch, shape) {
|
|
1131
|
+
switch (shape) {
|
|
1132
|
+
case "object-row-table":
|
|
1133
|
+
return { ...batch, ...convertTable(batch, "object-row-table") };
|
|
1134
|
+
case "array-row-table":
|
|
1135
|
+
return { ...batch, ...convertTable(batch, "array-row-table") };
|
|
1136
|
+
case "columnar-table":
|
|
1137
|
+
return { ...batch, ...convertTable(batch, "columnar-table") };
|
|
1138
|
+
case "arrow-table":
|
|
1139
|
+
return { ...batch, ...convertTable(batch, "arrow-table") };
|
|
1140
|
+
default:
|
|
1141
|
+
throw new Error(shape);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
async function* convertBatches(batches, shape) {
|
|
1145
|
+
for await (const batch of batches) {
|
|
1146
|
+
switch (shape) {
|
|
1147
|
+
case "object-row-table":
|
|
1148
|
+
yield convertBatch(batch, "object-row-table");
|
|
1149
|
+
break;
|
|
1150
|
+
case "array-row-table":
|
|
1151
|
+
yield convertBatch(batch, "array-row-table");
|
|
1152
|
+
break;
|
|
1153
|
+
case "columnar-table":
|
|
1154
|
+
yield convertBatch(batch, "columnar-table");
|
|
1155
|
+
break;
|
|
1156
|
+
case "arrow-table":
|
|
1157
|
+
yield convertBatch(batch, "arrow-table");
|
|
1158
|
+
break;
|
|
1159
|
+
default:
|
|
1160
|
+
throw new Error(shape);
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// dist/lib/table/tables/table-types.js
|
|
1166
|
+
function isArrayRowTable(table) {
|
|
1167
|
+
return table.shape === "array-row-table";
|
|
1168
|
+
}
|
|
1169
|
+
function isObjectRowTable(table) {
|
|
1170
|
+
return table.shape === "object-row-table";
|
|
1171
|
+
}
|
|
1172
|
+
function isColumnarTable(table) {
|
|
1173
|
+
return table.shape === "columnar-table";
|
|
1174
|
+
}
|
|
1175
|
+
function isGeoJSONTable(table) {
|
|
1176
|
+
return table.shape === "geojson-table";
|
|
1177
|
+
}
|
|
1178
|
+
function isArrowTable(table) {
|
|
1179
|
+
return table.shape === "arrow-table";
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
// dist/lib/table/batch-builder/base-table-batch-aggregator.js
|
|
1183
|
+
var DEFAULT_ROW_COUNT = 100;
|
|
1184
|
+
var BaseTableBatchAggregator = class {
|
|
1185
|
+
schema;
|
|
1186
|
+
options;
|
|
1187
|
+
shape;
|
|
1188
|
+
length = 0;
|
|
1189
|
+
rows = null;
|
|
1190
|
+
cursor = 0;
|
|
1191
|
+
_headers = [];
|
|
1192
|
+
constructor(schema, options) {
|
|
1193
|
+
this.options = options;
|
|
1194
|
+
this.schema = schema;
|
|
1195
|
+
if (!Array.isArray(schema)) {
|
|
1196
|
+
this._headers = [];
|
|
1197
|
+
for (const key in schema) {
|
|
1198
|
+
this._headers[schema[key].index] = schema[key].name;
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
rowCount() {
|
|
1203
|
+
return this.length;
|
|
1204
|
+
}
|
|
1205
|
+
addArrayRow(row, cursor) {
|
|
1206
|
+
if (Number.isFinite(cursor)) {
|
|
1207
|
+
this.cursor = cursor;
|
|
1208
|
+
}
|
|
1209
|
+
this.shape = "array-row-table";
|
|
1210
|
+
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
1211
|
+
this.rows[this.length] = row;
|
|
1212
|
+
this.length++;
|
|
1213
|
+
}
|
|
1214
|
+
addObjectRow(row, cursor) {
|
|
1215
|
+
if (Number.isFinite(cursor)) {
|
|
1216
|
+
this.cursor = cursor;
|
|
1217
|
+
}
|
|
1218
|
+
this.shape = "object-row-table";
|
|
1219
|
+
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
1220
|
+
this.rows[this.length] = row;
|
|
1221
|
+
this.length++;
|
|
1222
|
+
}
|
|
1223
|
+
getBatch() {
|
|
1224
|
+
let rows = this.rows;
|
|
1225
|
+
if (!rows) {
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
rows = rows.slice(0, this.length);
|
|
1229
|
+
this.rows = null;
|
|
1230
|
+
const batch = {
|
|
1231
|
+
shape: this.shape || "array-row-table",
|
|
1232
|
+
batchType: "data",
|
|
1233
|
+
data: rows,
|
|
1234
|
+
length: this.length,
|
|
1235
|
+
schema: this.schema,
|
|
1236
|
+
cursor: this.cursor
|
|
1237
|
+
};
|
|
1238
|
+
return batch;
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1242
|
+
// dist/lib/table/batch-builder/row-table-batch-aggregator.js
|
|
1243
|
+
var DEFAULT_ROW_COUNT2 = 100;
|
|
1244
|
+
var RowTableBatchAggregator = class {
|
|
1245
|
+
schema;
|
|
1246
|
+
options;
|
|
1247
|
+
length = 0;
|
|
1248
|
+
objectRows = null;
|
|
1249
|
+
arrayRows = null;
|
|
1250
|
+
cursor = 0;
|
|
1251
|
+
_headers = null;
|
|
1252
|
+
constructor(schema, options) {
|
|
1253
|
+
this.options = options;
|
|
1254
|
+
this.schema = schema;
|
|
1255
|
+
if (schema) {
|
|
1256
|
+
this._headers = [];
|
|
1257
|
+
for (let i = 0; i < schema.fields.length; i++) {
|
|
1258
|
+
this._headers[i] = schema.fields[i].name;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
rowCount() {
|
|
1263
|
+
return this.length;
|
|
1264
|
+
}
|
|
1265
|
+
addArrayRow(row, cursor) {
|
|
1266
|
+
if (Number.isFinite(cursor)) {
|
|
1267
|
+
this.cursor = cursor;
|
|
1268
|
+
}
|
|
1269
|
+
this._headers ||= inferHeadersFromArrayRow(row);
|
|
1270
|
+
switch (this.options.shape) {
|
|
1271
|
+
case "object-row-table":
|
|
1272
|
+
const rowObject = convertToObjectRow(row, this._headers);
|
|
1273
|
+
this.addObjectRow(rowObject, cursor);
|
|
1274
|
+
break;
|
|
1275
|
+
case "array-row-table":
|
|
1276
|
+
this.arrayRows = this.arrayRows || new Array(DEFAULT_ROW_COUNT2);
|
|
1277
|
+
this.arrayRows[this.length] = row;
|
|
1278
|
+
this.length++;
|
|
1279
|
+
break;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
addObjectRow(row, cursor) {
|
|
1283
|
+
if (Number.isFinite(cursor)) {
|
|
1284
|
+
this.cursor = cursor;
|
|
1285
|
+
}
|
|
1286
|
+
this._headers ||= inferHeadersFromObjectRow(row);
|
|
1287
|
+
switch (this.options.shape) {
|
|
1288
|
+
case "array-row-table":
|
|
1289
|
+
const rowArray = convertToArrayRow(row, this._headers);
|
|
1290
|
+
this.addArrayRow(rowArray, cursor);
|
|
1291
|
+
break;
|
|
1292
|
+
case "object-row-table":
|
|
1293
|
+
this.objectRows = this.objectRows || new Array(DEFAULT_ROW_COUNT2);
|
|
1294
|
+
this.objectRows[this.length] = row;
|
|
1295
|
+
this.length++;
|
|
1296
|
+
break;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
getBatch() {
|
|
1300
|
+
let rows = this.arrayRows || this.objectRows;
|
|
1301
|
+
if (!rows) {
|
|
1302
|
+
return null;
|
|
1303
|
+
}
|
|
1304
|
+
rows = rows.slice(0, this.length);
|
|
1305
|
+
this.arrayRows = null;
|
|
1306
|
+
this.objectRows = null;
|
|
1307
|
+
return {
|
|
1308
|
+
shape: this.options.shape,
|
|
1309
|
+
batchType: "data",
|
|
1310
|
+
data: rows,
|
|
1311
|
+
length: this.length,
|
|
1312
|
+
// @ts-expect-error we should infer a schema
|
|
1313
|
+
schema: this.schema,
|
|
1314
|
+
cursor: this.cursor
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
|
|
1319
|
+
// dist/lib/table/batch-builder/columnar-table-batch-aggregator.js
|
|
1320
|
+
var import_types = require("@math.gl/types");
|
|
1321
|
+
var DEFAULT_ROW_COUNT3 = 100;
|
|
1322
|
+
var ColumnarTableBatchAggregator = class {
|
|
1323
|
+
schema;
|
|
1324
|
+
length = 0;
|
|
1325
|
+
allocated = 0;
|
|
1326
|
+
columns = {};
|
|
1327
|
+
constructor(schema, options) {
|
|
1328
|
+
this.schema = schema;
|
|
1329
|
+
this._reallocateColumns();
|
|
1330
|
+
}
|
|
1331
|
+
rowCount() {
|
|
1332
|
+
return this.length;
|
|
1333
|
+
}
|
|
1334
|
+
addArrayRow(row) {
|
|
1335
|
+
this._reallocateColumns();
|
|
1336
|
+
let i = 0;
|
|
1337
|
+
for (const fieldName in this.columns) {
|
|
1338
|
+
this.columns[fieldName][this.length] = row[i++];
|
|
1339
|
+
}
|
|
1340
|
+
this.length++;
|
|
1341
|
+
}
|
|
1342
|
+
addObjectRow(row) {
|
|
1343
|
+
this._reallocateColumns();
|
|
1344
|
+
for (const fieldName in row) {
|
|
1345
|
+
this.columns[fieldName][this.length] = row[fieldName];
|
|
1346
|
+
}
|
|
1347
|
+
this.length++;
|
|
1348
|
+
}
|
|
1349
|
+
getBatch() {
|
|
1350
|
+
this._pruneColumns();
|
|
1351
|
+
const batch = {
|
|
1352
|
+
shape: "columnar-table",
|
|
1353
|
+
batchType: "data",
|
|
1354
|
+
data: this.columns,
|
|
1355
|
+
schema: this.schema,
|
|
1356
|
+
length: this.length
|
|
1357
|
+
};
|
|
1358
|
+
return batch;
|
|
1359
|
+
}
|
|
1360
|
+
// HELPERS
|
|
1361
|
+
_reallocateColumns() {
|
|
1362
|
+
if (this.length < this.allocated) {
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1365
|
+
this.allocated = this.allocated > 0 ? this.allocated *= 2 : DEFAULT_ROW_COUNT3;
|
|
1366
|
+
this.columns = {};
|
|
1367
|
+
for (const field of this.schema.fields) {
|
|
1368
|
+
const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
|
|
1369
|
+
const oldColumn = this.columns[field.name];
|
|
1370
|
+
if (!oldColumn) {
|
|
1371
|
+
this.columns[field.name] = new ArrayType(this.allocated);
|
|
1372
|
+
} else if (Array.isArray(oldColumn)) {
|
|
1373
|
+
oldColumn.length = this.allocated;
|
|
1374
|
+
} else if ((0, import_types.isTypedArray)(oldColumn)) {
|
|
1375
|
+
const typedArray = new ArrayType(this.allocated);
|
|
1376
|
+
typedArray.set(oldColumn);
|
|
1377
|
+
this.columns[field.name] = typedArray;
|
|
1378
|
+
} else {
|
|
1379
|
+
throw new Error("Invalid column type");
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
_pruneColumns() {
|
|
1384
|
+
for (const [columnName, column] of Object.entries(this.columns)) {
|
|
1385
|
+
this.columns[columnName] = column.slice(0, this.length);
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
};
|
|
1389
|
+
|
|
1390
|
+
// dist/lib/table/batch-builder/arrow-table-batch-aggregator.js
|
|
1391
|
+
var arrow5 = __toESM(require("apache-arrow"), 1);
|
|
1392
|
+
var ArrowTableBatchAggregator = class extends ColumnarTableBatchAggregator {
|
|
1393
|
+
arrowSchema;
|
|
1394
|
+
constructor(schema, options) {
|
|
1395
|
+
super(schema, options);
|
|
1396
|
+
this.arrowSchema = null;
|
|
1397
|
+
}
|
|
1398
|
+
getBatch() {
|
|
1399
|
+
const batch = super.getBatch();
|
|
1400
|
+
if (batch) {
|
|
1401
|
+
this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
|
|
1402
|
+
const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
|
|
1403
|
+
const recordBatch = new arrow5.RecordBatch(this.arrowSchema, arrow5.makeData({
|
|
1404
|
+
type: new arrow5.Struct(this.arrowSchema.fields),
|
|
1405
|
+
children: arrowVectors.map(({ data }) => data[0])
|
|
1406
|
+
}));
|
|
1407
|
+
return {
|
|
1408
|
+
shape: "arrow-table",
|
|
1409
|
+
batchType: "data",
|
|
1410
|
+
data: new arrow5.Table([recordBatch]),
|
|
1411
|
+
length: batch.length
|
|
1412
|
+
};
|
|
1413
|
+
}
|
|
1414
|
+
return null;
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
function getArrowSchema(schema) {
|
|
1418
|
+
const arrowFields = [];
|
|
1419
|
+
for (const key in schema) {
|
|
1420
|
+
const field = schema[key];
|
|
1421
|
+
if (field.type === Float32Array) {
|
|
1422
|
+
const metadata = /* @__PURE__ */ new Map();
|
|
1423
|
+
const arrowField = new arrow5.Field(field.name, new arrow5.Float32(), field.nullable, metadata);
|
|
1424
|
+
arrowFields.push(arrowField);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
if (arrowFields.length === 0) {
|
|
1428
|
+
throw new Error("No arrow convertible fields");
|
|
1429
|
+
}
|
|
1430
|
+
return new arrow5.Schema(arrowFields);
|
|
1431
|
+
}
|
|
1432
|
+
function getArrowVectors(arrowSchema, data) {
|
|
1433
|
+
const arrowVectors = [];
|
|
1434
|
+
for (const field of arrowSchema.fields) {
|
|
1435
|
+
const vector = data[field.name];
|
|
1436
|
+
if (vector instanceof Float32Array) {
|
|
1437
|
+
const arrowVector = arrow5.makeVector(vector);
|
|
1438
|
+
arrowVectors.push(arrowVector);
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
if (arrowSchema.fields.length !== arrowVectors.length) {
|
|
1442
|
+
throw new Error("Some columns not arrow convertible");
|
|
1443
|
+
}
|
|
1444
|
+
return arrowVectors;
|
|
1445
|
+
}
|
|
1446
|
+
|
|
1447
|
+
// dist/lib/table/batch-builder/table-batch-builder.js
|
|
1448
|
+
var DEFAULT_OPTIONS = {
|
|
1449
|
+
shape: void 0,
|
|
1450
|
+
batchSize: "auto",
|
|
1451
|
+
batchDebounceMs: 0,
|
|
1452
|
+
limit: 0,
|
|
1453
|
+
_limitMB: 0
|
|
1454
|
+
};
|
|
1455
|
+
var TableBatchBuilder = class {
|
|
1456
|
+
schema;
|
|
1457
|
+
options;
|
|
1458
|
+
aggregator = null;
|
|
1459
|
+
batchCount = 0;
|
|
1460
|
+
bytesUsed = 0;
|
|
1461
|
+
isChunkComplete = false;
|
|
1462
|
+
lastBatchEmittedMs = Date.now();
|
|
1463
|
+
totalLength = 0;
|
|
1464
|
+
totalBytes = 0;
|
|
1465
|
+
rowBytes = 0;
|
|
1466
|
+
constructor(schema, options) {
|
|
1467
|
+
this.schema = schema;
|
|
1468
|
+
this.options = { ...DEFAULT_OPTIONS, ...options };
|
|
1469
|
+
}
|
|
1470
|
+
limitReached() {
|
|
1471
|
+
var _a, _b;
|
|
1472
|
+
if (Boolean((_a = this.options) == null ? void 0 : _a.limit) && this.totalLength >= this.options.limit) {
|
|
1473
|
+
return true;
|
|
1474
|
+
}
|
|
1475
|
+
if (Boolean((_b = this.options) == null ? void 0 : _b._limitMB) && this.totalBytes / 1e6 >= this.options._limitMB) {
|
|
1476
|
+
return true;
|
|
1477
|
+
}
|
|
1478
|
+
return false;
|
|
1479
|
+
}
|
|
1480
|
+
/** @deprecated Use addArrayRow or addObjectRow */
|
|
1481
|
+
addRow(row) {
|
|
1482
|
+
if (this.limitReached()) {
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
this.totalLength++;
|
|
1486
|
+
this.rowBytes = this.rowBytes || this._estimateRowMB(row);
|
|
1487
|
+
this.totalBytes += this.rowBytes;
|
|
1488
|
+
if (Array.isArray(row)) {
|
|
1489
|
+
this.addArrayRow(row);
|
|
1490
|
+
} else {
|
|
1491
|
+
this.addObjectRow(row);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
/** Add one row to the batch */
|
|
1495
|
+
addArrayRow(row) {
|
|
1496
|
+
if (!this.aggregator) {
|
|
1497
|
+
const TableBatchType = this._getTableBatchType();
|
|
1498
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
1499
|
+
}
|
|
1500
|
+
this.aggregator.addArrayRow(row);
|
|
1501
|
+
}
|
|
1502
|
+
/** Add one row to the batch */
|
|
1503
|
+
addObjectRow(row) {
|
|
1504
|
+
if (!this.aggregator) {
|
|
1505
|
+
const TableBatchType = this._getTableBatchType();
|
|
1506
|
+
this.aggregator = new TableBatchType(this.schema, this.options);
|
|
1507
|
+
}
|
|
1508
|
+
this.aggregator.addObjectRow(row);
|
|
1509
|
+
}
|
|
1510
|
+
/** Mark an incoming raw memory chunk has completed */
|
|
1511
|
+
chunkComplete(chunk) {
|
|
1512
|
+
if (chunk instanceof ArrayBuffer) {
|
|
1513
|
+
this.bytesUsed += chunk.byteLength;
|
|
1514
|
+
}
|
|
1515
|
+
if (typeof chunk === "string") {
|
|
1516
|
+
this.bytesUsed += chunk.length;
|
|
1517
|
+
}
|
|
1518
|
+
this.isChunkComplete = true;
|
|
1519
|
+
}
|
|
1520
|
+
getFullBatch(options) {
|
|
1521
|
+
return this._isFull() ? this._getBatch(options) : null;
|
|
1522
|
+
}
|
|
1523
|
+
getFinalBatch(options) {
|
|
1524
|
+
return this._getBatch(options);
|
|
1525
|
+
}
|
|
1526
|
+
// INTERNAL
|
|
1527
|
+
_estimateRowMB(row) {
|
|
1528
|
+
return Array.isArray(row) ? row.length * 8 : Object.keys(row).length * 8;
|
|
1529
|
+
}
|
|
1530
|
+
_isFull() {
|
|
1531
|
+
if (!this.aggregator || this.aggregator.rowCount() === 0) {
|
|
1532
|
+
return false;
|
|
1533
|
+
}
|
|
1534
|
+
if (this.options.batchSize === "auto") {
|
|
1535
|
+
if (!this.isChunkComplete) {
|
|
1536
|
+
return false;
|
|
1537
|
+
}
|
|
1538
|
+
} else if (this.options.batchSize > this.aggregator.rowCount()) {
|
|
1539
|
+
return false;
|
|
1540
|
+
}
|
|
1541
|
+
if (this.options.batchDebounceMs > Date.now() - this.lastBatchEmittedMs) {
|
|
1542
|
+
return false;
|
|
1543
|
+
}
|
|
1544
|
+
this.isChunkComplete = false;
|
|
1545
|
+
this.lastBatchEmittedMs = Date.now();
|
|
1546
|
+
return true;
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* bytesUsed can be set via chunkComplete or via getBatch*
|
|
1550
|
+
*/
|
|
1551
|
+
_getBatch(options) {
|
|
1552
|
+
if (!this.aggregator) {
|
|
1553
|
+
return null;
|
|
1554
|
+
}
|
|
1555
|
+
if (options == null ? void 0 : options.bytesUsed) {
|
|
1556
|
+
this.bytesUsed = options.bytesUsed;
|
|
1557
|
+
}
|
|
1558
|
+
const normalizedBatch = this.aggregator.getBatch();
|
|
1559
|
+
normalizedBatch.count = this.batchCount;
|
|
1560
|
+
normalizedBatch.bytesUsed = this.bytesUsed;
|
|
1561
|
+
Object.assign(normalizedBatch, options);
|
|
1562
|
+
this.batchCount++;
|
|
1563
|
+
this.aggregator = null;
|
|
1564
|
+
return normalizedBatch;
|
|
1565
|
+
}
|
|
1566
|
+
_getTableBatchType() {
|
|
1567
|
+
switch (this.options.shape) {
|
|
1568
|
+
case "array-row-table":
|
|
1569
|
+
case "object-row-table":
|
|
1570
|
+
return RowTableBatchAggregator;
|
|
1571
|
+
case "columnar-table":
|
|
1572
|
+
return ColumnarTableBatchAggregator;
|
|
1573
|
+
case "arrow-table":
|
|
1574
|
+
return ArrowTableBatchAggregator;
|
|
1575
|
+
default:
|
|
1576
|
+
return BaseTableBatchAggregator;
|
|
1577
|
+
}
|
|
1578
|
+
}
|
|
1579
|
+
};
|
|
1580
|
+
__publicField(TableBatchBuilder, "ArrowBatch");
|
|
1581
|
+
|
|
1582
|
+
// dist/lib/table/arrow-api/arrow-like-field.js
|
|
1583
|
+
var ArrowLikeField = class {
|
|
1584
|
+
name;
|
|
1585
|
+
type;
|
|
1586
|
+
nullable;
|
|
1587
|
+
metadata;
|
|
1588
|
+
constructor(name, type, nullable = false, metadata = /* @__PURE__ */ new Map()) {
|
|
1589
|
+
this.name = name;
|
|
1590
|
+
this.type = type;
|
|
1591
|
+
this.nullable = nullable;
|
|
1592
|
+
this.metadata = metadata;
|
|
1593
|
+
}
|
|
1594
|
+
get typeId() {
|
|
1595
|
+
return this.type && this.type.typeId;
|
|
1596
|
+
}
|
|
1597
|
+
clone() {
|
|
1598
|
+
return new ArrowLikeField(this.name, this.type, this.nullable, this.metadata);
|
|
1599
|
+
}
|
|
1600
|
+
compareTo(other) {
|
|
1601
|
+
return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
|
|
1602
|
+
}
|
|
1603
|
+
toString() {
|
|
1604
|
+
return `${JSON.stringify(this.type)}${this.nullable ? ", nullable" : ""}${this.metadata ? `, metadata: ${JSON.stringify(this.metadata)}` : ""}`;
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
|
|
1608
|
+
// dist/lib/table/arrow-api/arrow-like-schema.js
|
|
1609
|
+
var ArrowLikeSchema = class {
|
|
1610
|
+
fields;
|
|
1611
|
+
metadata;
|
|
1612
|
+
constructor(fields, metadata = /* @__PURE__ */ new Map()) {
|
|
1613
|
+
this.fields = fields.map((field) => new ArrowLikeField(field.name, field.type, field.nullable, field.metadata));
|
|
1614
|
+
this.metadata = metadata instanceof Map ? metadata : new Map(Object.entries(metadata));
|
|
1615
|
+
}
|
|
1616
|
+
// TODO - arrow only seems to compare fields, not metadata
|
|
1617
|
+
compareTo(other) {
|
|
1618
|
+
if (this.metadata !== other.metadata) {
|
|
1619
|
+
return false;
|
|
1620
|
+
}
|
|
1621
|
+
if (this.fields.length !== other.fields.length) {
|
|
1622
|
+
return false;
|
|
1623
|
+
}
|
|
1624
|
+
for (let i = 0; i < this.fields.length; ++i) {
|
|
1625
|
+
if (!this.fields[i].compareTo(other.fields[i])) {
|
|
1626
|
+
return false;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
return true;
|
|
1630
|
+
}
|
|
1631
|
+
select(...columnNames) {
|
|
1632
|
+
const nameMap = /* @__PURE__ */ Object.create(null);
|
|
1633
|
+
for (const name of columnNames) {
|
|
1634
|
+
nameMap[name] = true;
|
|
1635
|
+
}
|
|
1636
|
+
const selectedFields = this.fields.filter((field) => nameMap[field.name]);
|
|
1637
|
+
return new ArrowLikeSchema(selectedFields, this.metadata);
|
|
1638
|
+
}
|
|
1639
|
+
selectAt(...columnIndices) {
|
|
1640
|
+
const selectedFields = columnIndices.map((index) => this.fields[index]).filter(Boolean);
|
|
1641
|
+
return new ArrowLikeSchema(selectedFields, this.metadata);
|
|
1642
|
+
}
|
|
1643
|
+
assign(schemaOrFields) {
|
|
1644
|
+
let fields;
|
|
1645
|
+
let metadata = this.metadata;
|
|
1646
|
+
if (schemaOrFields instanceof ArrowLikeSchema) {
|
|
1647
|
+
const otherArrowLikeSchema = schemaOrFields;
|
|
1648
|
+
fields = otherArrowLikeSchema.fields;
|
|
1649
|
+
metadata = mergeMaps(mergeMaps(/* @__PURE__ */ new Map(), this.metadata), otherArrowLikeSchema.metadata);
|
|
1650
|
+
} else {
|
|
1651
|
+
fields = schemaOrFields;
|
|
1652
|
+
}
|
|
1653
|
+
const fieldMap = /* @__PURE__ */ Object.create(null);
|
|
1654
|
+
for (const field of this.fields) {
|
|
1655
|
+
fieldMap[field.name] = field;
|
|
1656
|
+
}
|
|
1657
|
+
for (const field of fields) {
|
|
1658
|
+
fieldMap[field.name] = field;
|
|
1659
|
+
}
|
|
1660
|
+
const mergedFields = Object.values(fieldMap);
|
|
1661
|
+
return new ArrowLikeSchema(mergedFields, metadata);
|
|
1662
|
+
}
|
|
1663
|
+
};
|
|
1664
|
+
function mergeMaps(m1, m2) {
|
|
1665
|
+
return new Map([...m1 || /* @__PURE__ */ new Map(), ...m2 || /* @__PURE__ */ new Map()]);
|
|
1666
|
+
}
|
|
1667
|
+
|
|
1668
|
+
// dist/lib/table/arrow-api/arrow-like-table.js
|
|
1669
|
+
var ArrowLikeVector = class {
|
|
1670
|
+
table;
|
|
1671
|
+
columnName;
|
|
1672
|
+
constructor(table, columnName) {
|
|
1673
|
+
this.table = table;
|
|
1674
|
+
this.columnName = columnName;
|
|
1675
|
+
}
|
|
1676
|
+
get(rowIndex) {
|
|
1677
|
+
return getTableCell(this.table, rowIndex, this.columnName);
|
|
1678
|
+
}
|
|
1679
|
+
toArray() {
|
|
1680
|
+
var _a;
|
|
1681
|
+
switch (this.table.shape) {
|
|
1682
|
+
case "arrow-table":
|
|
1683
|
+
const arrowTable = this.table.data;
|
|
1684
|
+
return (_a = arrowTable.getChild(this.columnName)) == null ? void 0 : _a.toArray();
|
|
1685
|
+
case "columnar-table":
|
|
1686
|
+
return this.table.data[this.columnName];
|
|
1687
|
+
default:
|
|
1688
|
+
throw new Error(this.table.shape);
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
};
|
|
1692
|
+
var ArrowLikeTable = class {
|
|
1693
|
+
schema;
|
|
1694
|
+
table;
|
|
1695
|
+
constructor(table) {
|
|
1696
|
+
const schema = table.schema || deduceTableSchema(table);
|
|
1697
|
+
this.schema = new ArrowLikeSchema(schema.fields, schema.metadata);
|
|
1698
|
+
this.table = { ...table, schema };
|
|
1699
|
+
}
|
|
1700
|
+
// get schema() {
|
|
1701
|
+
// return this.table.schema;
|
|
1702
|
+
// }
|
|
1703
|
+
get data() {
|
|
1704
|
+
return this.table.shape === "geojson-table" ? this.table.features : this.table.data;
|
|
1705
|
+
}
|
|
1706
|
+
get numCols() {
|
|
1707
|
+
return getTableNumCols(this.table);
|
|
1708
|
+
}
|
|
1709
|
+
get length() {
|
|
1710
|
+
return getTableLength(this.table);
|
|
1711
|
+
}
|
|
1712
|
+
getChild(columnName) {
|
|
1713
|
+
return new ArrowLikeVector(this.table, columnName);
|
|
1714
|
+
}
|
|
1715
|
+
};
|
|
1716
|
+
|
|
1717
|
+
// dist/lib/mesh/mesh-utils.js
|
|
1718
|
+
function getMeshSize(attributes) {
|
|
1719
|
+
let size = 0;
|
|
1720
|
+
for (const attributeName in attributes) {
|
|
1721
|
+
const attribute = attributes[attributeName];
|
|
1722
|
+
if (ArrayBuffer.isView(attribute)) {
|
|
1723
|
+
size += attribute.byteLength * attribute.BYTES_PER_ELEMENT;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
return size;
|
|
1727
|
+
}
|
|
1728
|
+
function getMeshBoundingBox(attributes) {
|
|
1729
|
+
let minX = Infinity;
|
|
1730
|
+
let minY = Infinity;
|
|
1731
|
+
let minZ = Infinity;
|
|
1732
|
+
let maxX = -Infinity;
|
|
1733
|
+
let maxY = -Infinity;
|
|
1734
|
+
let maxZ = -Infinity;
|
|
1735
|
+
const positions = attributes.POSITION ? attributes.POSITION.value : [];
|
|
1736
|
+
const len = positions && positions.length;
|
|
1737
|
+
for (let i = 0; i < len; i += 3) {
|
|
1738
|
+
const x = positions[i];
|
|
1739
|
+
const y = positions[i + 1];
|
|
1740
|
+
const z = positions[i + 2];
|
|
1741
|
+
minX = x < minX ? x : minX;
|
|
1742
|
+
minY = y < minY ? y : minY;
|
|
1743
|
+
minZ = z < minZ ? z : minZ;
|
|
1744
|
+
maxX = x > maxX ? x : maxX;
|
|
1745
|
+
maxY = y > maxY ? y : maxY;
|
|
1746
|
+
maxZ = z > maxZ ? z : maxZ;
|
|
1747
|
+
}
|
|
1748
|
+
return [
|
|
1749
|
+
[minX, minY, minZ],
|
|
1750
|
+
[maxX, maxY, maxZ]
|
|
1751
|
+
];
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
// dist/lib/mesh/convert-mesh-to-table.js
|
|
1755
|
+
var arrow7 = __toESM(require("apache-arrow"), 1);
|
|
1756
|
+
|
|
1757
|
+
// dist/lib/arrow-utils/arrow-fixed-size-list-utils.js
|
|
1758
|
+
var arrow6 = __toESM(require("apache-arrow"), 1);
|
|
1759
|
+
function getFixedSizeListSize(vector) {
|
|
1760
|
+
return vector.type instanceof arrow6.FixedSizeList ? vector.type.listSize : 1;
|
|
1761
|
+
}
|
|
1762
|
+
function getFixedSizeListData(typedArray, stride) {
|
|
1763
|
+
const listType = getFixedSizeListType(typedArray, stride);
|
|
1764
|
+
const nestedType = listType.children[0].type;
|
|
1765
|
+
const buffers = {
|
|
1766
|
+
// valueOffsets: undefined,
|
|
1767
|
+
[arrow6.BufferType.DATA]: typedArray
|
|
1768
|
+
// values
|
|
1769
|
+
// nullBitmap: undefined,
|
|
1770
|
+
// typeIds: undefined
|
|
1771
|
+
};
|
|
1772
|
+
const nestedData = new arrow6.Data(nestedType, 0, typedArray.length, 0, buffers);
|
|
1773
|
+
const data = new arrow6.Data(listType, 0, typedArray.length / stride, 0, void 0, [nestedData]);
|
|
1774
|
+
return data;
|
|
1775
|
+
}
|
|
1776
|
+
function getFixedSizeListType(typedArray, stride) {
|
|
1777
|
+
const { type } = getDataTypeFromArray(typedArray);
|
|
1778
|
+
const arrowType = deserializeArrowType(type);
|
|
1779
|
+
const listType = new arrow6.FixedSizeList(stride, new arrow6.Field("value", arrowType));
|
|
1780
|
+
return listType;
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1783
|
+
// dist/lib/mesh/convert-mesh-to-table.js
|
|
1784
|
+
function convertMeshToTable(mesh, shape) {
|
|
1785
|
+
switch (shape) {
|
|
1786
|
+
case "columnar-table":
|
|
1787
|
+
return convertMeshToColumnarTable(mesh);
|
|
1788
|
+
case "arrow-table":
|
|
1789
|
+
return convertMeshToArrowTable(mesh);
|
|
1790
|
+
default:
|
|
1791
|
+
throw new Error(shape);
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
function convertMeshToColumnarTable(mesh) {
|
|
1795
|
+
const columns = {};
|
|
1796
|
+
for (const [columnName, attribute] of Object.entries(mesh.attributes)) {
|
|
1797
|
+
columns[columnName] = attribute.value;
|
|
1798
|
+
}
|
|
1799
|
+
return {
|
|
1800
|
+
shape: "columnar-table",
|
|
1801
|
+
schema: mesh.schema,
|
|
1802
|
+
data: columns
|
|
1803
|
+
};
|
|
1804
|
+
}
|
|
1805
|
+
function convertMeshToArrowTable(mesh, batchSize) {
|
|
1806
|
+
const { schema } = mesh;
|
|
1807
|
+
const arrowSchema = deserializeArrowSchema(schema);
|
|
1808
|
+
const arrowDatas = [];
|
|
1809
|
+
for (const attributeKey in mesh.attributes) {
|
|
1810
|
+
const attribute = mesh.attributes[attributeKey];
|
|
1811
|
+
const { value, size = 1 } = attribute;
|
|
1812
|
+
const listData = getFixedSizeListData(value, size);
|
|
1813
|
+
arrowDatas.push(listData);
|
|
1814
|
+
}
|
|
1815
|
+
const structField = new arrow7.Struct(arrowSchema.fields);
|
|
1816
|
+
const length = arrowDatas[0].length;
|
|
1817
|
+
const structData = new arrow7.Data(structField, 0, length, 0, void 0, arrowDatas);
|
|
1818
|
+
const recordBatch = new arrow7.RecordBatch(arrowSchema, structData);
|
|
1819
|
+
const table = new arrow7.Table([recordBatch]);
|
|
1820
|
+
return { shape: "arrow-table", schema, data: table };
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
// dist/lib/mesh/convert-table-to-mesh.js
|
|
1824
|
+
function convertTableToMesh(table) {
|
|
1825
|
+
switch (table.shape) {
|
|
1826
|
+
case "arrow-table":
|
|
1827
|
+
return convertArrowTableToMesh(table);
|
|
1828
|
+
default:
|
|
1829
|
+
throw new Error(table.shape);
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
function convertArrowTableToMesh(table) {
|
|
1833
|
+
const arrowTable = table.data;
|
|
1834
|
+
const schema = serializeArrowSchema(arrowTable.schema);
|
|
1835
|
+
const fields = schema.fields;
|
|
1836
|
+
const attributes = {};
|
|
1837
|
+
for (const field of fields) {
|
|
1838
|
+
const { name } = field;
|
|
1839
|
+
const attributeData = arrowTable.getChild(name);
|
|
1840
|
+
const size = getFixedSizeListSize(attributeData);
|
|
1841
|
+
const typedArray = attributeData == null ? void 0 : attributeData.toArray();
|
|
1842
|
+
attributes[name] = { value: typedArray, size };
|
|
1843
|
+
}
|
|
1844
|
+
fixMetadata(schema);
|
|
1845
|
+
const topology = schema.metadata.topology;
|
|
1846
|
+
return { schema, attributes, topology, mode: 0 };
|
|
1847
|
+
}
|
|
1848
|
+
function fixMetadata(schema) {
|
|
1849
|
+
schema.metadata ||= {};
|
|
1850
|
+
schema.metadata.topology ||= "point-list";
|
|
1851
|
+
schema.metadata.mode ||= "0";
|
|
1852
|
+
}
|
|
1853
|
+
|
|
1854
|
+
// dist/lib/mesh/deduce-mesh-schema.js
|
|
1855
|
+
function deduceMeshSchema(attributes, metadata = {}) {
|
|
1856
|
+
const fields = deduceMeshFields(attributes);
|
|
1857
|
+
return { fields, metadata };
|
|
1858
|
+
}
|
|
1859
|
+
function deduceMeshField(name, attribute, optionalMetadata) {
|
|
1860
|
+
const type = getDataTypeFromTypedArray(attribute.value);
|
|
1861
|
+
const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
|
|
1862
|
+
return {
|
|
1863
|
+
name,
|
|
1864
|
+
type: { type: "fixed-size-list", listSize: attribute.size, children: [{ name: "value", type }] },
|
|
1865
|
+
nullable: false,
|
|
1866
|
+
metadata
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
function deduceMeshFields(attributes) {
|
|
1870
|
+
const fields = [];
|
|
1871
|
+
for (const attributeName in attributes) {
|
|
1872
|
+
const attribute = attributes[attributeName];
|
|
1873
|
+
fields.push(deduceMeshField(attributeName, attribute));
|
|
1874
|
+
}
|
|
1875
|
+
return fields;
|
|
1876
|
+
}
|
|
1877
|
+
function makeMeshAttributeMetadata(attribute) {
|
|
1878
|
+
const result = {};
|
|
1879
|
+
if ("byteOffset" in attribute) {
|
|
1880
|
+
result.byteOffset = attribute.byteOffset.toString(10);
|
|
1881
|
+
}
|
|
1882
|
+
if ("byteStride" in attribute) {
|
|
1883
|
+
result.byteStride = attribute.byteStride.toString(10);
|
|
1884
|
+
}
|
|
1885
|
+
if ("normalized" in attribute) {
|
|
1886
|
+
result.normalized = attribute.normalized.toString();
|
|
1887
|
+
}
|
|
1888
|
+
return result;
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
// dist/lib/table/arrow-api/enum.js
|
|
1892
|
+
var Type;
|
|
1893
|
+
(function(Type2) {
|
|
1894
|
+
Type2[Type2["NONE"] = 0] = "NONE";
|
|
1895
|
+
Type2[Type2["Null"] = 1] = "Null";
|
|
1896
|
+
Type2[Type2["Int"] = 2] = "Int";
|
|
1897
|
+
Type2[Type2["Float"] = 3] = "Float";
|
|
1898
|
+
Type2[Type2["Binary"] = 4] = "Binary";
|
|
1899
|
+
Type2[Type2["Utf8"] = 5] = "Utf8";
|
|
1900
|
+
Type2[Type2["Bool"] = 6] = "Bool";
|
|
1901
|
+
Type2[Type2["Decimal"] = 7] = "Decimal";
|
|
1902
|
+
Type2[Type2["Date"] = 8] = "Date";
|
|
1903
|
+
Type2[Type2["Time"] = 9] = "Time";
|
|
1904
|
+
Type2[Type2["Timestamp"] = 10] = "Timestamp";
|
|
1905
|
+
Type2[Type2["Interval"] = 11] = "Interval";
|
|
1906
|
+
Type2[Type2["List"] = 12] = "List";
|
|
1907
|
+
Type2[Type2["Struct"] = 13] = "Struct";
|
|
1908
|
+
Type2[Type2["Union"] = 14] = "Union";
|
|
1909
|
+
Type2[Type2["FixedSizeBinary"] = 15] = "FixedSizeBinary";
|
|
1910
|
+
Type2[Type2["FixedSizeList"] = 16] = "FixedSizeList";
|
|
1911
|
+
Type2[Type2["Map"] = 17] = "Map";
|
|
1912
|
+
Type2[Type2["Dictionary"] = -1] = "Dictionary";
|
|
1913
|
+
Type2[Type2["Int8"] = -2] = "Int8";
|
|
1914
|
+
Type2[Type2["Int16"] = -3] = "Int16";
|
|
1915
|
+
Type2[Type2["Int32"] = -4] = "Int32";
|
|
1916
|
+
Type2[Type2["Int64"] = -5] = "Int64";
|
|
1917
|
+
Type2[Type2["Uint8"] = -6] = "Uint8";
|
|
1918
|
+
Type2[Type2["Uint16"] = -7] = "Uint16";
|
|
1919
|
+
Type2[Type2["Uint32"] = -8] = "Uint32";
|
|
1920
|
+
Type2[Type2["Uint64"] = -9] = "Uint64";
|
|
1921
|
+
Type2[Type2["Float16"] = -10] = "Float16";
|
|
1922
|
+
Type2[Type2["Float32"] = -11] = "Float32";
|
|
1923
|
+
Type2[Type2["Float64"] = -12] = "Float64";
|
|
1924
|
+
Type2[Type2["DateDay"] = -13] = "DateDay";
|
|
1925
|
+
Type2[Type2["DateMillisecond"] = -14] = "DateMillisecond";
|
|
1926
|
+
Type2[Type2["TimestampSecond"] = -15] = "TimestampSecond";
|
|
1927
|
+
Type2[Type2["TimestampMillisecond"] = -16] = "TimestampMillisecond";
|
|
1928
|
+
Type2[Type2["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
|
|
1929
|
+
Type2[Type2["TimestampNanosecond"] = -18] = "TimestampNanosecond";
|
|
1930
|
+
Type2[Type2["TimeSecond"] = -19] = "TimeSecond";
|
|
1931
|
+
Type2[Type2["TimeMillisecond"] = -20] = "TimeMillisecond";
|
|
1932
|
+
Type2[Type2["TimeMicrosecond"] = -21] = "TimeMicrosecond";
|
|
1933
|
+
Type2[Type2["TimeNanosecond"] = -22] = "TimeNanosecond";
|
|
1934
|
+
Type2[Type2["DenseUnion"] = -23] = "DenseUnion";
|
|
1935
|
+
Type2[Type2["SparseUnion"] = -24] = "SparseUnion";
|
|
1936
|
+
Type2[Type2["IntervalDayTime"] = -25] = "IntervalDayTime";
|
|
1937
|
+
Type2[Type2["IntervalYearMonth"] = -26] = "IntervalYearMonth";
|
|
1938
|
+
})(Type || (Type = {}));
|
|
1939
|
+
|
|
1940
|
+
// dist/lib/table/arrow-api/arrow-like-type.js
|
|
1941
|
+
var DataType = class {
|
|
1942
|
+
static isNull(x) {
|
|
1943
|
+
return x && x.typeId === Type.Null;
|
|
1944
|
+
}
|
|
1945
|
+
static isInt(x) {
|
|
1946
|
+
return x && x.typeId === Type.Int;
|
|
1947
|
+
}
|
|
1948
|
+
static isFloat(x) {
|
|
1949
|
+
return x && x.typeId === Type.Float;
|
|
1950
|
+
}
|
|
1951
|
+
static isBinary(x) {
|
|
1952
|
+
return x && x.typeId === Type.Binary;
|
|
1953
|
+
}
|
|
1954
|
+
static isUtf8(x) {
|
|
1955
|
+
return x && x.typeId === Type.Utf8;
|
|
1956
|
+
}
|
|
1957
|
+
static isBool(x) {
|
|
1958
|
+
return x && x.typeId === Type.Bool;
|
|
1959
|
+
}
|
|
1960
|
+
static isDecimal(x) {
|
|
1961
|
+
return x && x.typeId === Type.Decimal;
|
|
1962
|
+
}
|
|
1963
|
+
static isDate(x) {
|
|
1964
|
+
return x && x.typeId === Type.Date;
|
|
1965
|
+
}
|
|
1966
|
+
static isTime(x) {
|
|
1967
|
+
return x && x.typeId === Type.Time;
|
|
1968
|
+
}
|
|
1969
|
+
static isTimestamp(x) {
|
|
1970
|
+
return x && x.typeId === Type.Timestamp;
|
|
1971
|
+
}
|
|
1972
|
+
static isInterval(x) {
|
|
1973
|
+
return x && x.typeId === Type.Interval;
|
|
1974
|
+
}
|
|
1975
|
+
static isList(x) {
|
|
1976
|
+
return x && x.typeId === Type.List;
|
|
1977
|
+
}
|
|
1978
|
+
static isStruct(x) {
|
|
1979
|
+
return x && x.typeId === Type.Struct;
|
|
1980
|
+
}
|
|
1981
|
+
static isUnion(x) {
|
|
1982
|
+
return x && x.typeId === Type.Union;
|
|
1983
|
+
}
|
|
1984
|
+
static isFixedSizeBinary(x) {
|
|
1985
|
+
return x && x.typeId === Type.FixedSizeBinary;
|
|
1986
|
+
}
|
|
1987
|
+
static isFixedSizeList(x) {
|
|
1988
|
+
return x && x.typeId === Type.FixedSizeList;
|
|
1989
|
+
}
|
|
1990
|
+
static isMap(x) {
|
|
1991
|
+
return x && x.typeId === Type.Map;
|
|
1992
|
+
}
|
|
1993
|
+
static isDictionary(x) {
|
|
1994
|
+
return x && x.typeId === Type.Dictionary;
|
|
1995
|
+
}
|
|
1996
|
+
get typeId() {
|
|
1997
|
+
return Type.NONE;
|
|
1998
|
+
}
|
|
1999
|
+
// get ArrayType(): AnyArrayType {
|
|
2000
|
+
// return Int8Array;
|
|
2001
|
+
// }
|
|
2002
|
+
// get ArrayType() { return Array; }
|
|
2003
|
+
compareTo(other) {
|
|
2004
|
+
return this === other;
|
|
2005
|
+
}
|
|
2006
|
+
};
|
|
2007
|
+
var Null2 = class extends DataType {
|
|
2008
|
+
get typeId() {
|
|
2009
|
+
return Type.Null;
|
|
2010
|
+
}
|
|
2011
|
+
get [Symbol.toStringTag]() {
|
|
2012
|
+
return "Null";
|
|
2013
|
+
}
|
|
2014
|
+
toString() {
|
|
2015
|
+
return "Null";
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
var Bool2 = class extends DataType {
|
|
2019
|
+
get typeId() {
|
|
2020
|
+
return Type.Bool;
|
|
2021
|
+
}
|
|
2022
|
+
// get ArrayType() {
|
|
2023
|
+
// return Uint8Array;
|
|
2024
|
+
// }
|
|
2025
|
+
get [Symbol.toStringTag]() {
|
|
2026
|
+
return "Bool";
|
|
2027
|
+
}
|
|
2028
|
+
toString() {
|
|
2029
|
+
return "Bool";
|
|
2030
|
+
}
|
|
2031
|
+
};
|
|
2032
|
+
var Int2 = class extends DataType {
|
|
2033
|
+
isSigned;
|
|
2034
|
+
bitWidth;
|
|
2035
|
+
constructor(isSigned, bitWidth) {
|
|
2036
|
+
super();
|
|
2037
|
+
this.isSigned = isSigned;
|
|
2038
|
+
this.bitWidth = bitWidth;
|
|
2039
|
+
}
|
|
2040
|
+
get typeId() {
|
|
2041
|
+
return Type.Int;
|
|
2042
|
+
}
|
|
2043
|
+
// get ArrayType() {
|
|
2044
|
+
// switch (this.bitWidth) {
|
|
2045
|
+
// case 8:
|
|
2046
|
+
// return this.isSigned ? Int8Array : Uint8Array;
|
|
2047
|
+
// case 16:
|
|
2048
|
+
// return this.isSigned ? Int16Array : Uint16Array;
|
|
2049
|
+
// case 32:
|
|
2050
|
+
// return this.isSigned ? Int32Array : Uint32Array;
|
|
2051
|
+
// case 64:
|
|
2052
|
+
// return this.isSigned ? Int32Array : Uint32Array;
|
|
2053
|
+
// default:
|
|
2054
|
+
// throw new Error(`Unrecognized ${this[Symbol.toStringTag]} type`);
|
|
2055
|
+
// }
|
|
2056
|
+
// }
|
|
2057
|
+
get [Symbol.toStringTag]() {
|
|
2058
|
+
return "Int";
|
|
2059
|
+
}
|
|
2060
|
+
toString() {
|
|
2061
|
+
return `${this.isSigned ? "I" : "Ui"}nt${this.bitWidth}`;
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
var Float2 = class extends DataType {
|
|
2065
|
+
precision;
|
|
2066
|
+
constructor(precision) {
|
|
2067
|
+
super();
|
|
2068
|
+
this.precision = precision;
|
|
2069
|
+
}
|
|
2070
|
+
get typeId() {
|
|
2071
|
+
return Type.Float;
|
|
2072
|
+
}
|
|
2073
|
+
// get ArrayType() {
|
|
2074
|
+
// switch (this.precision) {
|
|
2075
|
+
// case Precision.HALF:
|
|
2076
|
+
// return Uint16Array;
|
|
2077
|
+
// case Precision.SINGLE:
|
|
2078
|
+
// return Float32Array;
|
|
2079
|
+
// case Precision.DOUBLE:
|
|
2080
|
+
// return Float64Array;
|
|
2081
|
+
// default:
|
|
2082
|
+
// throw new Error(`Unrecognized ${this[Symbol.toStringTag]} type`);
|
|
2083
|
+
// }
|
|
2084
|
+
// }
|
|
2085
|
+
get [Symbol.toStringTag]() {
|
|
2086
|
+
return "Float";
|
|
2087
|
+
}
|
|
2088
|
+
toString() {
|
|
2089
|
+
return `Float${this.precision}`;
|
|
2090
|
+
}
|
|
2091
|
+
};
|
|
2092
|
+
var Binary2 = class extends DataType {
|
|
2093
|
+
constructor() {
|
|
2094
|
+
super();
|
|
2095
|
+
}
|
|
2096
|
+
get typeId() {
|
|
2097
|
+
return Type.Binary;
|
|
2098
|
+
}
|
|
2099
|
+
toString() {
|
|
2100
|
+
return "Binary";
|
|
2101
|
+
}
|
|
2102
|
+
get [Symbol.toStringTag]() {
|
|
2103
|
+
return "Binary";
|
|
2104
|
+
}
|
|
2105
|
+
};
|
|
2106
|
+
var Utf82 = class extends DataType {
|
|
2107
|
+
get typeId() {
|
|
2108
|
+
return Type.Utf8;
|
|
2109
|
+
}
|
|
2110
|
+
// get ArrayType() {
|
|
2111
|
+
// return Uint8Array;
|
|
2112
|
+
// }
|
|
2113
|
+
get [Symbol.toStringTag]() {
|
|
2114
|
+
return "Utf8";
|
|
2115
|
+
}
|
|
2116
|
+
toString() {
|
|
2117
|
+
return "Utf8";
|
|
2118
|
+
}
|
|
2119
|
+
};
|
|
2120
|
+
var DateUnit2 = {
|
|
2121
|
+
DAY: 0,
|
|
2122
|
+
MILLISECOND: 1
|
|
2123
|
+
};
|
|
2124
|
+
var Date2 = class extends DataType {
|
|
2125
|
+
unit;
|
|
2126
|
+
constructor(unit) {
|
|
2127
|
+
super();
|
|
2128
|
+
this.unit = unit;
|
|
2129
|
+
}
|
|
2130
|
+
get typeId() {
|
|
2131
|
+
return Type.Date;
|
|
2132
|
+
}
|
|
2133
|
+
// get ArrayType() {
|
|
2134
|
+
// return Int32Array;
|
|
2135
|
+
// }
|
|
2136
|
+
get [Symbol.toStringTag]() {
|
|
2137
|
+
return "Date";
|
|
2138
|
+
}
|
|
2139
|
+
toString() {
|
|
2140
|
+
return `Date${(this.unit + 1) * 32}<${DateUnit2[this.unit]}>`;
|
|
2141
|
+
}
|
|
2142
|
+
};
|
|
2143
|
+
var TimeUnit2 = {
|
|
2144
|
+
SECOND: 1,
|
|
2145
|
+
MILLISECOND: 1e3,
|
|
2146
|
+
MICROSECOND: 1e6,
|
|
2147
|
+
NANOSECOND: 1e9
|
|
2148
|
+
};
|
|
2149
|
+
var Time2 = class extends DataType {
|
|
2150
|
+
unit;
|
|
2151
|
+
bitWidth;
|
|
2152
|
+
constructor(unit, bitWidth) {
|
|
2153
|
+
super();
|
|
2154
|
+
this.unit = unit;
|
|
2155
|
+
this.bitWidth = bitWidth;
|
|
2156
|
+
}
|
|
2157
|
+
get typeId() {
|
|
2158
|
+
return Type.Time;
|
|
2159
|
+
}
|
|
2160
|
+
toString() {
|
|
2161
|
+
return `Time${this.bitWidth}<${TimeUnit2[this.unit]}>`;
|
|
2162
|
+
}
|
|
2163
|
+
get [Symbol.toStringTag]() {
|
|
2164
|
+
return "Time";
|
|
2165
|
+
}
|
|
2166
|
+
};
|
|
2167
|
+
var Timestamp2 = class extends DataType {
|
|
2168
|
+
unit;
|
|
2169
|
+
timezone;
|
|
2170
|
+
constructor(unit, timezone = null) {
|
|
2171
|
+
super();
|
|
2172
|
+
this.unit = unit;
|
|
2173
|
+
this.timezone = timezone;
|
|
2174
|
+
}
|
|
2175
|
+
get typeId() {
|
|
2176
|
+
return Type.Timestamp;
|
|
2177
|
+
}
|
|
2178
|
+
// get ArrayType() {
|
|
2179
|
+
// return Int32Array;
|
|
2180
|
+
// }
|
|
2181
|
+
get [Symbol.toStringTag]() {
|
|
2182
|
+
return "Timestamp";
|
|
2183
|
+
}
|
|
2184
|
+
toString() {
|
|
2185
|
+
return `Timestamp<${TimeUnit2[this.unit]}${this.timezone ? `, ${this.timezone}` : ""}>`;
|
|
2186
|
+
}
|
|
2187
|
+
};
|
|
2188
|
+
var IntervalUnit2 = {
|
|
2189
|
+
DAY_TIME: 0,
|
|
2190
|
+
YEAR_MONTH: 1
|
|
2191
|
+
};
|
|
2192
|
+
var Interval2 = class extends DataType {
|
|
2193
|
+
unit;
|
|
2194
|
+
constructor(unit) {
|
|
2195
|
+
super();
|
|
2196
|
+
this.unit = unit;
|
|
2197
|
+
}
|
|
2198
|
+
get typeId() {
|
|
2199
|
+
return Type.Interval;
|
|
2200
|
+
}
|
|
2201
|
+
// get ArrayType() {
|
|
2202
|
+
// return Int32Array;
|
|
2203
|
+
// }
|
|
2204
|
+
get [Symbol.toStringTag]() {
|
|
2205
|
+
return "Interval";
|
|
2206
|
+
}
|
|
2207
|
+
toString() {
|
|
2208
|
+
return `Interval<${IntervalUnit2[this.unit]}>`;
|
|
2209
|
+
}
|
|
2210
|
+
};
|
|
2211
|
+
var FixedSizeList3 = class extends DataType {
|
|
2212
|
+
listSize;
|
|
2213
|
+
children;
|
|
2214
|
+
constructor(listSize, child) {
|
|
2215
|
+
super();
|
|
2216
|
+
this.listSize = listSize;
|
|
2217
|
+
this.children = [child];
|
|
2218
|
+
}
|
|
2219
|
+
get typeId() {
|
|
2220
|
+
return Type.FixedSizeList;
|
|
2221
|
+
}
|
|
2222
|
+
get valueType() {
|
|
2223
|
+
return this.children[0].type;
|
|
2224
|
+
}
|
|
2225
|
+
get valueField() {
|
|
2226
|
+
return this.children[0];
|
|
2227
|
+
}
|
|
2228
|
+
// get ArrayType() {
|
|
2229
|
+
// return this.valueType.ArrayType;
|
|
2230
|
+
// }
|
|
2231
|
+
get [Symbol.toStringTag]() {
|
|
2232
|
+
return "FixedSizeList";
|
|
2233
|
+
}
|
|
2234
|
+
toString() {
|
|
2235
|
+
return `FixedSizeList[${this.listSize}]<${JSON.stringify(this.valueType)}>`;
|
|
2236
|
+
}
|
|
2237
|
+
};
|
|
2238
|
+
var Struct5 = class extends DataType {
|
|
2239
|
+
children;
|
|
2240
|
+
constructor(children) {
|
|
2241
|
+
super();
|
|
2242
|
+
this.children = children;
|
|
2243
|
+
}
|
|
2244
|
+
get typeId() {
|
|
2245
|
+
return Type.Struct;
|
|
2246
|
+
}
|
|
2247
|
+
toString() {
|
|
2248
|
+
return `Struct<{${this.children.map((f) => `${f.name}:${JSON.stringify(f.type)}`).join(", ")}}>`;
|
|
2249
|
+
}
|
|
2250
|
+
get [Symbol.toStringTag]() {
|
|
2251
|
+
return "Struct";
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
|
|
2255
|
+
// dist/lib/table/batch-builder/arrow-table-builder.js
|
|
2256
|
+
var arrow8 = __toESM(require("apache-arrow"), 1);
|
|
2257
|
+
var import_schema_utils = require("@loaders.gl/schema-utils");
|
|
2258
|
+
var ArrowTableBuilder = class {
|
|
2259
|
+
schema;
|
|
2260
|
+
arrowSchema;
|
|
2261
|
+
arrowBuilders;
|
|
2262
|
+
length;
|
|
2263
|
+
constructor(schema) {
|
|
2264
|
+
this.schema = schema;
|
|
2265
|
+
this.arrowSchema = (0, import_schema_utils.convertSchemaToArrow)(schema);
|
|
2266
|
+
this.arrowBuilders = this.arrowSchema.fields.map((field) => arrow8.makeBuilder({ type: field.type, nullValues: [null] }));
|
|
2267
|
+
this.length = 0;
|
|
2268
|
+
}
|
|
2269
|
+
addObjectRow(row) {
|
|
2270
|
+
for (let i = 0; i < this.arrowBuilders.length; i++) {
|
|
2271
|
+
const columnName = this.schema.fields[i].name;
|
|
2272
|
+
const value = row[columnName];
|
|
2273
|
+
this.arrowBuilders[i].append(value);
|
|
2274
|
+
}
|
|
2275
|
+
this.length++;
|
|
2276
|
+
}
|
|
2277
|
+
addArrayRow(row) {
|
|
2278
|
+
for (let i = 0; i < this.arrowBuilders.length; i++) {
|
|
2279
|
+
this.arrowBuilders[i].append(row[i]);
|
|
2280
|
+
}
|
|
2281
|
+
this.length++;
|
|
2282
|
+
}
|
|
2283
|
+
/** Makes sure that a first batch with schema is sent even if no rows */
|
|
2284
|
+
firstBatch() {
|
|
2285
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
2286
|
+
if (arrowRecordBatch.numCols !== 0) {
|
|
2287
|
+
return null;
|
|
2288
|
+
}
|
|
2289
|
+
return {
|
|
2290
|
+
shape: "arrow-table",
|
|
2291
|
+
batchType: "data",
|
|
2292
|
+
length: arrowRecordBatch.numRows,
|
|
2293
|
+
schema: this.schema,
|
|
2294
|
+
data: new arrow8.Table(arrowRecordBatch)
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
/** Flush the current batch if conditions are right */
|
|
2298
|
+
flushBatch() {
|
|
2299
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
2300
|
+
if (arrowRecordBatch.numCols === 0) {
|
|
2301
|
+
return null;
|
|
2302
|
+
}
|
|
2303
|
+
return {
|
|
2304
|
+
shape: "arrow-table",
|
|
2305
|
+
batchType: "data",
|
|
2306
|
+
length: arrowRecordBatch.numRows,
|
|
2307
|
+
schema: this.schema,
|
|
2308
|
+
data: new arrow8.Table(arrowRecordBatch)
|
|
2309
|
+
};
|
|
2310
|
+
}
|
|
2311
|
+
/** Get a last batch if any data is left */
|
|
2312
|
+
finishBatch() {
|
|
2313
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
2314
|
+
this.arrowBuilders.forEach((builder) => builder.finish());
|
|
2315
|
+
if (arrowRecordBatch.numCols === 0) {
|
|
2316
|
+
return null;
|
|
2317
|
+
}
|
|
2318
|
+
return {
|
|
2319
|
+
shape: "arrow-table",
|
|
2320
|
+
batchType: "data",
|
|
2321
|
+
length: arrowRecordBatch.numRows,
|
|
2322
|
+
schema: this.schema,
|
|
2323
|
+
data: new arrow8.Table(arrowRecordBatch)
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
/** Return a table with all the accumulated data */
|
|
2327
|
+
finishTable() {
|
|
2328
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
2329
|
+
this.arrowBuilders.forEach((builder) => builder.finish());
|
|
2330
|
+
return {
|
|
2331
|
+
shape: "arrow-table",
|
|
2332
|
+
schema: this.schema,
|
|
2333
|
+
data: new arrow8.Table(arrowRecordBatch)
|
|
2334
|
+
};
|
|
2335
|
+
}
|
|
2336
|
+
/** Extract a record batch flushing the currently accumulated data in the builders */
|
|
2337
|
+
_getArrowRecordBatch() {
|
|
2338
|
+
const { arrowBuilders, arrowSchema } = this;
|
|
2339
|
+
const arrowDatas = arrowBuilders.map((builder) => builder.flush());
|
|
2340
|
+
const length = arrowDatas[0].length;
|
|
2341
|
+
const structField = new arrow8.Struct(arrowSchema.fields);
|
|
2342
|
+
const arrowStructData = new arrow8.Data(structField, 0, length, 0, void 0, arrowDatas);
|
|
2343
|
+
const arrowRecordBatch = new arrow8.RecordBatch(arrowSchema, arrowStructData);
|
|
2344
|
+
return arrowRecordBatch;
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
|
|
2348
|
+
// dist/lib/table/arrow-api/get-type-info.js
|
|
2349
|
+
function getTypeInfo(arrowTypeLike) {
|
|
2350
|
+
return {
|
|
2351
|
+
typeId: arrowTypeLike.typeId,
|
|
2352
|
+
ArrayType: arrowTypeLike.ArrayType,
|
|
2353
|
+
typeName: arrowTypeLike.toString(),
|
|
2354
|
+
typeEnumName: getTypeKey(arrowTypeLike.typeId),
|
|
2355
|
+
precision: arrowTypeLike.precision
|
|
2356
|
+
};
|
|
2357
|
+
}
|
|
2358
|
+
var ReverseType = null;
|
|
2359
|
+
function getTypeKey(typeKey) {
|
|
2360
|
+
if (!ReverseType) {
|
|
2361
|
+
ReverseType = {};
|
|
2362
|
+
for (const key in Type) {
|
|
2363
|
+
ReverseType[Type[key]] = key;
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
return ReverseType[typeKey];
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
// dist/lib/utils/async-queue.js
|
|
2370
|
+
var ArrayQueue = class extends Array {
|
|
2371
|
+
enqueue(value) {
|
|
2372
|
+
return this.push(value);
|
|
2373
|
+
}
|
|
2374
|
+
dequeue() {
|
|
2375
|
+
return this.shift();
|
|
2376
|
+
}
|
|
2377
|
+
};
|
|
2378
|
+
var AsyncQueue = class {
|
|
2379
|
+
_values;
|
|
2380
|
+
_settlers;
|
|
2381
|
+
_closed;
|
|
2382
|
+
constructor() {
|
|
2383
|
+
this._values = new ArrayQueue();
|
|
2384
|
+
this._settlers = new ArrayQueue();
|
|
2385
|
+
this._closed = false;
|
|
2386
|
+
}
|
|
2387
|
+
close() {
|
|
2388
|
+
while (this._settlers.length > 0) {
|
|
2389
|
+
this._settlers.dequeue().resolve({ done: true });
|
|
2390
|
+
}
|
|
2391
|
+
this._closed = true;
|
|
2392
|
+
}
|
|
2393
|
+
[Symbol.asyncIterator]() {
|
|
2394
|
+
return this;
|
|
2395
|
+
}
|
|
2396
|
+
enqueue(value) {
|
|
2397
|
+
if (this._closed) {
|
|
2398
|
+
throw new Error("Closed");
|
|
2399
|
+
}
|
|
2400
|
+
if (this._settlers.length > 0) {
|
|
2401
|
+
if (this._values.length > 0) {
|
|
2402
|
+
throw new Error("Illegal internal state");
|
|
2403
|
+
}
|
|
2404
|
+
const settler = this._settlers.dequeue();
|
|
2405
|
+
if (value instanceof Error) {
|
|
2406
|
+
settler.reject(value);
|
|
2407
|
+
} else {
|
|
2408
|
+
settler.resolve({ value });
|
|
2409
|
+
}
|
|
2410
|
+
} else {
|
|
2411
|
+
this._values.enqueue(value);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
/**
|
|
2415
|
+
* @returns a Promise for an IteratorResult
|
|
2416
|
+
*/
|
|
2417
|
+
next() {
|
|
2418
|
+
if (this._values.length > 0) {
|
|
2419
|
+
const value = this._values.dequeue();
|
|
2420
|
+
if (value instanceof Error) {
|
|
2421
|
+
return Promise.reject(value);
|
|
2422
|
+
}
|
|
2423
|
+
return Promise.resolve({ value });
|
|
2424
|
+
}
|
|
2425
|
+
if (this._closed) {
|
|
2426
|
+
if (this._settlers.length > 0) {
|
|
2427
|
+
throw new Error("Illegal internal state");
|
|
2428
|
+
}
|
|
2429
|
+
return Promise.resolve({ done: true });
|
|
2430
|
+
}
|
|
2431
|
+
return new Promise((resolve, reject) => {
|
|
2432
|
+
this._settlers.enqueue({ resolve, reject });
|
|
2433
|
+
});
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
//# sourceMappingURL=index.cjs.map
|