@uwdata/mosaic-core 0.17.0 → 0.19.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/LICENSE +47 -0
- package/README.md +0 -1
- package/dist/src/Coordinator.d.ts +159 -0
- package/dist/src/Coordinator.d.ts.map +1 -0
- package/dist/src/Coordinator.js +250 -0
- package/dist/src/Coordinator.js.map +1 -0
- package/dist/src/MosaicClient.d.ts +138 -0
- package/dist/src/MosaicClient.d.ts.map +1 -0
- package/dist/src/MosaicClient.js +214 -0
- package/dist/src/MosaicClient.js.map +1 -0
- package/dist/src/Param.d.ts +56 -0
- package/dist/src/Param.d.ts.map +1 -0
- package/dist/src/Param.js +89 -0
- package/dist/src/Param.js.map +1 -0
- package/dist/src/QueryConsolidator.d.ts +11 -0
- package/dist/src/QueryConsolidator.d.ts.map +1 -0
- package/dist/src/QueryConsolidator.js +249 -0
- package/dist/src/QueryConsolidator.js.map +1 -0
- package/dist/src/QueryManager.d.ts +77 -0
- package/dist/src/QueryManager.d.ts.map +1 -0
- package/dist/src/QueryManager.js +174 -0
- package/dist/src/QueryManager.js.map +1 -0
- package/dist/src/Selection.d.ts +222 -0
- package/dist/src/Selection.d.ts.map +1 -0
- package/dist/src/Selection.js +322 -0
- package/dist/src/Selection.js.map +1 -0
- package/dist/src/SelectionClause.d.ts +222 -0
- package/dist/src/SelectionClause.d.ts.map +1 -0
- package/dist/src/SelectionClause.js +168 -0
- package/dist/src/SelectionClause.js.map +1 -0
- package/dist/src/connectors/Connector.d.ts +26 -0
- package/dist/src/connectors/Connector.d.ts.map +1 -0
- package/dist/src/connectors/Connector.js +2 -0
- package/dist/src/connectors/Connector.js.map +1 -0
- package/dist/src/connectors/rest.d.ts +24 -0
- package/dist/src/connectors/rest.d.ts.map +1 -0
- package/dist/src/connectors/rest.js +37 -0
- package/dist/src/connectors/rest.js.map +1 -0
- package/dist/src/connectors/socket.d.ts +40 -0
- package/dist/src/connectors/socket.d.ts.map +1 -0
- package/dist/src/connectors/socket.js +115 -0
- package/dist/src/connectors/socket.js.map +1 -0
- package/dist/src/connectors/wasm.d.ts +56 -0
- package/dist/src/connectors/wasm.d.ts.map +1 -0
- package/dist/src/connectors/wasm.js +116 -0
- package/dist/src/connectors/wasm.js.map +1 -0
- package/dist/src/index.d.ts +28 -0
- package/dist/src/index.d.ts.map +1 -0
- package/{src → dist/src}/index.js +8 -11
- package/dist/src/index.js.map +1 -0
- package/dist/src/make-client.d.ts +33 -0
- package/dist/src/make-client.d.ts.map +1 -0
- package/dist/src/make-client.js +52 -0
- package/dist/src/make-client.js.map +1 -0
- package/dist/src/preagg/PreAggregator.d.ts +150 -0
- package/dist/src/preagg/PreAggregator.d.ts.map +1 -0
- package/dist/src/preagg/PreAggregator.js +382 -0
- package/dist/src/preagg/PreAggregator.js.map +1 -0
- package/dist/src/preagg/preagg-columns.d.ts +16 -0
- package/dist/src/preagg/preagg-columns.d.ts.map +1 -0
- package/dist/src/preagg/preagg-columns.js +95 -0
- package/dist/src/preagg/preagg-columns.js.map +1 -0
- package/dist/src/preagg/sufficient-statistics.d.ts +14 -0
- package/dist/src/preagg/sufficient-statistics.d.ts.map +1 -0
- package/dist/src/preagg/sufficient-statistics.js +446 -0
- package/dist/src/preagg/sufficient-statistics.js.map +1 -0
- package/dist/src/types.d.ts +77 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/util/AsyncDispatch.d.ts +121 -0
- package/dist/src/util/AsyncDispatch.d.ts.map +1 -0
- package/dist/src/util/AsyncDispatch.js +188 -0
- package/dist/src/util/AsyncDispatch.js.map +1 -0
- package/dist/src/util/cache.d.ts +19 -0
- package/dist/src/util/cache.d.ts.map +1 -0
- package/dist/src/util/cache.js +66 -0
- package/dist/src/util/cache.js.map +1 -0
- package/dist/src/util/decode-ipc.d.ts +12 -0
- package/dist/src/util/decode-ipc.d.ts.map +1 -0
- package/{src → dist/src}/util/decode-ipc.js +5 -6
- package/dist/src/util/decode-ipc.js.map +1 -0
- package/dist/src/util/distinct.d.ts +3 -0
- package/dist/src/util/distinct.d.ts.map +1 -0
- package/dist/src/util/distinct.js +16 -0
- package/dist/src/util/distinct.js.map +1 -0
- package/dist/src/util/field-info.d.ts +26 -0
- package/dist/src/util/field-info.d.ts.map +1 -0
- package/dist/src/util/field-info.js +91 -0
- package/dist/src/util/field-info.js.map +1 -0
- package/dist/src/util/hash.d.ts +2 -0
- package/dist/src/util/hash.d.ts.map +1 -0
- package/dist/src/util/hash.js +26 -0
- package/dist/src/util/hash.js.map +1 -0
- package/dist/src/util/is-activatable.d.ts +8 -0
- package/dist/src/util/is-activatable.d.ts.map +1 -0
- package/dist/src/util/is-activatable.js +10 -0
- package/dist/src/util/is-activatable.js.map +1 -0
- package/dist/src/util/is-arrow-table.d.ts +9 -0
- package/dist/src/util/is-arrow-table.d.ts.map +1 -0
- package/dist/src/util/is-arrow-table.js +11 -0
- package/dist/src/util/is-arrow-table.js.map +1 -0
- package/dist/src/util/js-type.d.ts +9 -0
- package/dist/src/util/js-type.d.ts.map +1 -0
- package/dist/src/util/js-type.js +59 -0
- package/dist/src/util/js-type.js.map +1 -0
- package/dist/src/util/priority-queue.d.ts +35 -0
- package/dist/src/util/priority-queue.d.ts.map +1 -0
- package/dist/src/util/priority-queue.js +81 -0
- package/dist/src/util/priority-queue.js.map +1 -0
- package/dist/src/util/query-result.d.ts +47 -0
- package/dist/src/util/query-result.d.ts.map +1 -0
- package/dist/src/util/query-result.js +83 -0
- package/dist/src/util/query-result.js.map +1 -0
- package/dist/src/util/synchronizer.d.ts +36 -0
- package/dist/src/util/synchronizer.d.ts.map +1 -0
- package/dist/src/util/synchronizer.js +52 -0
- package/dist/src/util/synchronizer.js.map +1 -0
- package/dist/src/util/throttle.d.ts +12 -0
- package/dist/src/util/throttle.d.ts.map +1 -0
- package/dist/src/util/throttle.js +51 -0
- package/dist/src/util/throttle.js.map +1 -0
- package/dist/src/util/to-data-columns.d.ts +22 -0
- package/dist/src/util/to-data-columns.d.ts.map +1 -0
- package/dist/src/util/to-data-columns.js +51 -0
- package/dist/src/util/to-data-columns.js.map +1 -0
- package/dist/src/util/void-logger.d.ts +13 -0
- package/dist/src/util/void-logger.d.ts.map +1 -0
- package/dist/src/util/void-logger.js +13 -0
- package/dist/src/util/void-logger.js.map +1 -0
- package/package.json +17 -11
- package/src/Coordinator.ts +396 -0
- package/src/{MosaicClient.js → MosaicClient.ts} +50 -43
- package/src/{Param.js → Param.ts} +29 -28
- package/src/{QueryConsolidator.js → QueryConsolidator.ts} +85 -62
- package/src/{QueryManager.js → QueryManager.ts} +61 -54
- package/src/Selection.ts +391 -0
- package/src/SelectionClause.ts +357 -0
- package/src/connectors/Connector.ts +6 -6
- package/src/connectors/rest.ts +56 -0
- package/src/connectors/{socket.js → socket.ts} +53 -42
- package/src/connectors/{wasm.js → wasm.ts} +52 -63
- package/src/index.ts +42 -0
- package/src/make-client.ts +93 -0
- package/src/preagg/{PreAggregator.js → PreAggregator.ts} +164 -145
- package/src/preagg/{preagg-columns.js → preagg-columns.ts} +27 -24
- package/src/preagg/{sufficient-statistics.js → sufficient-statistics.ts} +160 -110
- package/src/types.ts +24 -9
- package/src/util/{AsyncDispatch.js → AsyncDispatch.ts} +62 -43
- package/src/util/{cache.js → cache.ts} +25 -15
- package/src/util/decode-ipc.ts +15 -0
- package/src/util/{distinct.js → distinct.ts} +3 -3
- package/src/util/{field-info.js → field-info.ts} +30 -31
- package/src/util/{hash.js → hash.ts} +4 -4
- package/src/util/is-activatable.ts +11 -0
- package/src/util/is-arrow-table.ts +12 -0
- package/src/util/{js-type.js → js-type.ts} +7 -5
- package/src/util/{priority-queue.js → priority-queue.ts} +32 -20
- package/src/util/{query-result.js → query-result.ts} +24 -17
- package/src/util/synchronizer.ts +56 -0
- package/src/util/throttle.ts +59 -0
- package/src/util/to-data-columns.ts +65 -0
- package/src/util/void-logger.ts +23 -0
- package/src/Coordinator.js +0 -313
- package/src/Selection.js +0 -380
- package/src/SelectionClause.js +0 -159
- package/src/connectors/rest.js +0 -38
- package/src/index-types.ts +0 -5
- package/src/make-client.js +0 -101
- package/src/util/is-activatable.js +0 -8
- package/src/util/is-arrow-table.js +0 -10
- package/src/util/selection-types.ts +0 -137
- package/src/util/synchronizer.js +0 -47
- package/src/util/throttle.js +0 -54
- package/src/util/to-data-columns.js +0 -60
- package/src/util/void-logger.js +0 -13
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -3
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
import { and, argmax, argmin, coalesce, count, div, exp, isNotNull, ln, max, min, mul, pow, regrAvgX, regrAvgY, regrCount, sql, sqrt, sub, sum } from '@uwdata/mosaic-sql';
|
|
2
|
+
import { fnv_hash } from '../util/hash.js';
|
|
3
|
+
/**
|
|
4
|
+
* Determine sufficient statistics to preaggregate the given node. This
|
|
5
|
+
* method populates the *preagg* and *aggrs* arguments with necessary
|
|
6
|
+
* information for preaggregation optimization.
|
|
7
|
+
* @param node An aggregate function.
|
|
8
|
+
* @param preagg Map of column names to
|
|
9
|
+
* expressions to include in the preaggregation table.
|
|
10
|
+
* @param avg Global average query generator.
|
|
11
|
+
* @returns Output aggregate expression that uses preaggregated
|
|
12
|
+
* sufficient statistics to service updates.
|
|
13
|
+
*/
|
|
14
|
+
export function sufficientStatistics(node, preagg, avg) {
|
|
15
|
+
switch (node.name) {
|
|
16
|
+
case 'count':
|
|
17
|
+
case 'count_star':
|
|
18
|
+
return sumCountExpr(preagg, node);
|
|
19
|
+
case 'sum':
|
|
20
|
+
return sumExpr(preagg, node);
|
|
21
|
+
case 'avg':
|
|
22
|
+
return avgExpr(preagg, node);
|
|
23
|
+
case 'geomean':
|
|
24
|
+
return geomeanExpr(preagg, node);
|
|
25
|
+
case 'arg_max':
|
|
26
|
+
return argmaxExpr(preagg, node);
|
|
27
|
+
case 'arg_min':
|
|
28
|
+
return argminExpr(preagg, node);
|
|
29
|
+
// variance statistics drop the original aggregate operation
|
|
30
|
+
// in favor of tracking sufficient statistics
|
|
31
|
+
case 'variance':
|
|
32
|
+
case 'var_samp':
|
|
33
|
+
return varianceExpr(preagg, node, avg);
|
|
34
|
+
case 'var_pop':
|
|
35
|
+
return varianceExpr(preagg, node, avg, false);
|
|
36
|
+
case 'stddev':
|
|
37
|
+
case 'stddev_samp':
|
|
38
|
+
return sqrt(varianceExpr(preagg, node, avg));
|
|
39
|
+
case 'stddev_pop':
|
|
40
|
+
return sqrt(varianceExpr(preagg, node, avg, false));
|
|
41
|
+
case 'covar_samp':
|
|
42
|
+
return covarianceExpr(preagg, node, avg);
|
|
43
|
+
case 'covar_pop':
|
|
44
|
+
return covarianceExpr(preagg, node, avg, false);
|
|
45
|
+
case 'corr':
|
|
46
|
+
return corrExpr(preagg, node, avg);
|
|
47
|
+
// regression statistics
|
|
48
|
+
case 'regr_count':
|
|
49
|
+
return regrCountExpr(preagg, node).expr;
|
|
50
|
+
case 'regr_avgx':
|
|
51
|
+
return regrAvgXExpr(preagg, node);
|
|
52
|
+
case 'regr_avgy':
|
|
53
|
+
return regrAvgYExpr(preagg, node);
|
|
54
|
+
case 'regr_syy':
|
|
55
|
+
return regrVarExpr(preagg, 0, node, avg);
|
|
56
|
+
case 'regr_sxx':
|
|
57
|
+
return regrVarExpr(preagg, 1, node, avg);
|
|
58
|
+
case 'regr_sxy':
|
|
59
|
+
return covarianceExpr(preagg, node, avg, null);
|
|
60
|
+
case 'regr_slope':
|
|
61
|
+
return regrSlopeExpr(preagg, node, avg);
|
|
62
|
+
case 'regr_intercept':
|
|
63
|
+
return regrInterceptExpr(preagg, node, avg);
|
|
64
|
+
case 'regr_r2':
|
|
65
|
+
return pow(corrExpr(preagg, node, avg), 2);
|
|
66
|
+
// aggregates that commute directly
|
|
67
|
+
case 'max':
|
|
68
|
+
case 'min':
|
|
69
|
+
case 'bit_and':
|
|
70
|
+
case 'bit_or':
|
|
71
|
+
case 'bit_xor':
|
|
72
|
+
case 'bool_and':
|
|
73
|
+
case 'bool_or':
|
|
74
|
+
case 'product': {
|
|
75
|
+
const name = colName(node);
|
|
76
|
+
preagg[name] = node;
|
|
77
|
+
return sql `${node.name}("${name}")`;
|
|
78
|
+
}
|
|
79
|
+
// unsupported aggregate, return null to indicate failure
|
|
80
|
+
default: return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Generate a column name for the given aggregate node. The name is
|
|
85
|
+
* made from a hash of the string-serialized SQL expression.
|
|
86
|
+
* @param node The aggregate node to name.
|
|
87
|
+
* @returns The generated column name.
|
|
88
|
+
*/
|
|
89
|
+
function colName(node) {
|
|
90
|
+
return 'pre_' + fnv_hash(`${node}`).toString(16);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Add a sufficient statistic to the preaggregation column set.
|
|
94
|
+
* Generates a unique column name for the statistic and propagates
|
|
95
|
+
* a FILTER clause if one exists on the original aggregate node.
|
|
96
|
+
* @param preagg A map of columns (such as
|
|
97
|
+
* sufficient statistics) to pre-aggregate.
|
|
98
|
+
* @param expr The aggregate statistic to add.
|
|
99
|
+
* @param node The originating aggregate function call.
|
|
100
|
+
* @returns The name of the statistic column.
|
|
101
|
+
*/
|
|
102
|
+
function addStat(preagg, expr, node) {
|
|
103
|
+
const filter = node?.filter;
|
|
104
|
+
if (filter) {
|
|
105
|
+
// push filter clause to preaggregate expr
|
|
106
|
+
expr = expr.filter
|
|
107
|
+
? expr.where(and(filter, expr.filter))
|
|
108
|
+
: expr.where(filter);
|
|
109
|
+
}
|
|
110
|
+
const name = colName(expr);
|
|
111
|
+
preagg[name] = expr;
|
|
112
|
+
return name;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generate an expression for calculating counts over data dimensions.
|
|
116
|
+
* As a side effect, this method adds a column to the input *preagg* object
|
|
117
|
+
* to track the count of non-null values per-partition.
|
|
118
|
+
* @param preagg A map of columns (such as
|
|
119
|
+
* sufficient statistics) to pre-aggregate.
|
|
120
|
+
* @param node The originating aggregate function call.
|
|
121
|
+
* @returns An aggregate expression over
|
|
122
|
+
* pre-aggregated dimensions and associated column name.
|
|
123
|
+
*/
|
|
124
|
+
function countExpr(preagg, node) {
|
|
125
|
+
const name = addStat(preagg, count(node.args[0]), node);
|
|
126
|
+
return { expr: coalesce(sum(name), 0), name };
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Generate an expression for calculating counts over data dimensions.
|
|
130
|
+
* The expression is a summation with an additional coalesce operation
|
|
131
|
+
* to map null sums to zero-valued counts.
|
|
132
|
+
* @param preagg A map of columns (such as
|
|
133
|
+
* sufficient statistics) to pre-aggregate.
|
|
134
|
+
* @param node The originating aggregate function call.
|
|
135
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
136
|
+
*/
|
|
137
|
+
function sumCountExpr(preagg, node) {
|
|
138
|
+
return coalesce(sumExpr(preagg, node), 0);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Generate an expression for calculating sums over data dimensions.
|
|
142
|
+
* @param preagg A map of columns (such as
|
|
143
|
+
* sufficient statistics) to pre-aggregate.
|
|
144
|
+
* @param node The originating aggregate function call.
|
|
145
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
146
|
+
*/
|
|
147
|
+
function sumExpr(preagg, node) {
|
|
148
|
+
return sum(addStat(preagg, node));
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Generate an expression for calculating averages over data dimensions.
|
|
152
|
+
* As a side effect, this method adds a column to the input *preagg* object
|
|
153
|
+
* to track the count of non-null values per-partition.
|
|
154
|
+
* @param preagg A map of columns (such as
|
|
155
|
+
* sufficient statistics) to pre-aggregate.
|
|
156
|
+
* @param node The originating aggregate function call.
|
|
157
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
158
|
+
*/
|
|
159
|
+
function avgExpr(preagg, node) {
|
|
160
|
+
const as = addStat(preagg, node);
|
|
161
|
+
const { expr, name } = countExpr(preagg, node);
|
|
162
|
+
return div(sum(mul(as, name)), expr);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Generate an expression for calculating geometric means over data dimensions.
|
|
166
|
+
* This method uses log-based computations to ensure numerical stability. The
|
|
167
|
+
* geomean calculation uses two sufficient statistics: the sum of log values
|
|
168
|
+
* and the count of non-null values. As a side effect, this method adds columns
|
|
169
|
+
* for these statistics to the input *preagg* object.
|
|
170
|
+
* @param preagg A map of columns (such as
|
|
171
|
+
* sufficient statistics) to pre-aggregate.
|
|
172
|
+
* @param node The originating aggregate function call.
|
|
173
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
174
|
+
*/
|
|
175
|
+
function geomeanExpr(preagg, node) {
|
|
176
|
+
const x = node.args[0];
|
|
177
|
+
const expr = addStat(preagg, sum(ln(x)), node);
|
|
178
|
+
const { expr: n } = countExpr(preagg, node);
|
|
179
|
+
return exp(div(sum(expr), n));
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Generate an expression for calculating argmax over data dimensions.
|
|
183
|
+
* As a side effect, this method adds a column to the input *preagg* object
|
|
184
|
+
* to track a maximum value per-partition.
|
|
185
|
+
* @param preagg A map of columns (such as
|
|
186
|
+
* sufficient statistics) to pre-aggregate.
|
|
187
|
+
* @param node The originating aggregate function call.
|
|
188
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
189
|
+
*/
|
|
190
|
+
function argmaxExpr(preagg, node) {
|
|
191
|
+
const expr = addStat(preagg, node);
|
|
192
|
+
const maxy = addStat(preagg, max(node.args[1]), node);
|
|
193
|
+
return argmax(expr, maxy);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Generate an expression for calculating argmin over data dimensions.
|
|
197
|
+
* As a side effect, this method adds a column to the input *preagg* object
|
|
198
|
+
* to track a minimum value per-partition.
|
|
199
|
+
* @param preagg A map of columns (such as
|
|
200
|
+
* sufficient statistics) to pre-aggregate.
|
|
201
|
+
* @param node The originating aggregate function call.
|
|
202
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
203
|
+
*/
|
|
204
|
+
function argminExpr(preagg, node) {
|
|
205
|
+
const expr = addStat(preagg, node);
|
|
206
|
+
const miny = addStat(preagg, min(node.args[1]), node);
|
|
207
|
+
return argmin(expr, miny);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generate an expression for calculating variance over data dimensions.
|
|
211
|
+
* This method uses the "textbook" definition of variance (E[X^2] - E[X]^2),
|
|
212
|
+
* but on mean-centered data to reduce floating point error. The variance
|
|
213
|
+
* calculation uses three sufficient statistics: the count of non-null values,
|
|
214
|
+
* the residual sum of squares and the sum of residual (mean-centered) values.
|
|
215
|
+
* As a side effect, this method adds columns for these statistics to the
|
|
216
|
+
* input *preagg* object.
|
|
217
|
+
* @param preagg A map of columns (such as
|
|
218
|
+
* sufficient statistics) to pre-aggregate.
|
|
219
|
+
* @param node The originating aggregate function call.
|
|
220
|
+
* @param avg Global average query generator.
|
|
221
|
+
* @param correction A flag for whether a Bessel
|
|
222
|
+
* correction should be applied to compute the sample variance
|
|
223
|
+
* rather than the populatation variance.
|
|
224
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
225
|
+
*/
|
|
226
|
+
function varianceExpr(preagg, node, avg, correction = true) {
|
|
227
|
+
const x = node.args[0];
|
|
228
|
+
const { expr: n } = countExpr(preagg, node);
|
|
229
|
+
const delta = sub(x, avg(x));
|
|
230
|
+
const rssq = addStat(preagg, sum(pow(delta, 2)), node); // residual sum of squares
|
|
231
|
+
const rsum = addStat(preagg, sum(delta), node); // residual sum
|
|
232
|
+
const denom = correction ? sub(n, 1) : n; // Bessel correction
|
|
233
|
+
return div(sub(sum(rssq), div(pow(sum(rsum), 2), n)), denom);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Generate an expression for calculating covariance over data dimensions.
|
|
237
|
+
* This method uses mean-centered data to reduce floating point error. The
|
|
238
|
+
* covariance calculation uses four sufficient statistics: the count of
|
|
239
|
+
* non-null value pairs, the sum of residual products, and residual sums
|
|
240
|
+
* (of mean-centered values) for x and y. As a side effect, this method
|
|
241
|
+
* adds columns for these statistics to the input *preagg* object.
|
|
242
|
+
* @param preagg A map of columns (such as
|
|
243
|
+
* sufficient statistics) to pre-aggregate.
|
|
244
|
+
* @param node The originating aggregate function call.
|
|
245
|
+
* @param avg Global average query generator.
|
|
246
|
+
* @param correction A flag for whether a Bessel
|
|
247
|
+
* correction should be applied to compute the sample covariance rather
|
|
248
|
+
* than the populatation covariance. If null, an expression for the
|
|
249
|
+
* unnormalized covariance (no division by sample count) is returned.
|
|
250
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
251
|
+
*/
|
|
252
|
+
function covarianceExpr(preagg, node, avg, correction = true) {
|
|
253
|
+
const { expr: n } = regrCountExpr(preagg, node);
|
|
254
|
+
const sxy = regrSumXYExpr(preagg, node, avg);
|
|
255
|
+
const sx = regrSumExpr(preagg, 1, node, avg);
|
|
256
|
+
const sy = regrSumExpr(preagg, 0, node, avg);
|
|
257
|
+
const num = sub(sxy, div(mul(sx, sy), n));
|
|
258
|
+
return correction === null ? num // do not divide by count
|
|
259
|
+
: correction ? div(num, sub(n, 1)) // Bessel correction (sample)
|
|
260
|
+
: div(num, n); // no correction (population)
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Generate an expression for calculating Pearson product-moment correlation
|
|
264
|
+
* coefficients over data dimensions. This method uses mean-centered data
|
|
265
|
+
* to reduce floating point error. The correlation calculation uses six
|
|
266
|
+
* sufficient statistics: the count of non-null value pairs, the sum of
|
|
267
|
+
* residual products, and both residual sums and sums of squares for x and y.
|
|
268
|
+
* As a side effect, this method adds columns for these statistics to the
|
|
269
|
+
* input *preagg* object.
|
|
270
|
+
* @param preagg A map of columns (such as
|
|
271
|
+
* sufficient statistics) to pre-aggregate.
|
|
272
|
+
* @param node The originating aggregate function call.
|
|
273
|
+
* @param avg Global average query generator.
|
|
274
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
275
|
+
*/
|
|
276
|
+
function corrExpr(preagg, node, avg) {
|
|
277
|
+
const { expr: n } = regrCountExpr(preagg, node);
|
|
278
|
+
const sxy = regrSumXYExpr(preagg, node, avg);
|
|
279
|
+
const sxx = regrSumSqExpr(preagg, 1, node, avg);
|
|
280
|
+
const syy = regrSumSqExpr(preagg, 0, node, avg);
|
|
281
|
+
const sx = regrSumExpr(preagg, 1, node, avg);
|
|
282
|
+
const sy = regrSumExpr(preagg, 0, node, avg);
|
|
283
|
+
const vx = sub(sxx, div(pow(sx, 2), n));
|
|
284
|
+
const vy = sub(syy, div(pow(sy, 2), n));
|
|
285
|
+
return div(sub(sxy, div(mul(sx, sy), n)), sqrt(mul(vx, vy)));
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Generate an expression for the count of non-null (x, y) pairs. As a side
|
|
289
|
+
* effect, this method adds columns to the input *preagg* object to the
|
|
290
|
+
* partition-level count of non-null pairs.
|
|
291
|
+
* @param preagg A map of columns (such as
|
|
292
|
+
* sufficient statistics) to pre-aggregate.
|
|
293
|
+
* @param node The originating aggregate function call.
|
|
294
|
+
* @returns An aggregate expression over
|
|
295
|
+
* pre-aggregated dimensions and associated column name.
|
|
296
|
+
*/
|
|
297
|
+
function regrCountExpr(preagg, node) {
|
|
298
|
+
const [x, y] = node.args;
|
|
299
|
+
const n = addStat(preagg, regrCount(x, y), node);
|
|
300
|
+
return { expr: sum(n), name: n };
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Generate an expression for calculating sums of residual values for use in
|
|
304
|
+
* covariance and regression queries. Only values corresponding to non-null
|
|
305
|
+
* (x, y) pairs are included. This method uses mean-centered data to reduce
|
|
306
|
+
* floating point error. As a side effect, this method adds a column for
|
|
307
|
+
* partition-level sums to the input *preagg* object.
|
|
308
|
+
* @param preagg A map of columns (such as
|
|
309
|
+
* sufficient statistics) to pre-aggregate.
|
|
310
|
+
* @param i An index indicating which argument column to sum.
|
|
311
|
+
* @param node The originating aggregate function call.
|
|
312
|
+
* @param avg Global average query generator.
|
|
313
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
314
|
+
*/
|
|
315
|
+
function regrSumExpr(preagg, i, node, avg) {
|
|
316
|
+
const args = node.args;
|
|
317
|
+
const v = args[i];
|
|
318
|
+
const o = args[1 - i];
|
|
319
|
+
const rsum = sum(sub(v, avg(v))).where(isNotNull(o));
|
|
320
|
+
return sum(addStat(preagg, rsum, node));
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Generate an expressios for calculating sums of squared residual values for
|
|
324
|
+
* use in covariance and regression queries. Only values corresponding to
|
|
325
|
+
* non-null (x, y) pairs are included. This method uses mean-centered data to
|
|
326
|
+
* reduce floating point error. As a side effect, this method adds a column
|
|
327
|
+
* for partition-level sums to the input *preagg* object.
|
|
328
|
+
* @param preagg A map of columns (such as
|
|
329
|
+
* sufficient statistics) to pre-aggregate.
|
|
330
|
+
* @param i An index indicating which argument column to sum.
|
|
331
|
+
* @param node The originating aggregate function call.
|
|
332
|
+
* @param avg Global average query generator.
|
|
333
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
334
|
+
*/
|
|
335
|
+
function regrSumSqExpr(preagg, i, node, avg) {
|
|
336
|
+
const args = node.args;
|
|
337
|
+
const v = args[i];
|
|
338
|
+
const u = args[1 - i];
|
|
339
|
+
const ssq = sum(pow(sub(v, avg(v)), 2)).where(isNotNull(u));
|
|
340
|
+
return sum(addStat(preagg, ssq, node));
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Generate an expression for calculating sums of residual product values for
|
|
344
|
+
* use in covariance and regression queries. Only values corresponding to
|
|
345
|
+
* non-null (x, y) pairs are included. This method uses mean-centered data to
|
|
346
|
+
* reduce floating point error. As a side effect, this method adds a column
|
|
347
|
+
* for partition-level sums to the input *preagg* object.
|
|
348
|
+
* @param preagg A map of columns (such as
|
|
349
|
+
* sufficient statistics) to pre-aggregate.
|
|
350
|
+
* @param node The originating aggregate function call.
|
|
351
|
+
* @param avg Global average query generator.
|
|
352
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
353
|
+
*/
|
|
354
|
+
function regrSumXYExpr(preagg, node, avg) {
|
|
355
|
+
const [y, x] = node.args;
|
|
356
|
+
const sxy = sum(mul(sub(x, avg(x)), sub(y, avg(y))));
|
|
357
|
+
return sum(addStat(preagg, sxy, node));
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Generate an expression for the average x value in a regression context.
|
|
361
|
+
* Only values corresponding to non-null (x, y) pairs are included. As a side
|
|
362
|
+
* effect, this method adds columns to the input *preagg* object to track both
|
|
363
|
+
* the count of non-null pairs and partition-level averages.
|
|
364
|
+
* @param preagg A map of columns (such as
|
|
365
|
+
* sufficient statistics) to pre-aggregate.
|
|
366
|
+
* @param node The originating aggregate function call.
|
|
367
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
368
|
+
*/
|
|
369
|
+
function regrAvgXExpr(preagg, node) {
|
|
370
|
+
const [y, x] = node.args;
|
|
371
|
+
const { expr: n, name } = regrCountExpr(preagg, node);
|
|
372
|
+
const a = addStat(preagg, regrAvgX(y, x), node);
|
|
373
|
+
return div(sum(mul(a, name)), n);
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* Generate an expression for the average y value in a regression context.
|
|
377
|
+
* Only values corresponding to non-null (x, y) pairs are included. As a side
|
|
378
|
+
* effect, this method adds columns to the input *preagg* object to track both
|
|
379
|
+
* the count of non-null pairs and partition-level averages.
|
|
380
|
+
* @param preagg A map of columns (such as
|
|
381
|
+
* sufficient statistics) to pre-aggregate.
|
|
382
|
+
* @param node The originating aggregate function call.
|
|
383
|
+
* @returns An aggregate expression over pre-aggregated dimensions.
|
|
384
|
+
*/
|
|
385
|
+
function regrAvgYExpr(preagg, node) {
|
|
386
|
+
const [y, x] = node.args;
|
|
387
|
+
const { expr: n, name } = regrCountExpr(preagg, node);
|
|
388
|
+
const a = addStat(preagg, regrAvgY(y, x), node);
|
|
389
|
+
return div(sum(mul(a, name)), n);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Generate an expression for calculating variance over data dimensions for
|
|
393
|
+
* use in covariance and regression queries. Only values corresponding to
|
|
394
|
+
* non-null (x, y) pairs are included. This method uses mean-centered data to
|
|
395
|
+
* reduce floating point error. As a side effect, this method adds columns
|
|
396
|
+
* for partition-level count and sums to the input *preagg* object.
|
|
397
|
+
* @param preagg A map of columns (such as
|
|
398
|
+
* sufficient statistics) to pre-aggregate.
|
|
399
|
+
* @param i The index of the argument to compute the variance for.
|
|
400
|
+
* @param node The originating aggregate function call.
|
|
401
|
+
* @param avg Global average query generator.
|
|
402
|
+
* @returns An aggregate expression for calculating variance
|
|
403
|
+
* over pre-aggregated data dimensions.
|
|
404
|
+
*/
|
|
405
|
+
function regrVarExpr(preagg, i, node, avg) {
|
|
406
|
+
const { expr: n } = regrCountExpr(preagg, node);
|
|
407
|
+
const sum = regrSumExpr(preagg, i, node, avg);
|
|
408
|
+
const ssq = regrSumSqExpr(preagg, i, node, avg);
|
|
409
|
+
return sub(ssq, div(pow(sum, 2), n));
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Generate an expression for calculating a regression slope. The slope is
|
|
413
|
+
* computed as the covariance divided by the variance of the x variable. As a
|
|
414
|
+
* side effect, this method adds columns for sufficient statistics to the
|
|
415
|
+
* input *preagg* object.
|
|
416
|
+
* @param preagg A map of columns (such as
|
|
417
|
+
* sufficient statistics) to pre-aggregate.
|
|
418
|
+
* @param node The originating aggregate function call.
|
|
419
|
+
* @param avg Global average query generator.
|
|
420
|
+
* @returns An aggregate expression for calculating regression
|
|
421
|
+
* slopes over pre-aggregated data dimensions.
|
|
422
|
+
*/
|
|
423
|
+
function regrSlopeExpr(preagg, node, avg) {
|
|
424
|
+
const cov = covarianceExpr(preagg, node, avg, null);
|
|
425
|
+
const varx = regrVarExpr(preagg, 1, node, avg);
|
|
426
|
+
return div(cov, varx);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Generate an expression for calculating a regression intercept. The intercept
|
|
430
|
+
* is derived from the regression slope and average x and y values. As a
|
|
431
|
+
* side effect, this method adds columns for sufficient statistics to the
|
|
432
|
+
* input *preagg* object.
|
|
433
|
+
* @param preagg A map of columns (such as
|
|
434
|
+
* sufficient statistics) to pre-aggregate.
|
|
435
|
+
* @param node The originating aggregate function call.
|
|
436
|
+
* @param avg Global average query generator.
|
|
437
|
+
* @returns An aggregate expression for calculating regression
|
|
438
|
+
* intercepts over pre-aggregated data dimensions.
|
|
439
|
+
*/
|
|
440
|
+
function regrInterceptExpr(preagg, node, avg) {
|
|
441
|
+
const ax = regrAvgXExpr(preagg, node);
|
|
442
|
+
const ay = regrAvgYExpr(preagg, node);
|
|
443
|
+
const m = regrSlopeExpr(preagg, node, avg);
|
|
444
|
+
return sub(ay, mul(m, ax));
|
|
445
|
+
}
|
|
446
|
+
//# sourceMappingURL=sufficient-statistics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sufficient-statistics.js","sourceRoot":"","sources":["../../../src/preagg/sufficient-statistics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAC3K,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAmB,EACnB,MAAgC,EAChC,GAAuC;IAEvC,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;Q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AM,GAAG,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAChD,OAAO,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,aAAa,CACpB,MAAgC,EAChC,IAAmB,EACnB,GAAuC;IAEvC,MAAM,GAAG,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,iBAAiB,CACxB,MAAgC,EAChC,IAAmB,EACnB,GAAuC;IAEvC,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtC,MAAM,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC3C,OAAO,GAAG,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { DescribeQuery, ExprNode, Query } from '@uwdata/mosaic-sql';
|
|
2
|
+
import type { QueryResult } from './util/query-result.js';
|
|
3
|
+
/** Type for a query request. */
|
|
4
|
+
export interface QueryRequest {
|
|
5
|
+
type: 'exec' | 'json' | 'arrow';
|
|
6
|
+
query: string | Query | DescribeQuery;
|
|
7
|
+
cache?: boolean;
|
|
8
|
+
options?: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
/** Type for an entry within a query manager. */
|
|
11
|
+
export interface QueryEntry {
|
|
12
|
+
request: QueryRequest;
|
|
13
|
+
result: QueryResult;
|
|
14
|
+
}
|
|
15
|
+
/** Query type accepted by a coordinator. */
|
|
16
|
+
export type QueryType = string | Query | DescribeQuery;
|
|
17
|
+
/** String indicating a JavaScript data type. */
|
|
18
|
+
export type JSType = 'number' | 'date' | 'boolean' | 'string' | 'array' | 'object';
|
|
19
|
+
/** String indicating a requested summary statistic. */
|
|
20
|
+
export type Stat = 'count' | 'nulls' | 'max' | 'min' | 'distinct';
|
|
21
|
+
/** A reference to a database column or expression. */
|
|
22
|
+
export type FieldRef = string | ExprNode;
|
|
23
|
+
/**
|
|
24
|
+
* A request for metadata information about a database column.
|
|
25
|
+
*/
|
|
26
|
+
export interface FieldInfoRequest {
|
|
27
|
+
table: string;
|
|
28
|
+
column: FieldRef;
|
|
29
|
+
stats?: Stat[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A response with metadata information about a database column.
|
|
33
|
+
*/
|
|
34
|
+
export interface FieldInfo extends Partial<Record<Stat, number>> {
|
|
35
|
+
table: string;
|
|
36
|
+
column: string;
|
|
37
|
+
sqlType: string;
|
|
38
|
+
type: JSType;
|
|
39
|
+
nullable: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** A result row from a DESCRIBE query. */
|
|
42
|
+
export interface ColumnDescription {
|
|
43
|
+
column_name: string;
|
|
44
|
+
column_type: string;
|
|
45
|
+
null: 'YES' | 'NO';
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Interface for components that perform selection activation.
|
|
49
|
+
*/
|
|
50
|
+
export interface Activatable {
|
|
51
|
+
/**
|
|
52
|
+
* Activate the selection that this component publishes to.
|
|
53
|
+
*/
|
|
54
|
+
activate(): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Interface for cache implementations.
|
|
58
|
+
*/
|
|
59
|
+
export interface Cache {
|
|
60
|
+
get(key: string): unknown;
|
|
61
|
+
set(key: string, value: unknown): unknown;
|
|
62
|
+
clear(): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Interface for logger implementations
|
|
66
|
+
*/
|
|
67
|
+
export interface Logger {
|
|
68
|
+
debug(...args: unknown[]): void;
|
|
69
|
+
info(...args: unknown[]): void;
|
|
70
|
+
log(...args: unknown[]): void;
|
|
71
|
+
warn(...args: unknown[]): void;
|
|
72
|
+
error(...args: unknown[]): void;
|
|
73
|
+
group(label?: unknown): void;
|
|
74
|
+
groupCollapsed(label?: unknown): void;
|
|
75
|
+
groupEnd(): void;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D,gCAAgC;AAChC,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAChC,KAAK,EAAE,MAAM,GAAG,KAAK,GAAG,aAAa,CAAC;IACtC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED,gDAAgD;AAChD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,YAAY,CAAC;IACtB,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,4CAA4C;AAC5C,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,KAAK,GACL,aAAa,CAAC;AAElB,gDAAgD;AAChD,MAAM,MAAM,MAAM,GACd,QAAQ,GACR,MAAM,GACN,SAAS,GACT,QAAQ,GACR,OAAO,GACP,QAAQ,CAAC;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,IAAI,CAAC;IAC9B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAChC,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,cAAc,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACtC,QAAQ,IAAI,IAAI,CAAC;CAClB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
type EventCallback<T = unknown> = (value: T) => void | Promise<unknown>;
|
|
2
|
+
interface DispatchEntry<T = unknown> {
|
|
3
|
+
callbacks: Set<EventCallback<T>>;
|
|
4
|
+
pending: Promise<unknown> | null;
|
|
5
|
+
queue: DispatchQueue<T>;
|
|
6
|
+
}
|
|
7
|
+
interface QueueNode<T = unknown> {
|
|
8
|
+
value: T;
|
|
9
|
+
next?: QueueNode<T> | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Event dispatcher supporting asynchronous updates. If an event handler
|
|
13
|
+
* callback returns a Promise, the dispatcher waits for all such Promises
|
|
14
|
+
* to settle before dispatching future events of the same type.
|
|
15
|
+
*/
|
|
16
|
+
export declare class AsyncDispatch<T> {
|
|
17
|
+
_callbacks: Map<string, DispatchEntry<T>>;
|
|
18
|
+
/**
|
|
19
|
+
* Create a new asynchronous dispatcher instance.
|
|
20
|
+
*/
|
|
21
|
+
constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Add an event listener callback for the provided event type.
|
|
24
|
+
* @param type The event type.
|
|
25
|
+
* @param callback The event handler
|
|
26
|
+
* callback function to add. If the callback has already been
|
|
27
|
+
* added for the event type, this method has no effect.
|
|
28
|
+
*/
|
|
29
|
+
addEventListener(type: string, callback: EventCallback<T>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Remove an event listener callback for the provided event type.
|
|
32
|
+
* @param type The event type.
|
|
33
|
+
* @param callback The event handler
|
|
34
|
+
* callback function to remove.
|
|
35
|
+
*/
|
|
36
|
+
removeEventListener(type: string, callback: EventCallback<T>): void;
|
|
37
|
+
/**
|
|
38
|
+
* Lifecycle method that returns the event value to emit.
|
|
39
|
+
* This default implementation simply returns the input value as-is.
|
|
40
|
+
* Subclasses may override this method to implement custom transformations
|
|
41
|
+
* prior to emitting an event value to all listeners.
|
|
42
|
+
* @param type The event type.
|
|
43
|
+
* @param value The event value.
|
|
44
|
+
* @returns The (possibly transformed) event value to emit.
|
|
45
|
+
*/
|
|
46
|
+
willEmit(type: string, value: T): T;
|
|
47
|
+
/**
|
|
48
|
+
* Lifecycle method that returns a filter function for updating the
|
|
49
|
+
* queue of unemitted event values prior to enqueueing a new value.
|
|
50
|
+
* This default implementation simply returns null, indicating that
|
|
51
|
+
* unknown other unemitted event values should be dropped (that is, all
|
|
52
|
+
* queued events are filtered).
|
|
53
|
+
* @param type The event type.
|
|
54
|
+
* @param value The new event value that will be enqueued.
|
|
55
|
+
* @returns A dispatch queue filter
|
|
56
|
+
* function, or null if all unemitted event values should be filtered.
|
|
57
|
+
*/
|
|
58
|
+
emitQueueFilter(_type: string, // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
59
|
+
_value: unknown): ((value: unknown) => boolean | null) | null;
|
|
60
|
+
/**
|
|
61
|
+
* Cancel all unemitted event values for the given event type.
|
|
62
|
+
* @param type The event type.
|
|
63
|
+
*/
|
|
64
|
+
cancel(type: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Returns a promise that resolves when unknown pending updates complete for
|
|
67
|
+
* the event of the given type currently being processed. The Promise will
|
|
68
|
+
* resolve immediately if the queue for the given event type is empty.
|
|
69
|
+
* @param type The event type to wait for.
|
|
70
|
+
* @returns A pending event promise.
|
|
71
|
+
*/
|
|
72
|
+
pending(type: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Emit an event value to listeners for the given event type.
|
|
75
|
+
* If a previous emit has not yet resolved, the event value
|
|
76
|
+
* will be queued to be emitted later.
|
|
77
|
+
* The actual event value given to listeners will be the result
|
|
78
|
+
* of passing the input value through the emitValue() method.
|
|
79
|
+
* @param type The event type.
|
|
80
|
+
* @param value The event value.
|
|
81
|
+
*/
|
|
82
|
+
emit(type: string, value: T): void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Queue for managing unemitted event values.
|
|
86
|
+
*/
|
|
87
|
+
export declare class DispatchQueue<T = unknown> {
|
|
88
|
+
next: QueueNode<T> | null;
|
|
89
|
+
/**
|
|
90
|
+
* Create a new dispatch queue instance.
|
|
91
|
+
*/
|
|
92
|
+
constructor();
|
|
93
|
+
/**
|
|
94
|
+
* Clear the queue state of all event values.
|
|
95
|
+
*/
|
|
96
|
+
clear(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Indicate if the queue is empty.
|
|
99
|
+
* @returns True if queue is empty, false otherwise.
|
|
100
|
+
*/
|
|
101
|
+
isEmpty(): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Add a new value to the queue, and optionally filter the
|
|
104
|
+
* current queue content in response.
|
|
105
|
+
* @param value The value to add.
|
|
106
|
+
* @param filter An optional filter
|
|
107
|
+
* function to apply to existing queue content. If unspecified
|
|
108
|
+
* or falsy, all previously queued values are removed. Otherwise,
|
|
109
|
+
* the provided function is applied to all queue entries. The
|
|
110
|
+
* entry is retained if the filter function returns a truthy value,
|
|
111
|
+
* otherwise the entry is removed.
|
|
112
|
+
*/
|
|
113
|
+
enqueue(value: T, filter?: ((value: T) => boolean | null) | null): void;
|
|
114
|
+
/**
|
|
115
|
+
* Remove and return the next queued event value.
|
|
116
|
+
* @returns The next event value in the queue.
|
|
117
|
+
*/
|
|
118
|
+
dequeue(): T | undefined;
|
|
119
|
+
}
|
|
120
|
+
export {};
|
|
121
|
+
//# sourceMappingURL=AsyncDispatch.d.ts.map
|