@loaders.gl/arrow 4.0.1 → 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/dist/arrow-worker.js +33 -25
  2. package/dist/arrow-writer.d.ts +2 -2
  3. package/dist/arrow-writer.d.ts.map +1 -1
  4. package/dist/arrow-writer.js +6 -3
  5. package/dist/arrow-writer.js.map +1 -1
  6. package/dist/dist.dev.js +60 -29
  7. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +18 -2
  8. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
  9. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +18 -19
  10. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
  11. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +1 -1
  12. package/dist/geoarrow/get-arrow-bounds.d.ts.map +1 -1
  13. package/dist/geoarrow/get-arrow-bounds.js +1 -1
  14. package/dist/geoarrow/get-arrow-bounds.js.map +1 -1
  15. package/dist/index.cjs +177 -137
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +2 -1
  19. package/dist/index.js.map +1 -1
  20. package/dist/lib/arrow-table-batch.d.ts +2 -2
  21. package/dist/lib/arrow-table-batch.d.ts.map +1 -1
  22. package/dist/lib/arrow-table-batch.js +7 -7
  23. package/dist/lib/arrow-table-batch.js.map +1 -1
  24. package/dist/lib/arrow-table.d.ts +3 -3
  25. package/dist/lib/arrow-table.d.ts.map +1 -1
  26. package/dist/lib/arrow-table.js.map +1 -1
  27. package/dist/lib/encode-arrow.js +5 -5
  28. package/dist/lib/encode-arrow.js.map +1 -1
  29. package/dist/lib/parse-arrow-in-batches.js +3 -3
  30. package/dist/lib/parse-arrow-in-batches.js.map +1 -1
  31. package/dist/lib/parse-arrow-sync.js +2 -2
  32. package/dist/lib/parse-arrow-sync.js.map +1 -1
  33. package/dist/schema/arrow-type-utils.d.ts +2 -2
  34. package/dist/schema/arrow-type-utils.d.ts.map +1 -1
  35. package/dist/schema/arrow-type-utils.js +9 -9
  36. package/dist/schema/arrow-type-utils.js.map +1 -1
  37. package/dist/schema/convert-arrow-schema.d.ts +7 -7
  38. package/dist/schema/convert-arrow-schema.d.ts.map +1 -1
  39. package/dist/schema/convert-arrow-schema.js +113 -86
  40. package/dist/schema/convert-arrow-schema.js.map +1 -1
  41. package/dist/tables/convert-arrow-to-table.d.ts +2 -2
  42. package/dist/tables/convert-arrow-to-table.d.ts.map +1 -1
  43. package/dist/tables/convert-arrow-to-table.js.map +1 -1
  44. package/package.json +5 -5
  45. package/src/arrow-writer.ts +8 -5
  46. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +26 -26
  47. package/src/geoarrow/convert-geoarrow-to-geojson.ts +7 -7
  48. package/src/geoarrow/get-arrow-bounds.ts +1 -2
  49. package/src/index.ts +6 -1
  50. package/src/lib/arrow-table-batch.ts +13 -23
  51. package/src/lib/arrow-table.ts +3 -3
  52. package/src/lib/encode-arrow.ts +8 -8
  53. package/src/lib/parse-arrow-in-batches.ts +4 -4
  54. package/src/lib/parse-arrow-sync.ts +2 -2
  55. package/src/schema/arrow-type-utils.ts +10 -29
  56. package/src/schema/convert-arrow-schema.ts +126 -145
  57. package/src/tables/convert-arrow-to-table.ts +2 -2
@@ -2,54 +2,10 @@
2
2
  // Copyright (c) vis.gl contributors
3
3
 
4
4
  import type {DataType, Field, Schema, SchemaMetadata} from '@loaders.gl/schema';
