@loaders.gl/arrow 4.3.2 → 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/dist/arrow-loader.d.ts +1 -1
- package/dist/arrow-worker.js +638 -1292
- package/dist/arrow-writer.js +1 -1
- package/dist/dist.dev.js +2140 -3383
- package/dist/dist.min.js +5 -5
- package/dist/exports/arrow-format.d.ts +12 -0
- package/dist/exports/arrow-format.d.ts.map +1 -0
- package/dist/exports/arrow-format.js +18 -0
- package/dist/exports/arrow-loader.d.ts +1 -1
- package/dist/exports/arrow-loader.d.ts.map +1 -1
- package/dist/exports/arrow-loader.js +1 -1
- package/dist/exports/geoarrow-loader.d.ts +1 -1
- package/dist/exports/geoarrow-loader.d.ts.map +1 -1
- package/dist/geoarrow-loader.d.ts +1 -2
- package/dist/geoarrow-loader.d.ts.map +1 -1
- package/dist/geoarrow-writer.d.ts +3 -3
- package/dist/geoarrow-writer.d.ts.map +1 -1
- package/dist/geoarrow-writer.js +1 -1
- package/dist/index.cjs +39 -952
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -14
- package/dist/lib/parsers/parse-arrow.d.ts +1 -2
- package/dist/lib/parsers/parse-arrow.d.ts.map +1 -1
- package/dist/lib/parsers/parse-arrow.js +1 -1
- package/dist/lib/parsers/parse-geoarrow.d.ts +1 -2
- package/dist/lib/parsers/parse-geoarrow.d.ts.map +1 -1
- package/dist/lib/parsers/parse-geoarrow.js +2 -2
- package/dist/triangulate-on-worker.d.ts +2 -1
- package/dist/triangulate-on-worker.d.ts.map +1 -1
- package/dist/triangulate-on-worker.js +1 -1
- package/dist/triangulation-worker.js +212 -154
- package/dist/workers/triangulation-worker.js +2 -2
- package/package.json +10 -9
- package/src/exports/arrow-format.ts +21 -0
- package/src/exports/arrow-loader.ts +1 -1
- package/src/exports/geoarrow-loader.ts +1 -2
- package/src/geoarrow-loader.ts +6 -2
- package/src/geoarrow-writer.ts +1 -1
- package/src/index.ts +2 -42
- package/src/lib/parsers/parse-arrow.ts +2 -3
- package/src/lib/parsers/parse-geoarrow.ts +8 -4
- package/src/triangulate-on-worker.ts +2 -1
- package/src/workers/triangulation-worker.ts +3 -3
- package/dist/lib/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +0 -74
- package/dist/lib/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +0 -1
- package/dist/lib/geoarrow/convert-geoarrow-to-binary-geometry.js +0 -377
- package/dist/lib/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts +0 -13
- package/dist/lib/geoarrow/convert-geoarrow-to-geojson-geometry.d.ts.map +0 -1
- package/dist/lib/geoarrow/convert-geoarrow-to-geojson-geometry.js +0 -176
- package/dist/lib/geoarrow/get-arrow-bounds.d.ts +0 -11
- package/dist/lib/geoarrow/get-arrow-bounds.d.ts.map +0 -1
- package/dist/lib/geoarrow/get-arrow-bounds.js +0 -34
- package/dist/lib/tables/convert-arrow-schema.d.ts +0 -23
- package/dist/lib/tables/convert-arrow-schema.d.ts.map +0 -1
- package/dist/lib/tables/convert-arrow-schema.js +0 -280
- package/dist/lib/tables/convert-arrow-to-table.d.ts +0 -15
- package/dist/lib/tables/convert-arrow-to-table.d.ts.map +0 -1
- package/dist/lib/tables/convert-arrow-to-table.js +0 -104
- package/dist/lib/tables/convert-table-to-arrow.d.ts +0 -16
- package/dist/lib/tables/convert-table-to-arrow.d.ts.map +0 -1
- package/dist/lib/tables/convert-table-to-arrow.js +0 -56
- package/dist/schema/arrow-table-batch.d.ts +0 -10
- package/dist/schema/arrow-table-batch.d.ts.map +0 -1
- package/dist/schema/arrow-table-batch.js +0 -67
- package/dist/schema/arrow-table-type.d.ts +0 -25
- package/dist/schema/arrow-table-type.d.ts.map +0 -1
- package/dist/schema/arrow-table-type.js +0 -4
- package/src/lib/geoarrow/convert-geoarrow-to-binary-geometry.ts +0 -494
- package/src/lib/geoarrow/convert-geoarrow-to-geojson-geometry.ts +0 -207
- package/src/lib/geoarrow/get-arrow-bounds.ts +0 -41
- package/src/lib/tables/convert-arrow-schema.ts +0 -301
- package/src/lib/tables/convert-arrow-to-table.ts +0 -144
- package/src/lib/tables/convert-table-to-arrow.ts +0 -72
- package/src/schema/arrow-table-batch.ts +0 -82
- package/src/schema/arrow-table-type.ts +0 -30
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Update bounds from geoarrow sample data
|
|
7
|
-
*
|
|
8
|
-
* @param flatCoords the flattend coordinates array from one chunk of geoarrow column
|
|
9
|
-
* @param nDim the number of dimensions of the coordinates
|
|
10
|
-
* @param bounds the bounds to be updated
|
|
11
|
-
* @param sampleSize how many samples to be used to update the bounds, default is 1000 per chunk
|
|
12
|
-
* @returns the updated bounds
|
|
13
|
-
*/
|
|
14
|
-
export function updateBoundsFromGeoArrowSamples(
|
|
15
|
-
flatCoords: Float64Array,
|
|
16
|
-
nDim: number,
|
|
17
|
-
bounds: [number, number, number, number],
|
|
18
|
-
sampleSize: number = 100
|
|
19
|
-
): [number, number, number, number] {
|
|
20
|
-
const numberOfFeatures = flatCoords.length / nDim;
|
|
21
|
-
const sampleStep = Math.max(Math.floor(numberOfFeatures / sampleSize), 1);
|
|
22
|
-
|
|
23
|
-
const newBounds: [number, number, number, number] = [...bounds];
|
|
24
|
-
for (let i = 0; i < numberOfFeatures; i += sampleStep) {
|
|
25
|
-
const lng = flatCoords[i * nDim];
|
|
26
|
-
const lat = flatCoords[i * nDim + 1];
|
|
27
|
-
if (lng < newBounds[0]) {
|
|
28
|
-
newBounds[0] = lng;
|
|
29
|
-
}
|
|
30
|
-
if (lat < newBounds[1]) {
|
|
31
|
-
newBounds[1] = lat;
|
|
32
|
-
}
|
|
33
|
-
if (lng > newBounds[2]) {
|
|
34
|
-
newBounds[2] = lng;
|
|
35
|
-
}
|
|
36
|
-
if (lat > newBounds[3]) {
|
|
37
|
-
newBounds[3] = lat;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return newBounds;
|
|
41
|
-
}
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {DataType, Field, Schema, SchemaMetadata} from '@loaders.gl/schema';
|
|
6
|
-
import * as arrow from 'apache-arrow';
|
|
7
|
-
|
|
8
|
-
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
9
|
-
export function convertArrowToSchema(arrowSchema: arrow.Schema): Schema {
|
|
10
|
-
return serializeArrowSchema(arrowSchema);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
14
|
-
export function convertSchemaToArrow(schema: Schema): arrow.Schema {
|
|
15
|
-
return deserializeArrowSchema(schema);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
|
|
19
|
-
export function serializeArrowSchema(arrowSchema: arrow.Schema): Schema {
|
|
20
|
-
return {
|
|
21
|
-
fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
|
|
22
|
-
metadata: serializeArrowMetadata(arrowSchema.metadata)
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Convert a serialized Schema (plain data) to an Apache Arrow Schema (class instance) */
|
|
27
|
-
export function deserializeArrowSchema(schema: Schema): arrow.Schema {
|
|
28
|
-
return new arrow.Schema(
|
|
29
|
-
schema.fields.map((field) => deserializeArrowField(field)),
|
|
30
|
-
deserializeArrowMetadata(schema.metadata)
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** Convert Apache Arrow Schema metadata (Map<string, string>) to serialized metadata (Record<string, string> */
|
|
35
|
-
export function serializeArrowMetadata(arrowMetadata: Map<string, string>): SchemaMetadata {
|
|
36
|
-
return Object.fromEntries(arrowMetadata);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Convert serialized metadata (Record<string, string> to Apache Arrow Schema metadata (Map<string, string>) to */
|
|
40
|
-
export function deserializeArrowMetadata(metadata?: SchemaMetadata): Map<string, string> {
|
|
41
|
-
return metadata ? new Map(Object.entries(metadata)) : new Map<string, string>();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Convert Apache Arrow Field (class instance) to serialized Field (plain data) */
|
|
45
|
-
export function serializeArrowField(field: arrow.Field): Field {
|
|
46
|
-
return {
|
|
47
|
-
name: field.name,
|
|
48
|
-
type: serializeArrowType(field.type),
|
|
49
|
-
nullable: field.nullable,
|
|
50
|
-
metadata: serializeArrowMetadata(field.metadata)
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** Convert a serialized Field (plain data) to an Apache Arrow Field (class instance)*/
|
|
55
|
-
export function deserializeArrowField(field: Field): arrow.Field {
|
|
56
|
-
return new arrow.Field(
|
|
57
|
-
field.name,
|
|
58
|
-
deserializeArrowType(field.type),
|
|
59
|
-
field.nullable,
|
|
60
|
-
deserializeArrowMetadata(field.metadata)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Converts a serializable loaders.gl data type to hydrated arrow data type */
|
|
65
|
-
// eslint-disable-next-line complexity
|
|
66
|
-
export function serializeArrowType(arrowType: arrow.DataType): DataType {
|
|
67
|
-
switch (arrowType.constructor) {
|
|
68
|
-
case arrow.Null:
|
|
69
|
-
return 'null';
|
|
70
|
-
case arrow.Binary:
|
|
71
|
-
return 'binary';
|
|
72
|
-
case arrow.Bool:
|
|
73
|
-
return 'bool';
|
|
74
|
-
case arrow.Int:
|
|
75
|
-
const intType = arrowType as arrow.Int;
|
|
76
|
-
return `${intType.isSigned ? 'u' : ''}int${intType.bitWidth}`;
|
|
77
|
-
case arrow.Int8:
|
|
78
|
-
return 'int8';
|
|
79
|
-
case arrow.Int16:
|
|
80
|
-
return 'int16';
|
|
81
|
-
case arrow.Int32:
|
|
82
|
-
return 'int32';
|
|
83
|
-
case arrow.Int64:
|
|
84
|
-
return 'int64';
|
|
85
|
-
case arrow.Uint8:
|
|
86
|
-
return 'uint8';
|
|
87
|
-
case arrow.Uint16:
|
|
88
|
-
return 'uint16';
|
|
89
|
-
case arrow.Uint32:
|
|
90
|
-
return 'uint32';
|
|
91
|
-
case arrow.Uint64:
|
|
92
|
-
return 'uint64';
|
|
93
|
-
case arrow.Float:
|
|
94
|
-
const precision = (arrowType as arrow.Float).precision;
|
|
95
|
-
// return `float(precision + 1) * 16`;
|
|
96
|
-
switch (precision) {
|
|
97
|
-
case arrow.Precision.HALF:
|
|
98
|
-
return 'float16';
|
|
99
|
-
case arrow.Precision.SINGLE:
|
|
100
|
-
return 'float32';
|
|
101
|
-
case arrow.Precision.DOUBLE:
|
|
102
|
-
return 'float64';
|
|
103
|
-
default:
|
|
104
|
-
return 'float16';
|
|
105
|
-
}
|
|
106
|
-
case arrow.Float16:
|
|
107
|
-
return 'float16';
|
|
108
|
-
case arrow.Float32:
|
|
109
|
-
return 'float32';
|
|
110
|
-
case arrow.Float64:
|
|
111
|
-
return 'float64';
|
|
112
|
-
case arrow.Utf8:
|
|
113
|
-
return 'utf8';
|
|
114
|
-
case arrow.Decimal:
|
|
115
|
-
const decimal = arrowType as arrow.Decimal;
|
|
116
|
-
return {
|
|
117
|
-
type: 'decimal',
|
|
118
|
-
bitWidth: decimal.bitWidth,
|
|
119
|
-
precision: decimal.precision,
|
|
120
|
-
scale: decimal.scale
|
|
121
|
-
};
|
|
122
|
-
case arrow.Date_:
|
|
123
|
-
const dateUnit = (arrowType as arrow.Date_).unit;
|
|
124
|
-
return dateUnit === arrow.DateUnit.DAY ? 'date-day' : 'date-millisecond';
|
|
125
|
-
case arrow.DateDay:
|
|
126
|
-
return 'date-day';
|
|
127
|
-
case arrow.DateMillisecond:
|
|
128
|
-
return 'date-millisecond';
|
|
129
|
-
case arrow.Time:
|
|
130
|
-
const timeUnit = (arrowType as arrow.Time).unit;
|
|
131
|
-
switch (timeUnit) {
|
|
132
|
-
case arrow.TimeUnit.SECOND:
|
|
133
|
-
return 'time-second';
|
|
134
|
-
case arrow.TimeUnit.MILLISECOND:
|
|
135
|
-
return 'time-millisecond';
|
|
136
|
-
case arrow.TimeUnit.MICROSECOND:
|
|
137
|
-
return 'time-microsecond';
|
|
138
|
-
case arrow.TimeUnit.NANOSECOND:
|
|
139
|
-
return 'time-nanosecond';
|
|
140
|
-
default:
|
|
141
|
-
return 'time-second';
|
|
142
|
-
}
|
|
143
|
-
case arrow.TimeMillisecond:
|
|
144
|
-
return 'time-millisecond';
|
|
145
|
-
case arrow.TimeSecond:
|
|
146
|
-
return 'time-second';
|
|
147
|
-
case arrow.TimeMicrosecond:
|
|
148
|
-
return 'time-microsecond';
|
|
149
|
-
case arrow.TimeNanosecond:
|
|
150
|
-
return 'time-nanosecond';
|
|
151
|
-
case arrow.Timestamp:
|
|
152
|
-
const timeStampUnit = (arrowType as arrow.Timestamp).unit;
|
|
153
|
-
switch (timeStampUnit) {
|
|
154
|
-
case arrow.TimeUnit.SECOND:
|
|
155
|
-
return 'timestamp-second';
|
|
156
|
-
case arrow.TimeUnit.MILLISECOND:
|
|
157
|
-
return 'timestamp-millisecond';
|
|
158
|
-
case arrow.TimeUnit.MICROSECOND:
|
|
159
|
-
return 'timestamp-microsecond';
|
|
160
|
-
case arrow.TimeUnit.NANOSECOND:
|
|
161
|
-
return 'timestamp-nanosecond';
|
|
162
|
-
default:
|
|
163
|
-
return 'timestamp-second';
|
|
164
|
-
}
|
|
165
|
-
case arrow.TimestampSecond:
|
|
166
|
-
return 'timestamp-second';
|
|
167
|
-
case arrow.TimestampMillisecond:
|
|
168
|
-
return 'timestamp-millisecond';
|
|
169
|
-
case arrow.TimestampMicrosecond:
|
|
170
|
-
return 'timestamp-microsecond';
|
|
171
|
-
case arrow.TimestampNanosecond:
|
|
172
|
-
return 'timestamp-nanosecond';
|
|
173
|
-
case arrow.Interval:
|
|
174
|
-
const intervalUnit = (arrowType as arrow.Interval).unit;
|
|
175
|
-
switch (intervalUnit) {
|
|
176
|
-
case arrow.IntervalUnit.DAY_TIME:
|
|
177
|
-
return 'interval-daytime';
|
|
178
|
-
case arrow.IntervalUnit.YEAR_MONTH:
|
|
179
|
-
return 'interval-yearmonth';
|
|
180
|
-
default:
|
|
181
|
-
return 'interval-daytime';
|
|
182
|
-
}
|
|
183
|
-
case arrow.IntervalDayTime:
|
|
184
|
-
return 'interval-daytime';
|
|
185
|
-
case arrow.IntervalYearMonth:
|
|
186
|
-
return 'interval-yearmonth';
|
|
187
|
-
case arrow.Map_:
|
|
188
|
-
const mapType = arrowType as arrow.Map_;
|
|
189
|
-
return {
|
|
190
|
-
type: 'map',
|
|
191
|
-
keysSorted: mapType.keysSorted,
|
|
192
|
-
children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
193
|
-
};
|
|
194
|
-
case arrow.List:
|
|
195
|
-
const listType = arrowType as arrow.List;
|
|
196
|
-
const listField = listType.valueField;
|
|
197
|
-
return {
|
|
198
|
-
type: 'list',
|
|
199
|
-
children: [serializeArrowField(listField)]
|
|
200
|
-
};
|
|
201
|
-
case arrow.FixedSizeList:
|
|
202
|
-
const fixedSizeList = arrowType as arrow.FixedSizeList;
|
|
203
|
-
return {
|
|
204
|
-
type: 'fixed-size-list',
|
|
205
|
-
listSize: fixedSizeList.listSize,
|
|
206
|
-
children: [serializeArrowField(fixedSizeList.children[0])]
|
|
207
|
-
};
|
|
208
|
-
case arrow.Struct:
|
|
209
|
-
const structType = arrowType as arrow.Struct;
|
|
210
|
-
return {
|
|
211
|
-
type: 'struct',
|
|
212
|
-
children: structType.children.map((arrowField) => serializeArrowField(arrowField))
|
|
213
|
-
};
|
|
214
|
-
default:
|
|
215
|
-
throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/** Converts a serializable loaders.gl data type to hydrated arrow data type */
|
|
220
|
-
// eslint-disable-next-line complexity
|
|
221
|
-
export function deserializeArrowType(dataType: DataType): arrow.DataType {
|
|
222
|
-
if (typeof dataType === 'object') {
|
|
223
|
-
switch (dataType.type) {
|
|
224
|
-
case 'decimal':
|
|
225
|
-
return new arrow.Decimal(dataType.precision, dataType.scale, dataType.bitWidth);
|
|
226
|
-
case 'map':
|
|
227
|
-
let children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
228
|
-
return new arrow.Map_(children as any, dataType.keysSorted);
|
|
229
|
-
case 'list':
|
|
230
|
-
const field = deserializeArrowField(dataType.children[0]);
|
|
231
|
-
return new arrow.List(field);
|
|
232
|
-
case 'fixed-size-list':
|
|
233
|
-
const child = deserializeArrowField(dataType.children[0]);
|
|
234
|
-
return new arrow.FixedSizeList(dataType.listSize, child);
|
|
235
|
-
case 'struct':
|
|
236
|
-
children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
|
|
237
|
-
return new arrow.Struct(children);
|
|
238
|
-
default:
|
|
239
|
-
throw new Error('array type not supported');
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
switch (dataType) {
|
|
244
|
-
case 'null':
|
|
245
|
-
return new arrow.Null();
|
|
246
|
-
case 'binary':
|
|
247
|
-
return new arrow.Binary();
|
|
248
|
-
case 'bool':
|
|
249
|
-
return new arrow.Bool();
|
|
250
|
-
case 'int8':
|
|
251
|
-
return new arrow.Int8();
|
|
252
|
-
case 'int16':
|
|
253
|
-
return new arrow.Int16();
|
|
254
|
-
case 'int32':
|
|
255
|
-
return new arrow.Int32();
|
|
256
|
-
case 'int64':
|
|
257
|
-
return new arrow.Int64();
|
|
258
|
-
case 'uint8':
|
|
259
|
-
return new arrow.Uint8();
|
|
260
|
-
case 'uint16':
|
|
261
|
-
return new arrow.Uint16();
|
|
262
|
-
case 'uint32':
|
|
263
|
-
return new arrow.Uint32();
|
|
264
|
-
case 'uint64':
|
|
265
|
-
return new arrow.Uint64();
|
|
266
|
-
case 'float16':
|
|
267
|
-
return new arrow.Float16();
|
|
268
|
-
case 'float32':
|
|
269
|
-
return new arrow.Float32();
|
|
270
|
-
case 'float64':
|
|
271
|
-
return new arrow.Float64();
|
|
272
|
-
case 'utf8':
|
|
273
|
-
return new arrow.Utf8();
|
|
274
|
-
case 'date-day':
|
|
275
|
-
return new arrow.DateDay();
|
|
276
|
-
case 'date-millisecond':
|
|
277
|
-
return new arrow.DateMillisecond();
|
|
278
|
-
case 'time-second':
|
|
279
|
-
return new arrow.TimeSecond();
|
|
280
|
-
case 'time-millisecond':
|
|
281
|
-
return new arrow.TimeMillisecond();
|
|
282
|
-
case 'time-microsecond':
|
|
283
|
-
return new arrow.TimeMicrosecond();
|
|
284
|
-
case 'time-nanosecond':
|
|
285
|
-
return new arrow.TimeNanosecond();
|
|
286
|
-
case 'timestamp-second':
|
|
287
|
-
return new arrow.TimestampSecond();
|
|
288
|
-
case 'timestamp-millisecond':
|
|
289
|
-
return new arrow.TimestampMillisecond();
|
|
290
|
-
case 'timestamp-microsecond':
|
|
291
|
-
return new arrow.TimestampMicrosecond();
|
|
292
|
-
case 'timestamp-nanosecond':
|
|
293
|
-
return new arrow.TimestampNanosecond();
|
|
294
|
-
case 'interval-daytime':
|
|
295
|
-
return new arrow.IntervalDayTime();
|
|
296
|
-
case 'interval-yearmonth':
|
|
297
|
-
return new arrow.IntervalYearMonth();
|
|
298
|
-
default:
|
|
299
|
-
throw new Error('array type not supported');
|
|
300
|
-
}
|
|
301
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import * as arrow from 'apache-arrow';
|
|
6
|
-
import type {
|
|
7
|
-
Table,
|
|
8
|
-
ArrayRowTable,
|
|
9
|
-
ColumnarTable,
|
|
10
|
-
ObjectRowTable,
|
|
11
|
-
GeoJSONTable,
|
|
12
|
-
Feature
|
|
13
|
-
} from '@loaders.gl/schema';
|
|
14
|
-
import type {ArrowTable} from '../../schema/arrow-table-type';
|
|
15
|
-
|
|
16
|
-
import {convertTable} from '@loaders.gl/schema';
|
|
17
|
-
import {getGeometryColumnsFromSchema} from '@loaders.gl/gis';
|
|
18
|
-
import {convertArrowToSchema} from '../tables/convert-arrow-schema';
|
|
19
|
-
import {parseGeometryFromArrow} from '../geoarrow/convert-geoarrow-to-geojson-geometry';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Convert an Apache Arrow table to a loaders.gl Table
|
|
23
|
-
* @note Currently does not convert schema
|
|
24
|
-
*/
|
|
25
|
-
export function convertArrowToTable(arrow: arrow.Table, shape: 'arrow-table'): ArrowTable;
|
|
26
|
-
export function convertArrowToTable(arrow: arrow.Table, shape: 'columnar-table'): ColumnarTable;
|
|
27
|
-
export function convertArrowToTable(arrow: arrow.Table, shape: 'object-row-table'): ObjectRowTable;
|
|
28
|
-
export function convertArrowToTable(arrow: arrow.Table, shape: 'array-row-table'): ArrayRowTable;
|
|
29
|
-
export function convertArrowToTable(arrow: arrow.Table, shape: 'geojson-table'): GeoJSONTable;
|
|
30
|
-
export function convertArrowToTable(arrow: arrow.Table, shape: 'columnar-table'): ColumnarTable;
|
|
31
|
-
export function convertArrowToTable(arrow: arrow.Table, shape: Table['shape']): Table;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Convert an Apache Arrow table to a loaders.gl Table
|
|
35
|
-
* @note Currently does not convert schema
|
|
36
|
-
*/
|
|
37
|
-
export function convertArrowToTable(arrowTable: arrow.Table, shape: Table['shape']): Table {
|
|
38
|
-
switch (shape) {
|
|
39
|
-
case 'arrow-table':
|
|
40
|
-
return convertArrowToArrowTable(arrowTable);
|
|
41
|
-
case 'array-row-table':
|
|
42
|
-
return convertArrowToArrayRowTable(arrowTable);
|
|
43
|
-
case 'object-row-table':
|
|
44
|
-
return convertArrowToObjectRowTable(arrowTable);
|
|
45
|
-
case 'columnar-table':
|
|
46
|
-
return convertArrowToColumnarTable(arrowTable);
|
|
47
|
-
case 'geojson-table':
|
|
48
|
-
return convertArrowToGeoJSONTable(arrowTable);
|
|
49
|
-
default:
|
|
50
|
-
throw new Error(shape);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Wrap an apache arrow table in a loaders.gl table wrapper.
|
|
56
|
-
* From this additional conversions are available.
|
|
57
|
-
* @param arrowTable
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
function convertArrowToArrowTable(arrowTable: arrow.Table): ArrowTable {
|
|
61
|
-
return {
|
|
62
|
-
shape: 'arrow-table',
|
|
63
|
-
schema: convertArrowToSchema(arrowTable.schema),
|
|
64
|
-
data: arrowTable
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function convertArrowToArrayRowTable(arrowTable: arrow.Table): Table {
|
|
69
|
-
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
70
|
-
return convertTable(columnarTable, 'array-row-table');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function convertArrowToObjectRowTable(arrowTable: arrow.Table): Table {
|
|
74
|
-
const columnarTable = convertArrowToColumnarTable(arrowTable);
|
|
75
|
-
return convertTable(columnarTable, 'object-row-table');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Convert an Apache Arrow table to a ColumnarTable
|
|
80
|
-
* @note Currently does not convert schema
|
|
81
|
-
*/
|
|
82
|
-
function convertArrowToColumnarTable(arrowTable: arrow.Table): ColumnarTable {
|
|
83
|
-
// TODO - avoid calling `getColumn` on columns we are not interested in?
|
|
84
|
-
// Add options object?
|
|
85
|
-
|
|
86
|
-
const columns: ColumnarTable['data'] = {};
|
|
87
|
-
|
|
88
|
-
for (const field of arrowTable.schema.fields) {
|
|
89
|
-
// This (is intended to) coalesce all record batches into a single typed array
|
|
90
|
-
const arrowColumn = arrowTable.getChild(field.name);
|
|
91
|
-
const values = arrowColumn?.toArray();
|
|
92
|
-
columns[field.name] = values;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const schema = convertArrowToSchema(arrowTable.schema);
|
|
96
|
-
|
|
97
|
-
return {
|
|
98
|
-
shape: 'columnar-table',
|
|
99
|
-
schema,
|
|
100
|
-
data: columns
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Convert an Apache Arrow table to a GeoJSONTable
|
|
106
|
-
* @note Currently does not convert schema
|
|
107
|
-
*/
|
|
108
|
-
function convertArrowToGeoJSONTable(arrowTable: arrow.Table): GeoJSONTable {
|
|
109
|
-
const schema = convertArrowToSchema(arrowTable.schema);
|
|
110
|
-
const geometryColumns = getGeometryColumnsFromSchema(schema);
|
|
111
|
-
|
|
112
|
-
// get encoding from geometryColumns['geometry']
|
|
113
|
-
const encoding = geometryColumns.geometry.encoding;
|
|
114
|
-
|
|
115
|
-
const features: Feature[] = [];
|
|
116
|
-
|
|
117
|
-
// Remove geometry columns
|
|
118
|
-
const propertyColumnNames = arrowTable.schema.fields
|
|
119
|
-
.map((field) => field.name)
|
|
120
|
-
// TODO - this deletes all geometry columns
|
|
121
|
-
.filter((name) => !(name in geometryColumns));
|
|
122
|
-
const propertiesTable = arrowTable.select(propertyColumnNames);
|
|
123
|
-
|
|
124
|
-
const arrowGeometryColumn = arrowTable.getChild('geometry');
|
|
125
|
-
|
|
126
|
-
for (let row = 0; row < arrowTable.numRows; row++) {
|
|
127
|
-
// get the geometry value from arrow geometry column
|
|
128
|
-
// Note that type can vary
|
|
129
|
-
const arrowGeometry = arrowGeometryColumn?.get(row);
|
|
130
|
-
// parse arrow geometry to geojson feature
|
|
131
|
-
const feature = parseGeometryFromArrow(arrowGeometry, encoding);
|
|
132
|
-
if (feature) {
|
|
133
|
-
const properties = propertiesTable.get(row)?.toJSON() || {};
|
|
134
|
-
features.push({type: 'Feature', geometry: feature, properties});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
shape: 'geojson-table',
|
|
140
|
-
type: 'FeatureCollection',
|
|
141
|
-
schema,
|
|
142
|
-
features
|
|
143
|
-
};
|
|
144
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import * as arrow from 'apache-arrow';
|
|
6
|
-
import {Table, getTableLength, getTableNumCols, getTableCellAt} from '@loaders.gl/schema';
|
|
7
|
-
import {deserializeArrowSchema} from '../tables/convert-arrow-schema';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* * Convert a loaders.gl Table to an Apache Arrow Table
|
|
11
|
-
* @param mesh
|
|
12
|
-
* @param metadata
|
|
13
|
-
* @param batchSize
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
export function convertTableToArrow(table: Table, options?: {batchSize?: number}): arrow.Table {
|
|
17
|
-
switch (table.shape) {
|
|
18
|
-
case 'arrow-table':
|
|
19
|
-
return table.data as arrow.Table;
|
|
20
|
-
|
|
21
|
-
case 'columnar-table':
|
|
22
|
-
// TODO - optimized implementation is possible
|
|
23
|
-
// return convertColumnarTableToArrow(table, options);
|
|
24
|
-
|
|
25
|
-
// fall through
|
|
26
|
-
|
|
27
|
-
default:
|
|
28
|
-
const arrowBatchIterator = makeTableToArrowBatchesIterator(table, options);
|
|
29
|
-
return new arrow.Table(arrowBatchIterator);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function* makeTableToArrowBatchesIterator(
|
|
34
|
-
table: Table,
|
|
35
|
-
options?: {batchSize?: number}
|
|
36
|
-
): IterableIterator<arrow.RecordBatch> {
|
|
37
|
-
const arrowSchema = deserializeArrowSchema(table.schema!);
|
|
38
|
-
|
|
39
|
-
const length = getTableLength(table);
|
|
40
|
-
const numColumns = getTableNumCols(table);
|
|
41
|
-
const batchSize = options?.batchSize || length;
|
|
42
|
-
|
|
43
|
-
const builders = arrowSchema?.fields.map((arrowField) => arrow.makeBuilder(arrowField));
|
|
44
|
-
const structField = new arrow.Struct(arrowSchema.fields);
|
|
45
|
-
|
|
46
|
-
let batchLength = 0;
|
|
47
|
-
for (let rowIndex = 0; rowIndex < length; rowIndex++) {
|
|
48
|
-
for (let columnIndex = 0; columnIndex < numColumns; ++columnIndex) {
|
|
49
|
-
const value = getTableCellAt(table, rowIndex, columnIndex);
|
|
50
|
-
|
|
51
|
-
const builder = builders[columnIndex];
|
|
52
|
-
builder.append(value);
|
|
53
|
-
batchLength++;
|
|
54
|
-
|
|
55
|
-
if (batchLength >= batchSize) {
|
|
56
|
-
const datas = builders.map((builder) => builder.flush());
|
|
57
|
-
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
58
|
-
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
59
|
-
batchLength = 0;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (batchLength > 0) {
|
|
65
|
-
const datas = builders.map((builder) => builder.flush());
|
|
66
|
-
const structData = new arrow.Data(structField, 0, batchLength, 0, undefined, datas);
|
|
67
|
-
yield new arrow.RecordBatch(arrowSchema, structData);
|
|
68
|
-
batchLength = 0;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
builders.map((builder) => builder.finish());
|
|
72
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import {ColumnarTableBatchAggregator} from '@loaders.gl/schema';
|
|
6
|
-
import type {ArrowTableBatch} from './arrow-table-type';
|
|
7
|
-
import * as arrow from 'apache-arrow';
|
|
8
|
-
|
|
9
|
-
/** @note Should be part of @loaders.gl/schema - kept separate to avoid hard arrow dependency */
|
|
10
|
-
export class ArrowTableBatchAggregator extends ColumnarTableBatchAggregator {
|
|
11
|
-
arrowSchema: arrow.Schema | null;
|
|
12
|
-
|
|
13
|
-
constructor(schema, options) {
|
|
14
|
-
super(schema, options);
|
|
15
|
-
this.arrowSchema = null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
getBatch(): ArrowTableBatch | null {
|
|
19
|
-
const batch = super.getBatch();
|
|
20
|
-
if (batch) {
|
|
21
|
-
// Get the arrow schema
|
|
22
|
-
this.arrowSchema = this.arrowSchema || getArrowSchema(batch.schema);
|
|
23
|
-
|
|
24
|
-
// Get arrow format vectors
|
|
25
|
-
const arrowVectors = getArrowVectors(this.arrowSchema, batch.data);
|
|
26
|
-
|
|
27
|
-
// Create the record batch
|
|
28
|
-
const recordBatch = new arrow.RecordBatch(
|
|
29
|
-
this.arrowSchema,
|
|
30
|
-
arrow.makeData({
|
|
31
|
-
type: new arrow.Struct(this.arrowSchema.fields),
|
|
32
|
-
children: arrowVectors.map(({data}) => data[0])
|
|
33
|
-
})
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
shape: 'arrow-table',
|
|
38
|
-
batchType: 'data',
|
|
39
|
-
data: new arrow.Table([recordBatch]),
|
|
40
|
-
length: batch.length
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// Convert from a simple loaders.gl schema to an Arrow schema
|
|
49
|
-
function getArrowSchema(schema): arrow.Schema {
|
|
50
|
-
const arrowFields: arrow.Field[] = [];
|
|
51
|
-
for (const key in schema) {
|
|
52
|
-
const field = schema[key];
|
|
53
|
-
if (field.type === Float32Array) {
|
|
54
|
-
// TODO - just store the original field as metadata?
|
|
55
|
-
const metadata = new Map(); // field;
|
|
56
|
-
// arrow: new arrow.Field(name, nullable, metadata)
|
|
57
|
-
const arrowField = new arrow.Field(field.name, new arrow.Float32(), field.nullable, metadata);
|
|
58
|
-
arrowFields.push(arrowField);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (arrowFields.length === 0) {
|
|
62
|
-
throw new Error('No arrow convertible fields');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return new arrow.Schema(arrowFields);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Convert from simple loaders.gl arrays to arrow vectors
|
|
69
|
-
function getArrowVectors(arrowSchema, data): arrow.Vector[] {
|
|
70
|
-
const arrowVectors: any[] = [];
|
|
71
|
-
for (const field of arrowSchema.fields) {
|
|
72
|
-
const vector = data[field.name];
|
|
73
|
-
if (vector instanceof Float32Array) {
|
|
74
|
-
const arrowVector = arrow.makeVector(vector);
|
|
75
|
-
arrowVectors.push(arrowVector);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (arrowSchema.fields.length !== arrowVectors.length) {
|
|
79
|
-
throw new Error('Some columns not arrow convertible');
|
|
80
|
-
}
|
|
81
|
-
return arrowVectors;
|
|
82
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// loaders.gl
|
|
2
|
-
// SPDX-License-Identifier: MIT
|
|
3
|
-
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
import type {Batch, Schema} from '@loaders.gl/schema';
|
|
6
|
-
import type * as arrow from 'apache-arrow';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A table organized as an Apache Arrow table
|
|
10
|
-
* @note This is a variant of the type from loaders.gl/schema
|
|
11
|
-
* @note Should be part of @loaders.gl/schema - kept separate to avoid hard arrow dependency
|
|
12
|
-
*/
|
|
13
|
-
export type ArrowTable = {
|
|
14
|
-
shape: 'arrow-table';
|
|
15
|
-
schema?: Schema;
|
|
16
|
-
data: arrow.Table;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Batch for a table organized as an Apache Arrow table
|
|
21
|
-
* @note This is a variant of the type from loaders.gl/schema
|
|
22
|
-
* @note Should be part of @loaders.gl/schema - kept separate to avoid hard arrow dependency
|
|
23
|
-
*/
|
|
24
|
-
export type ArrowTableBatch = Batch & {
|
|
25
|
-
shape: 'arrow-table';
|
|
26
|
-
schemaType?: 'explicit' | 'deduced';
|
|
27
|
-
schema?: Schema;
|
|
28
|
-
data: arrow.Table; // ApacheRecordBatch;
|
|
29
|
-
length: number;
|
|
30
|
-
};
|