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