5
- import {
6
- Field as ArrowField,
7
- Schema as ArrowSchema,
8
- DataType as ArrowDataType,
9
- Null,
10
- Binary,
11
- Bool,
12
- Int,
13
- Int8,
14
- Int16,
15
- Int32,
16
- Int64,
17
- Uint8,
18
- Uint16,
19
- Uint32,
20
- Uint64,
21
- Float,
22
- Float16,
23
- Float32,
24
- Float64,
25
- Precision,
26
- Utf8,
27
- Date_,
28
- DateUnit,
29
- DateDay,
30
- DateMillisecond,
31
- Time,
32
- TimeMillisecond,
33
- TimeSecond,
34
- Timestamp,
35
- TimestampSecond,
36
- TimestampMillisecond,
37
- TimestampMicrosecond,
38
- TimestampNanosecond,
39
- Interval,
40
- IntervalUnit,
41
- IntervalDayTime,
42
- IntervalYearMonth,
43
- FixedSizeList,
44
- Struct,
45
- TimeUnit,
46
- TimeMicrosecond,
47
- TimeNanosecond,
48
- List
49
- } from 'apache-arrow';
5
+ import * as arrow from 'apache-arrow';
50
6
 
51
7
  /** Convert Apache Arrow Schema (class instance) to a serialized Schema (plain data) */
