@uwdata/mosaic-core 0.12.2 → 0.13.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.
@@ -1,4 +1,4 @@
1
- import { AggregateNode, and, argmax, argmin, count, div, ExprNode, isNotNull, max, min, mul, pow, regrAvgX, regrAvgY, regrCount, sql, sqrt, sub, sum } from '@uwdata/mosaic-sql';
1
+ import { AggregateNode, and, argmax, argmin, count, div, exp, ExprNode, isNotNull, ln, max, min, mul, pow, regrAvgX, regrAvgY, regrCount, sql, sqrt, sub, sum } from '@uwdata/mosaic-sql';
2
2
  import { fnv_hash } from '../util/hash.js';
3
3
 
4
4
  /**
@@ -18,6 +18,8 @@ export function sufficientStatistics(node, preagg, avg) {
18
18
  return sumExpr(preagg, node);
19
19
  case 'avg':
20
20
  return avgExpr(preagg, node);
21
+ case 'geomean':
22
+ return geomeanExpr(preagg, node);
21
23
  case 'arg_max':
22
24
  return argmaxExpr(preagg, node);
23
25
  case 'arg_min':
@@ -155,6 +157,24 @@ function avgExpr(preagg, node) {
155
157
  return div(sum(mul(as, name)), expr);
156
158
  }
157
159
 
160
+ /**
161
+ * Generate an expression for calculating geometric means over data dimensions.
162
+ * This method uses log-based computations to ensure numerical stability. The
163
+ * geomean calculation uses two sufficient statistics: the sum of log values
164
+ * and the count of non-null values. As a side effect, this method adds columns
165
+ * for these statistics to the input *preagg* object.
166
+ * @param {Record<string, ExprNode>} preagg A map of columns (such as
167
+ * sufficient statistics) to pre-aggregate.
168
+ * @param {AggregateNode} node The originating aggregate function call.
169
+ * @returns {ExprNode} An aggregate expression over pre-aggregated dimensions.
170
+ */
171
+ function geomeanExpr(preagg, node) {
172
+ const x = node.args[0];
173
+ const expr = addStat(preagg, sum(ln(x)), node);
174
+ const { expr: n } = countExpr(preagg, node);
175
+ return exp(div(sum(expr), n));
176
+ }
177
+
158
178
  /**
159
179
  * Generate an expression for calculating argmax over data dimensions.
160
180
  * As a side effect, this method adds a column to the input *preagg* object
package/src/types.ts CHANGED
@@ -1,4 +1,10 @@
1
- import type { ExprNode } from '@uwdata/mosaic-sql';
1
+ import type { DescribeQuery, ExprNode, Query } from '@uwdata/mosaic-sql';
2
+
3
+ /** Query type accepted by a coordinator. */
4
+ export type QueryType =
5
+ | string
6
+ | Query
7
+ | DescribeQuery;
2
8
 
3
9
  /** String indicating a JavaScript data type. */
4
10
  export type JSType =
@@ -46,3 +52,13 @@ export interface ColumnDescription {
46
52
  column_type: string,
47
53
  null: 'YES' | 'NO'
48
54
  }
55
+
56
+ /**
57
+ * Interface for components that perform selection activation.
58
+ */
59
+ export interface Activatable {
60
+ /**
61
+ * Activate the selection that this component publishes to.
62
+ */
63
+ activate(): void;
64
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Test if a value implements the Activatable interface.
3
+ * @param {*} value The value to test.
4
+ * @returns {value is import('../types.js').Activatable}
5
+ */
6
+ export function isActivatable(value) {
7
+ return typeof value?.activate === 'function' && value.activate.length === 0;
8
+ }
@@ -5,10 +5,12 @@ const NIL = {};
5
5
  * a Promise. Upon repeated invocation, the callback will not be invoked
6
6
  * until a prior Promise resolves. If multiple invocations occurs while
7
7
  * waiting, only the most recent invocation will be pending.
8
- * @param {(event: *) => Promise} callback The callback function.
8
+ * @template E, T
9
+ * @param {(event: E) => Promise<T>} callback The callback function.
9
10
  * @param {boolean} [debounce=true] Flag indicating if invocations
10
11
  * should also be debounced within the current animation frame.
11
- * @returns A new function that throttles access to the callback.
12
+ * @returns {(event: E) => void} A new function that throttles
13
+ * access to the callback.
12
14
  */
13
15
  export function throttle(callback, debounce = false) {
14
16
  let curr;
@@ -0,0 +1,3 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({});