@loaders.gl/schema-utils 4.4.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +41 -0
- package/README.md +9 -0
- package/dist/dist.dev.js +14269 -0
- package/dist/dist.min.js +18 -0
- package/dist/index.cjs +2436 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-fixed-size-list-utils.js +40 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts +11 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.d.ts.map +1 -0
- package/dist/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.js +32 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts +18 -0
- package/dist/lib/mesh/convert-mesh-to-table.d.ts.map +1 -0
- package/dist/lib/mesh/convert-mesh-to-table.js +60 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts +7 -0
- package/dist/lib/mesh/convert-table-to-mesh.d.ts.map +1 -0
- package/dist/lib/mesh/convert-table-to-mesh.js +40 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts +23 -0
- package/dist/lib/mesh/deduce-mesh-schema.d.ts.map +1 -0
- package/dist/lib/mesh/deduce-mesh-schema.js +62 -0
- package/dist/lib/mesh/mesh-utils.d.ts +23 -0
- package/dist/lib/mesh/mesh-utils.d.ts.map +1 -0
- package/dist/lib/mesh/mesh-utils.js +46 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts +23 -0
- package/dist/lib/schema/convert-arrow-schema.d.ts.map +1 -0
- package/dist/lib/schema/convert-arrow-schema.js +280 -0
- package/dist/lib/schema/data-type.d.ts +16 -0
- package/dist/lib/schema/data-type.d.ts.map +1 -0
- package/dist/lib/schema/data-type.js +88 -0
- package/dist/lib/schema/deduce-table-schema.d.ts +14 -0
- package/dist/lib/schema/deduce-table-schema.d.ts.map +1 -0
- package/dist/lib/schema/deduce-table-schema.js +100 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts +19 -0
- package/dist/lib/table/arrow-api/arrow-like-field.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-field.js +36 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts +43 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-interface.js +4 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts +12 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-schema.js +81 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts +28 -0
- package/dist/lib/table/arrow-api/arrow-like-table.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-table.js +63 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts +177 -0
- package/dist/lib/table/arrow-api/arrow-like-type.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/arrow-like-type.js +442 -0
- package/dist/lib/table/arrow-api/enum.d.ts +92 -0
- package/dist/lib/table/arrow-api/enum.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/enum.js +97 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts +13 -0
- package/dist/lib/table/arrow-api/get-type-info.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/get-type-info.js +27 -0
- package/dist/lib/table/arrow-api/index.d.ts +5 -0
- package/dist/lib/table/arrow-api/index.d.ts.map +1 -0
- package/dist/lib/table/arrow-api/index.js +7 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts +10 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-batch-aggregator.js +67 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts +25 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/arrow-table-builder.js +99 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts +19 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/base-table-batch-aggregator.js +63 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts +20 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/columnar-table-batch-aggregator.js +83 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts +21 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/row-table-batch-aggregator.js +85 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts +24 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-aggregator.js +4 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts +52 -0
- package/dist/lib/table/batch-builder/table-batch-builder.d.ts.map +1 -0
- package/dist/lib/table/batch-builder/table-batch-builder.js +148 -0
- package/dist/lib/table/batches/convert-batches.d.ts +10 -0
- package/dist/lib/table/batches/convert-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/convert-batches.js +45 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts +17 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-arrow-batch-iterator.js +57 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts +15 -0
- package/dist/lib/table/batches/make-table-batch-iterator.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-batch-iterator.js +21 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts +9 -0
- package/dist/lib/table/batches/make-table-from-batches.d.ts.map +1 -0
- package/dist/lib/table/batches/make-table-from-batches.js +62 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts +24 -0
- package/dist/lib/table/tables/convert-arrow-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-arrow-table.js +150 -0
- package/dist/lib/table/tables/convert-table.d.ts +43 -0
- package/dist/lib/table/tables/convert-table.d.ts.map +1 -0
- package/dist/lib/table/tables/convert-table.js +120 -0
- package/dist/lib/table/tables/make-table.d.ts +67 -0
- package/dist/lib/table/tables/make-table.d.ts.map +1 -0
- package/dist/lib/table/tables/make-table.js +101 -0
- package/dist/lib/table/tables/row-utils.d.ts +15 -0
- package/dist/lib/table/tables/row-utils.d.ts.map +1 -0
- package/dist/lib/table/tables/row-utils.js +49 -0
- package/dist/lib/table/tables/table-accessors.d.ts +68 -0
- package/dist/lib/table/tables/table-accessors.d.ts.map +1 -0
- package/dist/lib/table/tables/table-accessors.js +350 -0
- package/dist/lib/table/tables/table-column.d.ts +7 -0
- package/dist/lib/table/tables/table-column.d.ts.map +1 -0
- package/dist/lib/table/tables/table-column.js +39 -0
- package/dist/lib/table/tables/table-types.d.ts +12 -0
- package/dist/lib/table/tables/table-types.d.ts.map +1 -0
- package/dist/lib/table/tables/table-types.js +23 -0
- package/dist/lib/utils/assert.d.ts +2 -0
- package/dist/lib/utils/assert.d.ts.map +1 -0
- package/dist/lib/utils/assert.js +8 -0
- package/dist/lib/utils/async-queue.d.ts +18 -0
- package/dist/lib/utils/async-queue.d.ts.map +1 -0
- package/dist/lib/utils/async-queue.js +90 -0
- package/dist/types/types.d.ts +15 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/types.js +4 -0
- package/package.json +52 -0
- package/src/index.ts +134 -0
- package/src/lib/arrow-utils/arrow-fixed-size-list-utils.ts +63 -0
- package/src/lib/arrow-utils/arrow-list-of-fixed-size-list-utils.ts +48 -0
- package/src/lib/mesh/convert-mesh-to-table.ts +77 -0
- package/src/lib/mesh/convert-table-to-mesh.ts +49 -0
- package/src/lib/mesh/deduce-mesh-schema.ts +75 -0
- package/src/lib/mesh/mesh-utils.ts +64 -0
- package/src/lib/schema/convert-arrow-schema.ts +301 -0
- package/src/lib/schema/data-type.ts +103 -0
- package/src/lib/schema/deduce-table-schema.ts +119 -0
- package/src/lib/table/arrow-api/arrow-like-field.ts +53 -0
- package/src/lib/table/arrow-api/arrow-like-interface.ts +84 -0
- package/src/lib/table/arrow-api/arrow-like-schema.ts +101 -0
- package/src/lib/table/arrow-api/arrow-like-table.ts +85 -0
- package/src/lib/table/arrow-api/arrow-like-type.ts +502 -0
- package/src/lib/table/arrow-api/enum.ts +99 -0
- package/src/lib/table/arrow-api/get-type-info.ts +38 -0
- package/src/lib/table/arrow-api/index.ts +8 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator-builders.ts.disabled +190 -0
- package/src/lib/table/batch-builder/arrow-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/arrow-table-builder.ts +112 -0
- package/src/lib/table/batch-builder/base-table-batch-aggregator.ts +82 -0
- package/src/lib/table/batch-builder/columnar-table-batch-aggregator.ts +99 -0
- package/src/lib/table/batch-builder/row-table-batch-aggregator.ts +108 -0
- package/src/lib/table/batch-builder/table-batch-aggregator.ts +28 -0
- package/src/lib/table/batch-builder/table-batch-builder.ts +185 -0
- package/src/lib/table/batches/convert-batches.ts +83 -0
- package/src/lib/table/batches/make-arrow-batch-iterator.ts +75 -0
- package/src/lib/table/batches/make-table-batch-iterator.ts +25 -0
- package/src/lib/table/batches/make-table-from-batches.ts +84 -0
- package/src/lib/table/tables/convert-arrow-table.ts +198 -0
- package/src/lib/table/tables/convert-table.ts +151 -0
- package/src/lib/table/tables/make-table.ts +127 -0
- package/src/lib/table/tables/row-utils.ts +59 -0
- package/src/lib/table/tables/table-accessors.ts +417 -0
- package/src/lib/table/tables/table-column.ts +49 -0
- package/src/lib/table/tables/table-types.ts +37 -0
- package/src/lib/utils/assert.ts +8 -0
- package/src/lib/utils/async-queue.ts +104 -0
- package/src/types/types.ts +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/arrow-api/enum.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,oBAAY,IAAI;IACd,mCAAmC;IACnC,IAAI,IAAI;IACR,6CAA6C;IAC7C,IAAI,IAAI;IACR,oEAAoE;IACpE,GAAG,IAAI;IACP,2CAA2C;IAC3C,KAAK,IAAI;IACT,wDAAwD;IACxD,MAAM,IAAI;IACV,gDAAgD;IAChD,IAAI,IAAI;IACR,gDAAgD;IAChD,IAAI,IAAI;IACR,sFAAsF;IACtF,OAAO,IAAI;IACX,gEAAgE;IAChE,IAAI,IAAI;IACR,iJAAiJ;IACjJ,IAAI,IAAI;IACR,qFAAqF;IACrF,SAAS,KAAK;IACd,mDAAmD;IACnD,QAAQ,KAAK;IACb,uCAAuC;IACvC,IAAI,KAAK;IACT,8BAA8B;IAC9B,MAAM,KAAK;IACX,6BAA6B;IAC7B,KAAK,KAAK;IACV,sEAAsE;IACtE,eAAe,KAAK;IACpB,oEAAoE;IACpE,aAAa,KAAK;IAClB,iCAAiC;IACjC,GAAG,KAAK;IAER,mCAAmC;IACnC,UAAU,KAAK;IACf,IAAI,KAAK;IACT,KAAK,KAAK;IACV,KAAK,KAAK;IACV,KAAK,KAAK;IACV,KAAK,KAAK;IACV,MAAM,KAAK;IACX,MAAM,KAAK;IACX,MAAM,KAAK;IACX,OAAO,MAAM;IACb,OAAO,MAAM;IACb,OAAO,MAAM;IACb,OAAO,MAAM;IACb,eAAe,MAAM;IACrB,eAAe,MAAM;IACrB,oBAAoB,MAAM;IAC1B,oBAAoB,MAAM;IAC1B,mBAAmB,MAAM;IACzB,UAAU,MAAM;IAChB,eAAe,MAAM;IACrB,eAAe,MAAM;IACrB,cAAc,MAAM;IACpB,UAAU,MAAM;IAChB,WAAW,MAAM;IACjB,eAAe,MAAM;IACrB,iBAAiB,MAAM;CACxB"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
// This code is adapted from ArrowJS https://github.com/apache/arrow
|
|
5
|
+
// under Apache license http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
/**
|
|
7
|
+
* Main data type enumeration.
|
|
8
|
+
*
|
|
9
|
+
* Data types in this library are all *logical*. They can be expressed as
|
|
10
|
+
* either a primitive physical type (bytes or bits of some fixed size), a
|
|
11
|
+
* nested type consisting of other data types, or another data type (e.g. a
|
|
12
|
+
* timestamp encoded as an int64).
|
|
13
|
+
*
|
|
14
|
+
* **Note**: Only enum values 0-17 (NONE through Map) are written to an Arrow
|
|
15
|
+
* IPC payload.
|
|
16
|
+
*
|
|
17
|
+
* The rest of the values are specified here so TypeScript can narrow the type
|
|
18
|
+
* signatures further beyond the base Arrow Types. The Arrow DataTypes include
|
|
19
|
+
* metadata like `bitWidth` that impact the type signatures of the values we
|
|
20
|
+
* accept and return.
|
|
21
|
+
*
|
|
22
|
+
* For example, the `Int8Vector` reads 1-byte numbers from an `Int8Array`, an
|
|
23
|
+
* `Int32Vector` reads a 4-byte number from an `Int32Array`, and an `Int64Vector`
|
|
24
|
+
* reads a pair of 4-byte lo, hi 32-bit integers as a zero-copy slice from the
|
|
25
|
+
* underlying `Int32Array`.
|
|
26
|
+
*
|
|
27
|
+
* Library consumers benefit by knowing the narrowest type, since we can ensure
|
|
28
|
+
* the types across all public methods are propagated, and never bail to `any`.
|
|
29
|
+
* These values are _never_ used at runtime, and they will _never_ be written
|
|
30
|
+
* to the flatbuffers metadata of serialized Arrow IPC payloads.
|
|
31
|
+
*/
|
|
32
|
+
export var Type;
|
|
33
|
+
(function (Type) {
|
|
34
|
+
/** The default placeholder type */
|
|
35
|
+
Type[Type["NONE"] = 0] = "NONE";
|
|
36
|
+
/** A NULL type having no physical storage */
|
|
37
|
+
Type[Type["Null"] = 1] = "Null";
|
|
38
|
+
/** Signed or unsigned 8, 16, 32, or 64-bit little-endian integer */
|
|
39
|
+
Type[Type["Int"] = 2] = "Int";
|
|
40
|
+
/** 2, 4, or 8-byte floating point value */
|
|
41
|
+
Type[Type["Float"] = 3] = "Float";
|
|
42
|
+
/** Variable-length bytes (no guarantee of UTF8-ness) */
|
|
43
|
+
Type[Type["Binary"] = 4] = "Binary";
|
|
44
|
+
/** UTF8 variable-length string as List<Char> */
|
|
45
|
+
Type[Type["Utf8"] = 5] = "Utf8";
|
|
46
|
+
/** Boolean as 1 bit, LSB bit-packed ordering */
|
|
47
|
+
Type[Type["Bool"] = 6] = "Bool";
|
|
48
|
+
/** Precision-and-scale-based decimal type. Storage type depends on the parameters. */
|
|
49
|
+
Type[Type["Decimal"] = 7] = "Decimal";
|
|
50
|
+
/** int32_t days or int64_t milliseconds since the UNIX epoch */
|
|
51
|
+
Type[Type["Date"] = 8] = "Date";
|
|
52
|
+
/** Time as signed 32 or 64-bit integer, representing either seconds, milliseconds, microseconds, or nanoseconds since midnight since midnight */
|
|
53
|
+
Type[Type["Time"] = 9] = "Time";
|
|
54
|
+
/** Exact timestamp encoded with int64 since UNIX epoch (Default unit millisecond) */
|
|
55
|
+
Type[Type["Timestamp"] = 10] = "Timestamp";
|
|
56
|
+
/** YEAR_MONTH or DAY_TIME interval in SQL style */
|
|
57
|
+
Type[Type["Interval"] = 11] = "Interval";
|
|
58
|
+
/** A list of some logical data type */
|
|
59
|
+
Type[Type["List"] = 12] = "List";
|
|
60
|
+
/** Struct of logical types */
|
|
61
|
+
Type[Type["Struct"] = 13] = "Struct";
|
|
62
|
+
/** Union of logical types */
|
|
63
|
+
Type[Type["Union"] = 14] = "Union";
|
|
64
|
+
/** Fixed-size binary. Each value occupies the same number of bytes */
|
|
65
|
+
Type[Type["FixedSizeBinary"] = 15] = "FixedSizeBinary";
|
|
66
|
+
/** Fixed-size list. Each value occupies the same number of bytes */
|
|
67
|
+
Type[Type["FixedSizeList"] = 16] = "FixedSizeList";
|
|
68
|
+
/** Map of named logical types */
|
|
69
|
+
Type[Type["Map"] = 17] = "Map";
|
|
70
|
+
/** Dictionary aka Category type */
|
|
71
|
+
Type[Type["Dictionary"] = -1] = "Dictionary";
|
|
72
|
+
Type[Type["Int8"] = -2] = "Int8";
|
|
73
|
+
Type[Type["Int16"] = -3] = "Int16";
|
|
74
|
+
Type[Type["Int32"] = -4] = "Int32";
|
|
75
|
+
Type[Type["Int64"] = -5] = "Int64";
|
|
76
|
+
Type[Type["Uint8"] = -6] = "Uint8";
|
|
77
|
+
Type[Type["Uint16"] = -7] = "Uint16";
|
|
78
|
+
Type[Type["Uint32"] = -8] = "Uint32";
|
|
79
|
+
Type[Type["Uint64"] = -9] = "Uint64";
|
|
80
|
+
Type[Type["Float16"] = -10] = "Float16";
|
|
81
|
+
Type[Type["Float32"] = -11] = "Float32";
|
|
82
|
+
Type[Type["Float64"] = -12] = "Float64";
|
|
83
|
+
Type[Type["DateDay"] = -13] = "DateDay";
|
|
84
|
+
Type[Type["DateMillisecond"] = -14] = "DateMillisecond";
|
|
85
|
+
Type[Type["TimestampSecond"] = -15] = "TimestampSecond";
|
|
86
|
+
Type[Type["TimestampMillisecond"] = -16] = "TimestampMillisecond";
|
|
87
|
+
Type[Type["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
|
|
88
|
+
Type[Type["TimestampNanosecond"] = -18] = "TimestampNanosecond";
|
|
89
|
+
Type[Type["TimeSecond"] = -19] = "TimeSecond";
|
|
90
|
+
Type[Type["TimeMillisecond"] = -20] = "TimeMillisecond";
|
|
91
|
+
Type[Type["TimeMicrosecond"] = -21] = "TimeMicrosecond";
|
|
92
|
+
Type[Type["TimeNanosecond"] = -22] = "TimeNanosecond";
|
|
93
|
+
Type[Type["DenseUnion"] = -23] = "DenseUnion";
|
|
94
|
+
Type[Type["SparseUnion"] = -24] = "SparseUnion";
|
|
95
|
+
Type[Type["IntervalDayTime"] = -25] = "IntervalDayTime";
|
|
96
|
+
Type[Type["IntervalYearMonth"] = -26] = "IntervalYearMonth";
|
|
97
|
+
})(Type || (Type = {}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Type } from "./arrow-like-type.js";
|
|
2
|
+
/**
|
|
3
|
+
* Gets type information from an Arrow type object or "mock" Arrow type object
|
|
4
|
+
* @param arrowTypeLike Arrow Type or type object of similar shape
|
|
5
|
+
*/
|
|
6
|
+
export declare function getTypeInfo(arrowTypeLike: any): {
|
|
7
|
+
typeId: Type;
|
|
8
|
+
ArrayType: ArrayLike<unknown>;
|
|
9
|
+
typeName: string;
|
|
10
|
+
typeEnumName?: string;
|
|
11
|
+
precision?: number;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=get-type-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-type-info.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/arrow-api/get-type-info.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,IAAI,EAAC,6BAA0B;AAEvC;;;GAGG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,GAAG,GAAG;IAC/C,MAAM,EAAE,IAAI,CAAC;IACb,SAAS,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAQA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Type } from "./arrow-like-type.js";
|
|
5
|
+
/**
|
|
6
|
+
* Gets type information from an Arrow type object or "mock" Arrow type object
|
|
7
|
+
* @param arrowTypeLike Arrow Type or type object of similar shape
|
|
8
|
+
*/
|
|
9
|
+
export function getTypeInfo(arrowTypeLike) {
|
|
10
|
+
return {
|
|
11
|
+
typeId: arrowTypeLike.typeId,
|
|
12
|
+
ArrayType: arrowTypeLike.ArrayType,
|
|
13
|
+
typeName: arrowTypeLike.toString(),
|
|
14
|
+
typeEnumName: getTypeKey(arrowTypeLike.typeId),
|
|
15
|
+
precision: arrowTypeLike.precision
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
let ReverseType = null;
|
|
19
|
+
function getTypeKey(typeKey) {
|
|
20
|
+
if (!ReverseType) {
|
|
21
|
+
ReverseType = {};
|
|
22
|
+
for (const key in Type) {
|
|
23
|
+
ReverseType[Type[key]] = key;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return ReverseType[typeKey];
|
|
27
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { ArrowLikeField as Field } from "./arrow-like-field.js";
|
|
2
|
+
export { ArrowLikeSchema as Schema } from "./arrow-like-schema.js";
|
|
3
|
+
export { ArrowLikeTable as Table } from "./arrow-like-table.js";
|
|
4
|
+
export * from "./arrow-like-type.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/arrow-api/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,cAAc,IAAI,KAAK,EAAC,8BAA2B;AAC3D,OAAO,EAAC,eAAe,IAAI,MAAM,EAAC,+BAA4B;AAC9D,OAAO,EAAC,cAAc,IAAI,KAAK,EAAC,8BAA2B;AAC3D,qCAAkC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export { ArrowLikeField as Field } from "./arrow-like-field.js";
|
|
5
|
+
export { ArrowLikeSchema as Schema } from "./arrow-like-schema.js";
|
|
6
|
+
export { ArrowLikeTable as Table } from "./arrow-like-table.js";
|
|
7
|
+
export * from "./arrow-like-type.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ArrowTableBatch } from '@loaders.gl/schema';
|
|
2
|
+
import { ColumnarTableBatchAggregator } from "./columnar-table-batch-aggregator.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-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-table-batch-aggregator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batch-builder/arrow-table-batch-aggregator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAC,4BAA4B,EAAC,6CAA0C;AAC/E,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"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { ColumnarTableBatchAggregator } from "./columnar-table-batch-aggregator.js";
|
|
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
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Schema, ArrowTable, ArrowTableBatch } from '@loaders.gl/schema';
|
|
2
|
+
import * as arrow from 'apache-arrow';
|
|
3
|
+
/** Builds an arrow table or batches */
|
|
4
|
+
export declare class ArrowTableBuilder {
|
|
5
|
+
schema: Schema;
|
|
6
|
+
arrowSchema: arrow.Schema;
|
|
7
|
+
arrowBuilders: arrow.Builder[];
|
|
8
|
+
length: number;
|
|
9
|
+
constructor(schema: Schema);
|
|
10
|
+
addObjectRow(row: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}): void;
|
|
13
|
+
addArrayRow(row: any[]): void;
|
|
14
|
+
/** Makes sure that a first batch with schema is sent even if no rows */
|
|
15
|
+
firstBatch(): ArrowTableBatch | null;
|
|
16
|
+
/** Flush the current batch if conditions are right */
|
|
17
|
+
flushBatch(): ArrowTableBatch | null;
|
|
18
|
+
/** Get a last batch if any data is left */
|
|
19
|
+
finishBatch(): ArrowTableBatch | null;
|
|
20
|
+
/** Return a table with all the accumulated data */
|
|
21
|
+
finishTable(): ArrowTable;
|
|
22
|
+
/** Extract a record batch flushing the currently accumulated data in the builders */
|
|
23
|
+
_getArrowRecordBatch(): arrow.RecordBatch;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=arrow-table-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arrow-table-builder.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batch-builder/arrow-table-builder.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,uCAAuC;AACvC,qBAAa,iBAAiB;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC;IAC1B,aAAa,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;gBAEH,MAAM,EAAE,MAAM;IAS1B,YAAY,CAAC,GAAG,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC;IAYtC,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;IAOtB,wEAAwE;IACxE,UAAU,IAAI,eAAe,GAAG,IAAI;IAepC,sDAAsD;IACtD,UAAU,IAAI,eAAe,GAAG,IAAI;IAcpC,2CAA2C;IAC3C,WAAW,IAAI,eAAe,GAAG,IAAI;IAerC,mDAAmD;IACnD,WAAW,IAAI,UAAU;IAUzB,qFAAqF;IACrF,oBAAoB,IAAI,KAAK,CAAC,WAAW;CAS1C"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import * as arrow from 'apache-arrow';
|
|
5
|
+
import { convertSchemaToArrow } from '@loaders.gl/schema-utils';
|
|
6
|
+
/** Builds an arrow table or batches */
|
|
7
|
+
export class ArrowTableBuilder {
|
|
8
|
+
schema;
|
|
9
|
+
arrowSchema;
|
|
10
|
+
arrowBuilders;
|
|
11
|
+
length;
|
|
12
|
+
constructor(schema) {
|
|
13
|
+
this.schema = schema;
|
|
14
|
+
this.arrowSchema = convertSchemaToArrow(schema);
|
|
15
|
+
this.arrowBuilders = this.arrowSchema.fields.map((field) => arrow.makeBuilder({ type: field.type, nullValues: [null] }));
|
|
16
|
+
this.length = 0;
|
|
17
|
+
}
|
|
18
|
+
addObjectRow(row) {
|
|
19
|
+
for (let i = 0; i < this.arrowBuilders.length; i++) {
|
|
20
|
+
const columnName = this.schema.fields[i].name;
|
|
21
|
+
const value = row[columnName];
|
|
22
|
+
// if (this.schema.fields[i].type.toString() === 'bool') {
|
|
23
|
+
// debugger;
|
|
24
|
+
// }
|
|
25
|
+
this.arrowBuilders[i].append(value);
|
|
26
|
+
}
|
|
27
|
+
this.length++;
|
|
28
|
+
}
|
|
29
|
+
addArrayRow(row) {
|
|
30
|
+
for (let i = 0; i < this.arrowBuilders.length; i++) {
|
|
31
|
+
this.arrowBuilders[i].append(row[i]);
|
|
32
|
+
}
|
|
33
|
+
this.length++;
|
|
34
|
+
}
|
|
35
|
+
/** Makes sure that a first batch with schema is sent even if no rows */
|
|
36
|
+
firstBatch() {
|
|
37
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
38
|
+
// If there is data, a batch will be sent later
|
|
39
|
+
if (arrowRecordBatch.numCols !== 0) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
shape: 'arrow-table',
|
|
44
|
+
batchType: 'data',
|
|
45
|
+
length: arrowRecordBatch.numRows,
|
|
46
|
+
schema: this.schema,
|
|
47
|
+
data: new arrow.Table(arrowRecordBatch)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Flush the current batch if conditions are right */
|
|
51
|
+
flushBatch() {
|
|
52
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
53
|
+
if (arrowRecordBatch.numCols === 0) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
shape: 'arrow-table',
|
|
58
|
+
batchType: 'data',
|
|
59
|
+
length: arrowRecordBatch.numRows,
|
|
60
|
+
schema: this.schema,
|
|
61
|
+
data: new arrow.Table(arrowRecordBatch)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** Get a last batch if any data is left */
|
|
65
|
+
finishBatch() {
|
|
66
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
67
|
+
this.arrowBuilders.forEach((builder) => builder.finish());
|
|
68
|
+
if (arrowRecordBatch.numCols === 0) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
shape: 'arrow-table',
|
|
73
|
+
batchType: 'data',
|
|
74
|
+
length: arrowRecordBatch.numRows,
|
|
75
|
+
schema: this.schema,
|
|
76
|
+
data: new arrow.Table(arrowRecordBatch)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/** Return a table with all the accumulated data */
|
|
80
|
+
finishTable() {
|
|
81
|
+
const arrowRecordBatch = this._getArrowRecordBatch();
|
|
82
|
+
this.arrowBuilders.forEach((builder) => builder.finish());
|
|
83
|
+
return {
|
|
84
|
+
shape: 'arrow-table',
|
|
85
|
+
schema: this.schema,
|
|
86
|
+
data: new arrow.Table(arrowRecordBatch)
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/** Extract a record batch flushing the currently accumulated data in the builders */
|
|
90
|
+
_getArrowRecordBatch() {
|
|
91
|
+
const { arrowBuilders, arrowSchema } = this;
|
|
92
|
+
const arrowDatas = arrowBuilders.map((builder) => builder.flush());
|
|
93
|
+
const length = arrowDatas[0].length;
|
|
94
|
+
const structField = new arrow.Struct(arrowSchema.fields);
|
|
95
|
+
const arrowStructData = new arrow.Data(structField, 0, length, 0, undefined, arrowDatas);
|
|
96
|
+
const arrowRecordBatch = new arrow.RecordBatch(arrowSchema, arrowStructData);
|
|
97
|
+
return arrowRecordBatch;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Schema, TableBatch } from '@loaders.gl/schema';
|
|
2
|
+
import { TableBatchAggregator, TableBatchOptions } from "./table-batch-aggregator.js";
|
|
3
|
+
export declare class BaseTableBatchAggregator implements TableBatchAggregator {
|
|
4
|
+
schema: Schema;
|
|
5
|
+
options: TableBatchOptions;
|
|
6
|
+
shape?: 'array-row-table' | 'object-row-table';
|
|
7
|
+
length: number;
|
|
8
|
+
rows: any[] | null;
|
|
9
|
+
cursor: number;
|
|
10
|
+
private _headers;
|
|
11
|
+
constructor(schema: Schema, options: TableBatchOptions);
|
|
12
|
+
rowCount(): number;
|
|
13
|
+
addArrayRow(row: any[], cursor?: number): void;
|
|
14
|
+
addObjectRow(row: {
|
|
15
|
+
[columnName: string]: any;
|
|
16
|
+
}, cursor?: number): void;
|
|
17
|
+
getBatch(): TableBatch | null;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=base-table-batch-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-table-batch-aggregator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batch-builder/base-table-batch-aggregator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,oCAAiC;AAIjF,qBAAa,wBAAyB,YAAW,oBAAoB;IACnE,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,iBAAiB,CAAC;IAE3B,KAAK,CAAC,EAAE,iBAAiB,GAAG,kBAAkB,CAAC;IAC/C,MAAM,EAAE,MAAM,CAAK;IACnB,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAQ;IAC1B,MAAM,EAAE,MAAM,CAAK;IACnB,OAAO,CAAC,QAAQ,CAAgB;gBAEpB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB;IActD,QAAQ,IAAI,MAAM;IAIlB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAY9C,YAAY,CAAC,GAAG,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAYrE,QAAQ,IAAI,UAAU,GAAG,IAAI;CAoB9B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
const DEFAULT_ROW_COUNT = 100;
|
|
5
|
+
export class BaseTableBatchAggregator {
|
|
6
|
+
schema;
|
|
7
|
+
options;
|
|
8
|
+
shape;
|
|
9
|
+
length = 0;
|
|
10
|
+
rows = null;
|
|
11
|
+
cursor = 0;
|
|
12
|
+
_headers = [];
|
|
13
|
+
constructor(schema, options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
this.schema = schema;
|
|
16
|
+
// schema is an array if there're no headers
|
|
17
|
+
// object if there are headers
|
|
18
|
+
if (!Array.isArray(schema)) {
|
|
19
|
+
this._headers = [];
|
|
20
|
+
for (const key in schema) {
|
|
21
|
+
this._headers[schema[key].index] = schema[key].name;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
rowCount() {
|
|
26
|
+
return this.length;
|
|
27
|
+
}
|
|
28
|
+
addArrayRow(row, cursor) {
|
|
29
|
+
if (Number.isFinite(cursor)) {
|
|
30
|
+
this.cursor = cursor;
|
|
31
|
+
}
|
|
32
|
+
this.shape = 'array-row-table';
|
|
33
|
+
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
34
|
+
this.rows[this.length] = row;
|
|
35
|
+
this.length++;
|
|
36
|
+
}
|
|
37
|
+
addObjectRow(row, cursor) {
|
|
38
|
+
if (Number.isFinite(cursor)) {
|
|
39
|
+
this.cursor = cursor;
|
|
40
|
+
}
|
|
41
|
+
this.shape = 'object-row-table';
|
|
42
|
+
this.rows = this.rows || new Array(DEFAULT_ROW_COUNT);
|
|
43
|
+
this.rows[this.length] = row;
|
|
44
|
+
this.length++;
|
|
45
|
+
}
|
|
46
|
+
getBatch() {
|
|
47
|
+
let rows = this.rows;
|
|
48
|
+
if (!rows) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
rows = rows.slice(0, this.length);
|
|
52
|
+
this.rows = null;
|
|
53
|
+
const batch = {
|
|
54
|
+
shape: this.shape || 'array-row-table',
|
|
55
|
+
batchType: 'data',
|
|
56
|
+
data: rows,
|
|
57
|
+
length: this.length,
|
|
58
|
+
schema: this.schema,
|
|
59
|
+
cursor: this.cursor
|
|
60
|
+
};
|
|
61
|
+
return batch;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Schema, ColumnarTableBatch, ArrowTableBatch, TypedArray } from '@loaders.gl/schema';
|
|
2
|
+
import { TableBatchAggregator } from "./table-batch-aggregator.js";
|
|
3
|
+
type ColumnarTableBatchOptions = {};
|
|
4
|
+
export declare class ColumnarTableBatchAggregator implements TableBatchAggregator {
|
|
5
|
+
schema: Schema;
|
|
6
|
+
length: number;
|
|
7
|
+
allocated: number;
|
|
8
|
+
columns: Record<string, TypedArray | Array<any>>;
|
|
9
|
+
constructor(schema: Schema, options: ColumnarTableBatchOptions);
|
|
10
|
+
rowCount(): number;
|
|
11
|
+
addArrayRow(row: any[]): void;
|
|
12
|
+
addObjectRow(row: {
|
|
13
|
+
[columnName: string]: any;
|
|
14
|
+
}): void;
|
|
15
|
+
getBatch(): ColumnarTableBatch | ArrowTableBatch | null;
|
|
16
|
+
_reallocateColumns(): void;
|
|
17
|
+
_pruneColumns(): void;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=columnar-table-batch-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"columnar-table-batch-aggregator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batch-builder/columnar-table-batch-aggregator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,kBAAkB,EAAE,eAAe,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAGhG,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAC9D,KAAK,yBAAyB,GAAG,EAAE,CAAC;AAIpC,qBAAa,4BAA6B,YAAW,oBAAoB;IACvE,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAK;IACnB,SAAS,EAAE,MAAM,CAAK;IACtB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAM;gBAE1C,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,yBAAyB;IAK9D,QAAQ,IAAI,MAAM;IAIlB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;IAWtB,YAAY,CAAC,GAAG,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,GAAG,IAAI;IASpD,QAAQ,IAAI,kBAAkB,GAAG,eAAe,GAAG,IAAI;IAgBvD,kBAAkB;IA8BlB,aAAa;CAKd"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// loaders.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { isTypedArray } from '@math.gl/types';
|
|
5
|
+
import { getArrayTypeFromDataType } from "../../schema/data-type.js";
|
|
6
|
+
const DEFAULT_ROW_COUNT = 100;
|
|
7
|
+
export class ColumnarTableBatchAggregator {
|
|
8
|
+
schema;
|
|
9
|
+
length = 0;
|
|
10
|
+
allocated = 0;
|
|
11
|
+
columns = {};
|
|
12
|
+
constructor(schema, options) {
|
|
13
|
+
this.schema = schema;
|
|
14
|
+
this._reallocateColumns();
|
|
15
|
+
}
|
|
16
|
+
rowCount() {
|
|
17
|
+
return this.length;
|
|
18
|
+
}
|
|
19
|
+
addArrayRow(row) {
|
|
20
|
+
// If user keeps pushing rows beyond batch size, reallocate
|
|
21
|
+
this._reallocateColumns();
|
|
22
|
+
let i = 0;
|
|
23
|
+
// TODO what if no csv header, columns not populated?
|
|
24
|
+
for (const fieldName in this.columns) {
|
|
25
|
+
this.columns[fieldName][this.length] = row[i++];
|
|
26
|
+
}
|
|
27
|
+
this.length++;
|
|
28
|
+
}
|
|
29
|
+
addObjectRow(row) {
|
|
30
|
+
// If user keeps pushing rows beyond batch size, reallocate
|
|
31
|
+
this._reallocateColumns();
|
|
32
|
+
for (const fieldName in row) {
|
|
33
|
+
this.columns[fieldName][this.length] = row[fieldName];
|
|
34
|
+
}
|
|
35
|
+
this.length++;
|
|
36
|
+
}
|
|
37
|
+
getBatch() {
|
|
38
|
+
this._pruneColumns();
|
|
39
|
+
const batch = {
|
|
40
|
+
shape: 'columnar-table',
|
|
41
|
+
batchType: 'data',
|
|
42
|
+
data: this.columns,
|
|
43
|
+
schema: this.schema,
|
|
44
|
+
length: this.length
|
|
45
|
+
};
|
|
46
|
+
return batch;
|
|
47
|
+
}
|
|
48
|
+
// HELPERS
|
|
49
|
+
_reallocateColumns() {
|
|
50
|
+
if (this.length < this.allocated) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
// @ts-ignore TODO
|
|
54
|
+
this.allocated = this.allocated > 0 ? (this.allocated *= 2) : DEFAULT_ROW_COUNT;
|
|
55
|
+
this.columns = {};
|
|
56
|
+
for (const field of this.schema.fields) {
|
|
57
|
+
const ArrayType = getArrayTypeFromDataType(field.type, field.nullable);
|
|
58
|
+
const oldColumn = this.columns[field.name];
|
|
59
|
+
if (!oldColumn) {
|
|
60
|
+
// Create new
|
|
61
|
+
this.columns[field.name] = new ArrayType(this.allocated);
|
|
62
|
+
}
|
|
63
|
+
else if (Array.isArray(oldColumn)) {
|
|
64
|
+
// Plain array, just increase its size
|
|
65
|
+
oldColumn.length = this.allocated;
|
|
66
|
+
}
|
|
67
|
+
else if (isTypedArray(oldColumn)) {
|
|
68
|
+
const typedArray = new ArrayType(this.allocated);
|
|
69
|
+
// Copy the old data to the new array
|
|
70
|
+
typedArray.set(oldColumn);
|
|
71
|
+
this.columns[field.name] = typedArray;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
throw new Error('Invalid column type');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
_pruneColumns() {
|
|
79
|
+
for (const [columnName, column] of Object.entries(this.columns)) {
|
|
80
|
+
this.columns[columnName] = column.slice(0, this.length);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Schema, TableBatch } from '@loaders.gl/schema';
|
|
2
|
+
import { TableBatchAggregator, TableBatchOptions } from "./table-batch-aggregator.js";
|
|
3
|
+
export declare class RowTableBatchAggregator implements TableBatchAggregator {
|
|
4
|
+
schema: Schema | null;
|
|
5
|
+
options: TableBatchOptions;
|
|
6
|
+
length: number;
|
|
7
|
+
objectRows: {
|
|
8
|
+
[columnName: string]: unknown;
|
|
9
|
+
}[] | null;
|
|
10
|
+
arrayRows: unknown[][] | null;
|
|
11
|
+
cursor: number;
|
|
12
|
+
private _headers;
|
|
13
|
+
constructor(schema: Schema | null, options: TableBatchOptions);
|
|
14
|
+
rowCount(): number;
|
|
15
|
+
addArrayRow(row: any[], cursor?: number): void;
|
|
16
|
+
addObjectRow(row: {
|
|
17
|
+
[columnName: string]: any;
|
|
18
|
+
}, cursor?: number): void;
|
|
19
|
+
getBatch(): TableBatch | null;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=row-table-batch-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"row-table-batch-aggregator.d.ts","sourceRoot":"","sources":["../../../../src/lib/table/batch-builder/row-table-batch-aggregator.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,MAAM,EAAE,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAC,oBAAoB,EAAE,iBAAiB,EAAC,oCAAiC;AAUjF,qBAAa,uBAAwB,YAAW,oBAAoB;IAClE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,OAAO,EAAE,iBAAiB,CAAC;IAE3B,MAAM,EAAE,MAAM,CAAK;IACnB,UAAU,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,EAAE,GAAG,IAAI,CAAQ;IAC5D,SAAS,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,CAAQ;IACrC,MAAM,EAAE,MAAM,CAAK;IACnB,OAAO,CAAC,QAAQ,CAAyB;gBAE7B,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,iBAAiB;IAc7D,QAAQ,IAAI,MAAM;IAIlB,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAsB9C,YAAY,CAAC,GAAG,EAAE;QAAC,CAAC,UAAU,EAAE,MAAM,GAAG,GAAG,CAAA;KAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAsBrE,QAAQ,IAAI,UAAU,GAAG,IAAI;CAoB9B"}
|