@loaders.gl/arrow 4.0.1 → 4.0.2

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 (56) hide show
  1. package/dist/arrow-worker.js +33 -25
  2. package/dist/arrow-writer.d.ts.map +1 -1
  3. package/dist/arrow-writer.js +6 -3
  4. package/dist/arrow-writer.js.map +1 -1
  5. package/dist/dist.dev.js +18 -14
  6. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts +18 -2
  7. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.d.ts.map +1 -1
  8. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js +8 -9
  9. package/dist/geoarrow/convert-geoarrow-to-binary-geometry.js.map +1 -1
  10. package/dist/geoarrow/convert-geoarrow-to-geojson.js.map +1 -1
  11. package/dist/geoarrow/get-arrow-bounds.d.ts.map +1 -1
  12. package/dist/geoarrow/get-arrow-bounds.js +1 -1
  13. package/dist/geoarrow/get-arrow-bounds.js.map +1 -1
  14. package/dist/index.cjs +135 -122
  15. package/dist/index.d.ts +2 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/lib/arrow-table-batch.d.ts +2 -2
  20. package/dist/lib/arrow-table-batch.d.ts.map +1 -1
  21. package/dist/lib/arrow-table-batch.js +7 -7
  22. package/dist/lib/arrow-table-batch.js.map +1 -1
  23. package/dist/lib/arrow-table.d.ts +3 -3
  24. package/dist/lib/arrow-table.d.ts.map +1 -1
  25. package/dist/lib/arrow-table.js.map +1 -1
  26. package/dist/lib/encode-arrow.js +5 -5
  27. package/dist/lib/encode-arrow.js.map +1 -1
  28. package/dist/lib/parse-arrow-in-batches.js +3 -3
  29. package/dist/lib/parse-arrow-in-batches.js.map +1 -1
  30. package/dist/lib/parse-arrow-sync.js +2 -2
  31. package/dist/lib/parse-arrow-sync.js.map +1 -1
  32. package/dist/schema/arrow-type-utils.d.ts +2 -2
  33. package/dist/schema/arrow-type-utils.d.ts.map +1 -1
  34. package/dist/schema/arrow-type-utils.js +9 -9
  35. package/dist/schema/arrow-type-utils.js.map +1 -1
  36. package/dist/schema/convert-arrow-schema.d.ts +7 -7
  37. package/dist/schema/convert-arrow-schema.d.ts.map +1 -1
  38. package/dist/schema/convert-arrow-schema.js +81 -81
  39. package/dist/schema/convert-arrow-schema.js.map +1 -1
  40. package/dist/tables/convert-arrow-to-table.d.ts +2 -2
  41. package/dist/tables/convert-arrow-to-table.d.ts.map +1 -1
  42. package/dist/tables/convert-arrow-to-table.js.map +1 -1
  43. package/package.json +5 -5
  44. package/src/arrow-writer.ts +6 -3
  45. package/src/geoarrow/convert-geoarrow-to-binary-geometry.ts +14 -16
  46. package/src/geoarrow/convert-geoarrow-to-geojson.ts +7 -7
  47. package/src/geoarrow/get-arrow-bounds.ts +1 -2
  48. package/src/index.ts +6 -1
  49. package/src/lib/arrow-table-batch.ts +13 -23
  50. package/src/lib/arrow-table.ts +3 -3
  51. package/src/lib/encode-arrow.ts +8 -8
  52. package/src/lib/parse-arrow-in-batches.ts +4 -4
  53. package/src/lib/parse-arrow-sync.ts +2 -2
  54. package/src/schema/arrow-type-utils.ts +10 -29
  55. package/src/schema/convert-arrow-schema.ts +98 -142
  56. 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,134 +52,134 @@ 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
103
  case Date:
148
- const dateUnit = (arrowType as Date_).unit;
149
- return dateUnit === DateUnit.DAY ? 'date-day' : 'date-millisecond';
150
- case DateDay:
104
+ const dateUnit = (arrowType as arrow.Date_).unit;
105
+ return dateUnit === arrow.DateUnit.DAY ? 'date-day' : 'date-millisecond';
106
+ case arrow.DateDay:
151
107
  return 'date-day';
152
- case DateMillisecond:
108
+ case arrow.DateMillisecond:
153
109
  return 'date-millisecond';