52
- export function serializeArrowSchema(arrowSchema: ArrowSchema): Schema {
8
+ export function serializeArrowSchema(arrowSchema: arrow.Schema): Schema {
53
9
  return {
54
10
  fields: arrowSchema.fields.map((arrowField) => serializeArrowField(arrowField)),
55
11
  metadata: serializeArrowMetadata(arrowSchema.metadata)
@@ -57,8 +13,8 @@ export function serializeArrowSchema(arrowSchema: ArrowSchema): Schema {
57
13
  }
58
14
 
59
15
  /** Convert a serialized Schema (plain data) to an Apache Arrow Schema (class instance) */
60
- export function deserializeArrowSchema(schema: Schema): ArrowSchema {
61
- return new ArrowSchema(
16
+ export function deserializeArrowSchema(schema: Schema): arrow.Schema {
17
+ return new arrow.Schema(
62
18
  schema.fields.map((field) => deserializeArrowField(field)),
63
19
  deserializeArrowMetadata(schema.metadata)
64
20
  );
@@ -75,7 +31,7 @@ export function deserializeArrowMetadata(metadata?: SchemaMetadata): Map<string,
75
31
  }
76
32
 
77
33
  /** Convert Apache Arrow Field (class instance) to serialized Field (plain data) */
78
- export function serializeArrowField(field: ArrowField): Field {
34
+ export function serializeArrowField(field: arrow.Field): Field {
79
35
  return {
80
36
  name: field.name,
81
37
  type: serializeArrowType(field.type),
@@ -85,8 +41,8 @@ export function serializeArrowField(field: ArrowField): Field {
85
41
  }
86
42
 
87
43
  /** Convert a serialized Field (plain data) to an Apache Arrow Field (class instance)*/
88
- export function deserializeArrowField(field: Field): ArrowField {
89
- return new ArrowField(
44
+ export function deserializeArrowField(field: Field): arrow.Field {
45
+ return new arrow.Field(
90
46
  field.name,
91
47
  deserializeArrowType(field.type),
92
48
  field.nullable,
@@ -96,153 +52,178 @@ export function deserializeArrowField(field: Field): ArrowField {
96
52
 
97
53
  /** Converts a serializable loaders.gl data type to hydrated arrow data type */
98
54
  // eslint-disable-next-line complexity
99
- export function serializeArrowType(arrowType: ArrowDataType): DataType {
55
+ export function serializeArrowType(arrowType: arrow.DataType): DataType {
100
56
  switch (arrowType.constructor) {
101
- case Null:
57
+ case arrow.Null:
102
58
  return 'null';
103
- case Binary:
59
+ case arrow.Binary:
104
60
  return 'binary';
105
- case Bool:
61
+ case arrow.Bool:
106
62
  return 'bool';
107
- case Int:
108
- const intType = arrowType as Int;
63
+ case arrow.Int:
64
+ const intType = arrowType as arrow.Int;
109
65
  return `${intType.isSigned ? 'u' : ''}int${intType.bitWidth}`;
110
- case Int8:
66
+ case arrow.Int8:
111
67
  return 'int8';
112
- case Int16:
68
+ case arrow.Int16:
113
69
  return 'int16';
114
- case Int32:
70
+ case arrow.Int32:
115
71
  return 'int32';
116
- case Int64:
72
+ case arrow.Int64:
117
73
  return 'int64';
118
- case Uint8:
74
+ case arrow.Uint8:
119
75
  return 'uint8';
120
- case Uint16:
76
+ case arrow.Uint16:
121
77
  return 'uint16';
122
- case Uint32:
78
+ case arrow.Uint32:
123
79
  return 'uint32';
124
- case Uint64:
80
+ case arrow.Uint64:
125
81
  return 'uint64';
126
- case Float:
127
- const precision = (arrowType as Float).precision;
82
+ case arrow.Float:
83
+ const precision = (arrowType as arrow.Float).precision;
128
84
  // return `float(precision + 1) * 16`;
129
85
  switch (precision) {
130
- case Precision.HALF:
86
+ case arrow.Precision.HALF:
131
87
  return 'float16';
132
- case Precision.SINGLE:
88
+ case arrow.Precision.SINGLE:
133
89
  return 'float32';
134
- case Precision.DOUBLE:
90
+ case arrow.Precision.DOUBLE:
135
91
  return 'float64';
136
92
  default:
137
93
  return 'float16';
138
94
  }
139
- case Float16:
95
+ case arrow.Float16:
140
96
  return 'float16';
141
- case Float32:
97
+ case arrow.Float32:
142
98
  return 'float32';
143
- case Float64:
99
+ case arrow.Float64:
144
100
  return 'float64';
145
- case Utf8:
101
+ case arrow.Utf8:
146
102
  return 'utf8';
147
- case Date:
148
- const dateUnit = (arrowType as Date_).unit;
149
- return dateUnit === DateUnit.DAY ? 'date-day' : 'date-millisecond';
150
- case DateDay:
103
+ case arrow.Decimal:
104
+ const decimal = arrowType as arrow.Decimal;
105
+ return {
106
+ type: 'decimal',
107
+ bitWidth: decimal.bitWidth,
108
+ precision: decimal.precision,
109
+ scale: decimal.scale
110
+ };
111
+ case arrow.Date_:
112
+ const dateUnit = (arrowType as arrow.Date_).unit;
113
+ return dateUnit === arrow.DateUnit.DAY ? 'date-day' : 'date-millisecond';
114
+ case arrow.DateDay:
151
115
  return 'date-day';
152
- case DateMillisecond:
116
+ case arrow.DateMillisecond:
153
117
  return 'date-millisecond';
154
- case Time:
155
- const timeUnit = (arrowType as Time).unit;
118
+ case arrow.Time:
119
+ const timeUnit = (arrowType as arrow.Time).unit;
156
120
  switch (timeUnit) {
157
- case TimeUnit.SECOND:
121
+ case arrow.TimeUnit.SECOND:
158
122
  return 'time-second';
159
- case TimeUnit.MILLISECOND:
123
+ case arrow.TimeUnit.MILLISECOND:
160
124
  return 'time-millisecond';
161
- case TimeUnit.MICROSECOND:
125
+ case arrow.TimeUnit.MICROSECOND:
162
126
  return 'time-microsecond';
163
- case TimeUnit.NANOSECOND:
127
+ case arrow.TimeUnit.NANOSECOND:
164
128
  return 'time-nanosecond';
165
129
  default:
166
130
  return 'time-second';
167
131
  }
168
- case TimeMillisecond:
132
+ case arrow.TimeMillisecond:
169
133
  return 'time-millisecond';
170
- case TimeSecond:
134
+ case arrow.TimeSecond:
171
135
  return 'time-second';
172
- case TimeMicrosecond:
136
+ case arrow.TimeMicrosecond:
173
137
  return 'time-microsecond';
174
- case TimeNanosecond:
138
+ case arrow.TimeNanosecond:
175
139
  return 'time-nanosecond';
176
- case Timestamp:
177
- const timeStampUnit = (arrowType as Timestamp).unit;
140
+ case arrow.Timestamp:
141
+ const timeStampUnit = (arrowType as arrow.Timestamp).unit;
178
142
  switch (timeStampUnit) {
179
- case TimeUnit.SECOND:
143
+ case arrow.TimeUnit.SECOND:
180
144
  return 'timestamp-second';
181
- case TimeUnit.MILLISECOND:
145
+ case arrow.TimeUnit.MILLISECOND:
182
146
  return 'timestamp-millisecond';
183
- case TimeUnit.MICROSECOND:
147
+ case arrow.TimeUnit.MICROSECOND:
184
148
  return 'timestamp-microsecond';
185
- case TimeUnit.NANOSECOND:
149
+ case arrow.TimeUnit.NANOSECOND:
186
150
  return 'timestamp-nanosecond';
187
151
  default:
188
152
  return 'timestamp-second';
189
153
  }
190
- case TimestampSecond:
154
+ case arrow.TimestampSecond:
191
155
  return 'timestamp-second';
192
- case TimestampMillisecond:
156
+ case arrow.TimestampMillisecond:
193
157
  return 'timestamp-millisecond';
194
- case TimestampMicrosecond:
158
+ case arrow.TimestampMicrosecond:
195
159
  return 'timestamp-microsecond';
196
- case TimestampNanosecond:
160
+ case arrow.TimestampNanosecond:
197
161
  return 'timestamp-nanosecond';
198
- case Interval:
199
- const intervalUnit = (arrowType as Interval).unit;
162
+ case arrow.Interval:
163
+ const intervalUnit = (arrowType as arrow.Interval).unit;
200
164
  switch (intervalUnit) {
201
- case IntervalUnit.DAY_TIME:
165
+ case arrow.IntervalUnit.DAY_TIME:
202
166
  return 'interval-daytime';
203
- case IntervalUnit.YEAR_MONTH:
167
+ case arrow.IntervalUnit.YEAR_MONTH:
204
168
  return 'interval-yearmonth';
205
169
  default:
206
170
  return 'interval-daytime';
207
171
  }
208
- case IntervalDayTime:
172
+ case arrow.IntervalDayTime:
209
173
  return 'interval-daytime';
210
- case IntervalYearMonth:
174
+ case arrow.IntervalYearMonth:
211
175
  return 'interval-yearmonth';
212
- case List:
213
- const listType = arrowType as List;
176
+ case arrow.Map_:
177
+ const mapType = arrowType as arrow.Map_;
178
+ return {
179
+ type: 'map',
180
+ keysSorted: mapType.keysSorted,
181
+ children: mapType.children.map((arrowField) => serializeArrowField(arrowField))
182
+ };
183
+ case arrow.List:
184
+ const listType = arrowType as arrow.List;
214
185
  const listField = listType.valueField;
215
186
  return {
216
187
  type: 'list',
217
188
  children: [serializeArrowField(listField)]
218
189
  };
219
- case FixedSizeList:
190
+ case arrow.FixedSizeList:
191
+ const fixedSizeList = arrowType as arrow.FixedSizeList;
220
192
  return {
221
193
  type: 'fixed-size-list',
222
- listSize: (arrowType as FixedSizeList).listSize,
223
- children: [serializeArrowField((arrowType as FixedSizeList).children[0])]
194
+ listSize: fixedSizeList.listSize,
195
+ children: [serializeArrowField(fixedSizeList.children[0])]
196
+ };
197
+ case arrow.Struct:
198
+ const structType = arrowType as arrow.Struct;
199
+ return {
200
+ type: 'struct',
201
+ children: structType.children.map((arrowField) => serializeArrowField(arrowField))
224
202
  };
225
- // case Struct:
226
- // return {type: 'struct', children: (arrowType as Struct).children};
227
203
  default:
228
- throw new Error('array type not supported');
204
+ throw new Error(`arrow type not supported: ${arrowType.constructor.name}`);
229
205
  }
230
206
  }
231
207
 
232
208
  /** Converts a serializable loaders.gl data type to hydrated arrow data type */
233
209
  // eslint-disable-next-line complexity
234
- export function deserializeArrowType(dataType: DataType): ArrowDataType {
210
+ export function deserializeArrowType(dataType: DataType): arrow.DataType {
235
211
  if (typeof dataType === 'object') {
236
212
  switch (dataType.type) {
213
+ case 'decimal':
214
+ return new arrow.Decimal(dataType.precision, dataType.scale, dataType.bitWidth);
215
+ case 'map':
216
+ let children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
217
+ return new arrow.Map_(children as any, dataType.keysSorted);
237
218
  case 'list':
238
219
  const field = deserializeArrowField(dataType.children[0]);
239
- return new List(field);
220
+ return new arrow.List(field);
240
221
  case 'fixed-size-list':
241
222
  const child = deserializeArrowField(dataType.children[0]);
242
- return new FixedSizeList(dataType.listSize, child);
223
+ return new arrow.FixedSizeList(dataType.listSize, child);
243
224
  case 'struct':
244
- const children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
245
- return new Struct(children);
225
+ children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
226
+ return new arrow.Struct(children);
246
227
  default:
247
228
  throw new Error('array type not supported');
248
229
  }
@@ -250,59 +231,59 @@ export function deserializeArrowType(dataType: DataType): ArrowDataType {
250
231
 
251
232
  switch (dataType) {
252
233
  case 'null':
253
- return new Null();
234
+ return new arrow.Null();
254
235
  case 'binary':
255
- return new Binary();
236
+ return new arrow.Binary();
256
237
  case 'bool':
257
- return new Bool();
238
+ return new arrow.Bool();
258
239
  case 'int8':
259
- return new Int8();
240
+ return new arrow.Int8();
260
241
  case 'int16':
261
- return new Int16();
242
+ return new arrow.Int16();
262
243
  case 'int32':
263
- return new Int32();
244
+ return new arrow.Int32();
264
245
  case 'int64':
265
- return new Int64();
246
+ return new arrow.Int64();
266
247
  case 'uint8':
267
- return new Uint8();
248
+ return new arrow.Uint8();
268
249
  case 'uint16':
269
- return new Uint16();
250
+ return new arrow.Uint16();
270
251
  case 'uint32':
271
- return new Uint32();
252
+ return new arrow.Uint32();
272
253
  case 'uint64':
273
- return new Uint64();
254
+ return new arrow.Uint64();
274
255
  case 'float16':
275
- return new Float16();
256
+ return new arrow.Float16();
276
257
  case 'float32':
277
- return new Float32();
258
+ return new arrow.Float32();
278
259
  case 'float64':
279
- return new Float64();
260
+ return new arrow.Float64();
280
261
  case 'utf8':
281
- return new Utf8();
262
+ return new arrow.Utf8();
282
263
  case 'date-day':
283
- return new DateDay();
264
+ return new arrow.DateDay();
284
265
  case 'date-millisecond':
285
- return new DateMillisecond();
266
+ return new arrow.DateMillisecond();
286
267
  case 'time-second':
287
- return new TimeSecond();
268
+ return new arrow.TimeSecond();
288
269
  case 'time-millisecond':
289
- return new TimeMillisecond();
270
+ return new arrow.TimeMillisecond();
290
271
  case 'time-microsecond':
291
- return new TimeMicrosecond();
272
+ return new arrow.TimeMicrosecond();
292
273
  case 'time-nanosecond':
293
- return new TimeNanosecond();
274
+ return new arrow.TimeNanosecond();
294
275
  case 'timestamp-second':
295
- return new TimestampSecond();
276
+ return new arrow.TimestampSecond();
296
277
  case 'timestamp-millisecond':
297
- return new TimestampMillisecond();
278
+ return new arrow.TimestampMillisecond();
298
279
  case 'timestamp-microsecond':
299
- return new TimestampMicrosecond();
280
+ return new arrow.TimestampMicrosecond();
300
281
  case 'timestamp-nanosecond':
301
- return new TimestampNanosecond();
282
+ return new arrow.TimestampNanosecond();
302
283
  case 'interval-daytime':
303
- return new IntervalDayTime();
284
+ return new arrow.IntervalDayTime();
304
285
  case 'interval-yearmonth':
305
- return new IntervalYearMonth();
286
+ return new arrow.IntervalYearMonth();
306
287
  default:
307
288
  throw new Error('array type not supported');
308
289
  }
@@ -2,7 +2,7 @@
2
2
  // Copyright (c) vis.gl contributors
3
3
 
4
4
  import type {ColumnarTable, ObjectRowTable} from '@loaders.gl/schema';
5
- import type {Table as ApacheArrowTable} from 'apache-arrow';
5
+ import type * as arrow from 'apache-arrow';
6
6
  import type {ArrowTable} from '../lib/arrow-table';
7
7
 
8
8
  /**
@@ -11,7 +11,7 @@ import type {ArrowTable} from '../lib/arrow-table';
11
11
  * @param arrowTable
12
12
  * @returns
13
13
  */
14
- export function convertApacheArrowToArrowTable(arrowTable: ApacheArrowTable): ArrowTable {
14
+ export function convertApacheArrowToArrowTable(arrowTable: arrow.Table): ArrowTable {
15
15
  return {
16
16
  shape: 'arrow-table',
17
17
  data: arrowTable