@uwdata/mosaic-core 0.10.0 → 0.11.0
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/mosaic-core.js +5951 -15206
- package/dist/mosaic-core.min.js +6 -15
- package/package.json +7 -7
- package/src/Coordinator.js +56 -31
- package/src/DataCubeIndexer.js +82 -24
- package/src/MosaicClient.js +9 -0
- package/src/QueryConsolidator.js +13 -9
- package/src/QueryManager.js +9 -3
- package/src/Selection.js +41 -10
- package/src/connectors/rest.js +3 -3
- package/src/connectors/socket.js +4 -3
- package/src/connectors/wasm.js +20 -4
- package/src/index.js +3 -8
- package/src/util/decode-ipc.js +11 -0
- package/src/util/field-info.js +3 -11
- package/src/util/index-columns.js +69 -72
- package/src/util/is-arrow-table.js +10 -0
- package/src/util/priority-queue.js +75 -76
- package/src/util/throttle.js +11 -1
- package/src/util/to-data-columns.js +4 -15
- package/src/util/convert-arrow.js +0 -145
package/src/util/throttle.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
const NIL = {};
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Throttle invocations of a callback function. The callback must return
|
|
5
|
+
* a Promise. Upon repeated invocation, the callback will not be invoked
|
|
6
|
+
* until a prior Promise resolves. If multiple invocations occurs while
|
|
7
|
+
* waiting, only the most recent invocation will be pending.
|
|
8
|
+
* @param {(event: *) => Promise} callback The callback function.
|
|
9
|
+
* @param {boolean} [debounce=true] Flag indicating if invocations
|
|
10
|
+
* should also be debounced within the current animation frame.
|
|
11
|
+
* @returns A new function that throttles access to the callback.
|
|
12
|
+
*/
|
|
3
13
|
export function throttle(callback, debounce = false) {
|
|
4
14
|
let curr;
|
|
5
15
|
let next;
|
|
6
16
|
let pending = NIL;
|
|
7
17
|
|
|
8
18
|
function invoke(event) {
|
|
9
|
-
curr = callback(event).
|
|
19
|
+
curr = callback(event).finally(() => {
|
|
10
20
|
if (next) {
|
|
11
21
|
const { value } = next;
|
|
12
22
|
next = null;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isArrowTable } from './is-arrow-table.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @typedef {Array | Int8Array | Uint8Array | Uint8ClampedArray
|
|
@@ -27,23 +27,12 @@ export function toDataColumns(data) {
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Convert an Arrow table to a set of column arrays.
|
|
30
|
-
* @param {import('
|
|
30
|
+
* @param {import('@uwdata/flechette').Table} data An Arrow Table.
|
|
31
31
|
* @returns {DataColumns} An object with named column arrays.
|
|
32
32
|
*/
|
|
33
33
|
function arrowToColumns(data) {
|
|
34
|
-
const { numRows
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
for (let col = 0; col < numCols; ++col) {
|
|
38
|
-
const name = fields[col].name;
|
|
39
|
-
if (columns[name]) {
|
|
40
|
-
console.warn(`Redundant column name "${name}". Skipping...`);
|
|
41
|
-
} else {
|
|
42
|
-
columns[name] = convertArrowColumn(data.getChildAt(col));
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return { numRows, columns };
|
|
34
|
+
const { numRows } = data;
|
|
35
|
+
return { numRows, columns: data.toColumns() };
|
|
47
36
|
}
|
|
48
37
|
|
|
49
38
|
/**
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { DataType } from 'apache-arrow';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {import('apache-arrow').Vector} Vector
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Test if a value is an Apache Arrow table.
|
|
9
|
-
* As sometimes multiple Arrow versions may be used simultaneously,
|
|
10
|
-
* we use a "duck typing" approach and check for a getChild function.
|
|
11
|
-
* @param {*} values The value to test
|
|
12
|
-
* @returns {values is import('apache-arrow').Table} true if the value duck types as Apache Arrow data
|
|
13
|
-
*/
|
|
14
|
-
export function isArrowTable(values) {
|
|
15
|
-
return typeof values?.getChild === 'function';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Return a JavaScript array type for an Apache Arrow column type.
|
|
20
|
-
* @param {DataType} type an Apache Arrow column type
|
|
21
|
-
* @returns a JavaScript array constructor
|
|
22
|
-
*/
|
|
23
|
-
export function convertArrowArrayType(type) {
|
|
24
|
-
return DataType.isInt(type) || DataType.isFloat(type) || DataType.isDecimal(type)
|
|
25
|
-
? Float64Array
|
|
26
|
-
: Array;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Return a function that converts Apache Arrow values to JavaScript values.
|
|
31
|
-
* Timestamps are converted to Date values.
|
|
32
|
-
* Large integers (BigInt) are converted to Float64 numbers.
|
|
33
|
-
* Fixed-point decimal values are convert to Float64 numbers.
|
|
34
|
-
* Otherwise, the default Arrow values are used.
|
|
35
|
-
* @param {DataType} type an Apache Arrow column type
|
|
36
|
-
* @returns a value conversion function
|
|
37
|
-
*/
|
|
38
|
-
export function convertArrowValue(type) {
|
|
39
|
-
// map timestamp numbers to date objects
|
|
40
|
-
if (DataType.isTimestamp(type)) {
|
|
41
|
-
return v => v == null ? v : new Date(v);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// map bigint to number
|
|
45
|
-
if (DataType.isInt(type) && type.bitWidth >= 64) {
|
|
46
|
-
return v => v == null ? v : Number(v);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// map decimal to number
|
|
50
|
-
if (DataType.isDecimal(type)) {
|
|
51
|
-
const scale = 1 / Math.pow(10, type.scale);
|
|
52
|
-
return v => v == null ? v : decimalToNumber(v, scale);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// otherwise use Arrow JS defaults
|
|
56
|
-
return v => v;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Convert an Apache Arrow column to a JavaScript array.
|
|
61
|
-
* Timestamps are converted to Date values.
|
|
62
|
-
* Large integers (BigInt) are converted to Float64 numbers.
|
|
63
|
-
* Fixed-point decimal values are convert to Float64 numbers.
|
|
64
|
-
* Otherwise, the default Arrow values are used.
|
|
65
|
-
* @param {Vector} column An Apache Arrow column
|
|
66
|
-
* @returns an array of values
|
|
67
|
-
*/
|
|
68
|
-
export function convertArrowColumn(column) {
|
|
69
|
-
const { type } = column;
|
|
70
|
-
|
|
71
|
-
// map timestamp numbers to date objects
|
|
72
|
-
if (DataType.isTimestamp(type)) {
|
|
73
|
-
const size = column.length;
|
|
74
|
-
const array = new Array(size);
|
|
75
|
-
for (let row = 0; row < size; ++row) {
|
|
76
|
-
const v = column.get(row);
|
|
77
|
-
array[row] = v == null ? null : new Date(v);
|
|
78
|
-
}
|
|
79
|
-
return array;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// map bigint to number
|
|
83
|
-
if (DataType.isInt(type) && type.bitWidth >= 64) {
|
|
84
|
-
const size = column.length;
|
|
85
|
-
const array = column.nullCount ? new Array(size) : new Float64Array(size);
|
|
86
|
-
for (let row = 0; row < size; ++row) {
|
|
87
|
-
const v = column.get(row);
|
|
88
|
-
array[row] = v == null ? null : Number(v);
|
|
89
|
-
}
|
|
90
|
-
return array;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// map decimal to number
|
|
94
|
-
if (DataType.isDecimal(type)) {
|
|
95
|
-
const scale = 1 / Math.pow(10, type.scale);
|
|
96
|
-
const size = column.length;
|
|
97
|
-
const array = column.nullCount ? new Array(size) : new Float64Array(size);
|
|
98
|
-
for (let row = 0; row < size; ++row) {
|
|
99
|
-
const v = column.get(row);
|
|
100
|
-
array[row] = v == null ? null : decimalToNumber(v, scale);
|
|
101
|
-
}
|
|
102
|
-
return array;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// if there are null values, use a standard array
|
|
106
|
-
if (column.nullCount) {
|
|
107
|
-
return Array.from(column);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// otherwise use Arrow JS defaults
|
|
111
|
-
return column.toArray();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// generate base values for big integers
|
|
115
|
-
// represented within a Uint32Array
|
|
116
|
-
const BASE32 = Array.from(
|
|
117
|
-
{ length: 8 },
|
|
118
|
-
(_, i) => Math.pow(2, i * 32)
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Convert a fixed point decimal value to a double precision number.
|
|
123
|
-
* Note: if the value is sufficiently large the conversion may be lossy!
|
|
124
|
-
* @param {Uint32Array & { signed: boolean }} v a fixed decimal value
|
|
125
|
-
* @param {number} scale a scale factor, corresponding to the
|
|
126
|
-
* number of fractional decimal digits in the fixed point value
|
|
127
|
-
* @returns {number} the resulting number
|
|
128
|
-
*/
|
|
129
|
-
function decimalToNumber(v, scale) {
|
|
130
|
-
const n = v.length;
|
|
131
|
-
let x = 0;
|
|
132
|
-
|
|
133
|
-
if (v.signed && (v[n - 1] | 0) < 0) {
|
|
134
|
-
for (let i = 0; i < n; ++i) {
|
|
135
|
-
x += ~v[i] * BASE32[i];
|
|
136
|
-
}
|
|
137
|
-
x = -(x + 1);
|
|
138
|
-
} else {
|
|
139
|
-
for (let i = 0; i < n; ++i) {
|
|
140
|
-
x += v[i] * BASE32[i];
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return x * scale;
|
|
145
|
-
}
|