154
- case Time:
155
- const timeUnit = (arrowType as Time).unit;
110
+ case arrow.Time:
111
+ const timeUnit = (arrowType as arrow.Time).unit;
156
112
  switch (timeUnit) {
157
- case TimeUnit.SECOND:
113
+ case arrow.TimeUnit.SECOND:
158
114
  return 'time-second';
159
- case TimeUnit.MILLISECOND:
115
+ case arrow.TimeUnit.MILLISECOND:
160
116
  return 'time-millisecond';
161
- case TimeUnit.MICROSECOND:
117
+ case arrow.TimeUnit.MICROSECOND:
162
118
  return 'time-microsecond';
163
- case TimeUnit.NANOSECOND:
119
+ case arrow.TimeUnit.NANOSECOND:
164
120
  return 'time-nanosecond';
165
121
  default:
166
122
  return 'time-second';
167
123
  }
168
- case TimeMillisecond:
124
+ case arrow.TimeMillisecond:
169
125
  return 'time-millisecond';
170
- case TimeSecond:
126
+ case arrow.TimeSecond:
171
127
  return 'time-second';
172
- case TimeMicrosecond:
128
+ case arrow.TimeMicrosecond:
173
129
  return 'time-microsecond';
174
- case TimeNanosecond:
130
+ case arrow.TimeNanosecond:
175
131
  return 'time-nanosecond';
176
- case Timestamp:
177
- const timeStampUnit = (arrowType as Timestamp).unit;
132
+ case arrow.Timestamp:
133
+ const timeStampUnit = (arrowType as arrow.Timestamp).unit;
178
134
  switch (timeStampUnit) {
179
- case TimeUnit.SECOND:
135
+ case arrow.TimeUnit.SECOND:
180
136
  return 'timestamp-second';
181
- case TimeUnit.MILLISECOND:
137
+ case arrow.TimeUnit.MILLISECOND:
182
138
  return 'timestamp-millisecond';
183
- case TimeUnit.MICROSECOND:
139
+ case arrow.TimeUnit.MICROSECOND:
184
140
  return 'timestamp-microsecond';
185
- case TimeUnit.NANOSECOND:
141
+ case arrow.TimeUnit.NANOSECOND:
186
142
  return 'timestamp-nanosecond';
187
143
  default:
188
144
  return 'timestamp-second';
189
145
  }
190
- case TimestampSecond:
146
+ case arrow.TimestampSecond:
191
147
  return 'timestamp-second';
192
- case TimestampMillisecond:
148
+ case arrow.TimestampMillisecond:
193
149
  return 'timestamp-millisecond';
194
- case TimestampMicrosecond:
150
+ case arrow.TimestampMicrosecond:
195
151
  return 'timestamp-microsecond';
196
- case TimestampNanosecond:
152
+ case arrow.TimestampNanosecond:
197
153
  return 'timestamp-nanosecond';
198
- case Interval:
199
- const intervalUnit = (arrowType as Interval).unit;
154
+ case arrow.Interval:
155
+ const intervalUnit = (arrowType as arrow.Interval).unit;
200
156
  switch (intervalUnit) {
201
- case IntervalUnit.DAY_TIME:
157
+ case arrow.IntervalUnit.DAY_TIME:
202
158
  return 'interval-daytime';
203
- case IntervalUnit.YEAR_MONTH:
159
+ case arrow.IntervalUnit.YEAR_MONTH:
204
160
  return 'interval-yearmonth';
205
161
  default:
206
162
  return 'interval-daytime';
207
163
  }
208
- case IntervalDayTime:
164
+ case arrow.IntervalDayTime:
209
165
  return 'interval-daytime';
210
- case IntervalYearMonth:
166
+ case arrow.IntervalYearMonth:
211
167
  return 'interval-yearmonth';
212
- case List:
213
- const listType = arrowType as List;
168
+ case arrow.List:
169
+ const listType = arrowType as arrow.List;
214
170
  const listField = listType.valueField;
215
171
  return {
216
172
  type: 'list',
217
173
  children: [serializeArrowField(listField)]
218
174
  };
219
- case FixedSizeList:
175
+ case arrow.FixedSizeList:
220
176
  return {
221
177
  type: 'fixed-size-list',
222
- listSize: (arrowType as FixedSizeList).listSize,
223
- children: [serializeArrowField((arrowType as FixedSizeList).children[0])]
178
+ listSize: (arrowType as arrow.FixedSizeList).listSize,
179
+ children: [serializeArrowField((arrowType as arrow.FixedSizeList).children[0])]
224
180
  };
225
- // case Struct:
226
- // return {type: 'struct', children: (arrowType as Struct).children};
181
+ // case arrow.Struct:
182
+ // return {type: 'struct', children: (arrowType as arrow.Struct).children};
227
183
  default:
228
184
  throw new Error('array type not supported');
229
185
  }
@@ -231,18 +187,18 @@ export function serializeArrowType(arrowType: ArrowDataType): DataType {
231
187
 
232
188
  /** Converts a serializable loaders.gl data type to hydrated arrow data type */
233
189
  // eslint-disable-next-line complexity
234
- export function deserializeArrowType(dataType: DataType): ArrowDataType {
190
+ export function deserializeArrowType(dataType: DataType): arrow.DataType {
235
191
  if (typeof dataType === 'object') {
236
192
  switch (dataType.type) {
237
193
  case 'list':
238
194
  const field = deserializeArrowField(dataType.children[0]);
239
- return new List(field);
195
+ return new arrow.List(field);
240
196
  case 'fixed-size-list':
241
197
  const child = deserializeArrowField(dataType.children[0]);
242
- return new FixedSizeList(dataType.listSize, child);
198
+ return new arrow.FixedSizeList(dataType.listSize, child);
243
199
  case 'struct':
244
200
  const children = dataType.children.map((arrowField) => deserializeArrowField(arrowField));
245
- return new Struct(children);
201
+ return new arrow.Struct(children);
246
202
  default:
247
203
  throw new Error('array type not supported');
248
204
  }
@@ -250,59 +206,59 @@ export function deserializeArrowType(dataType: DataType): ArrowDataType {
250
206
 
251
207
  switch (dataType) {
252
208
  case 'null':
253
- return new Null();
209
+ return new arrow.Null();
254
210
  case 'binary':
255
- return new Binary();
211
+ return new arrow.Binary();
256
212
  case 'bool':
257
- return new Bool();
213
+ return new arrow.Bool();
258
214
  case 'int8':
259
- return new Int8();
215
+ return new arrow.Int8();
260
216
  case 'int16':
261
- return new Int16();
217
+ return new arrow.Int16();
262
218
  case 'int32':
263
- return new Int32();
219
+ return new arrow.Int32();
264
220
  case 'int64':
265
- return new Int64();
221
+ return new arrow.Int64();
266
222
  case 'uint8':
267
- return new Uint8();
223
+ return new arrow.Uint8();
268
224
  case 'uint16':
269
- return new Uint16();
225
+ return new arrow.Uint16();
270
226
  case 'uint32':
271
- return new Uint32();
227
+ return new arrow.Uint32();
272
228
  case 'uint64':
273
- return new Uint64();
229
+ return new arrow.Uint64();
274
230
  case 'float16':
275
- return new Float16();
231
+ return new arrow.Float16();
276
232
  case 'float32':
277
- return new Float32();
233
+ return new arrow.Float32();
278
234
  case 'float64':
279
- return new Float64();
235
+ return new arrow.Float64();
280
236
  case 'utf8':
281
- return new Utf8();
237
+ return new arrow.Utf8();
282
238
  case 'date-day':
283
- return new DateDay();
239
+ return new arrow.DateDay();
284
240
  case 'date-millisecond':
285
- return new DateMillisecond();
241
+ return new arrow.DateMillisecond();
286
242
  case 'time-second':
287
- return new TimeSecond();
243
+ return new arrow.TimeSecond();
288
244
  case 'time-millisecond':
289
- return new TimeMillisecond();
245
+ return new arrow.TimeMillisecond();
290
246
  case 'time-microsecond':
291
- return new TimeMicrosecond();
247
+ return new arrow.TimeMicrosecond();
292
248
  case 'time-nanosecond':
293
- return new TimeNanosecond();
249
+ return new arrow.TimeNanosecond();
294
250
  case 'timestamp-second':
295
- return new TimestampSecond();
251
+ return new arrow.TimestampSecond();
296
252
  case 'timestamp-millisecond':
297
- return new TimestampMillisecond();
253
+ return new arrow.TimestampMillisecond();
298
254
  case 'timestamp-microsecond':
299
- return new TimestampMicrosecond();
255
+ return new arrow.TimestampMicrosecond();
300
256
  case 'timestamp-nanosecond':
301
- return new TimestampNanosecond();
257
+ return new arrow.TimestampNanosecond();
302
258
  case 'interval-daytime':
303
- return new IntervalDayTime();
259
+ return new arrow.IntervalDayTime();
304
260
  case 'interval-yearmonth':
305
- return new IntervalYearMonth();
261
+ return new arrow.IntervalYearMonth();
306
262
  default:
307
263
  throw new Error('array type not supported');
308
264
  }
@@ -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