@uwdata/mosaic-core 0.16.2 → 0.18.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.
Files changed (206) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +0 -1
  3. package/dist/src/Coordinator.d.ts +147 -0
  4. package/dist/src/Coordinator.d.ts.map +1 -0
  5. package/dist/src/Coordinator.js +269 -0
  6. package/dist/src/Coordinator.js.map +1 -0
  7. package/dist/{types → src}/MosaicClient.d.ts +37 -42
  8. package/dist/src/MosaicClient.d.ts.map +1 -0
  9. package/dist/src/MosaicClient.js +213 -0
  10. package/dist/src/MosaicClient.js.map +1 -0
  11. package/dist/src/Param.d.ts +56 -0
  12. package/dist/src/Param.d.ts.map +1 -0
  13. package/dist/src/Param.js +89 -0
  14. package/dist/src/Param.js.map +1 -0
  15. package/dist/src/QueryConsolidator.d.ts +11 -0
  16. package/dist/src/QueryConsolidator.d.ts.map +1 -0
  17. package/dist/src/QueryConsolidator.js +249 -0
  18. package/dist/src/QueryConsolidator.js.map +1 -0
  19. package/dist/src/QueryManager.d.ts +77 -0
  20. package/dist/src/QueryManager.d.ts.map +1 -0
  21. package/dist/src/QueryManager.js +174 -0
  22. package/dist/src/QueryManager.js.map +1 -0
  23. package/dist/src/Selection.d.ts +222 -0
  24. package/dist/src/Selection.d.ts.map +1 -0
  25. package/dist/src/Selection.js +319 -0
  26. package/dist/src/Selection.js.map +1 -0
  27. package/dist/src/SelectionClause.d.ts +192 -0
  28. package/dist/src/SelectionClause.d.ts.map +1 -0
  29. package/dist/src/SelectionClause.js +126 -0
  30. package/dist/src/SelectionClause.js.map +1 -0
  31. package/dist/{types → src}/connectors/Connector.d.ts +6 -5
  32. package/dist/src/connectors/Connector.d.ts.map +1 -0
  33. package/dist/src/connectors/Connector.js +2 -0
  34. package/dist/src/connectors/Connector.js.map +1 -0
  35. package/dist/src/connectors/rest.d.ts +24 -0
  36. package/dist/src/connectors/rest.d.ts.map +1 -0
  37. package/dist/src/connectors/rest.js +37 -0
  38. package/dist/src/connectors/rest.js.map +1 -0
  39. package/dist/src/connectors/socket.d.ts +40 -0
  40. package/dist/src/connectors/socket.d.ts.map +1 -0
  41. package/dist/src/connectors/socket.js +115 -0
  42. package/dist/src/connectors/socket.js.map +1 -0
  43. package/dist/src/connectors/wasm.d.ts +53 -0
  44. package/dist/src/connectors/wasm.d.ts.map +1 -0
  45. package/dist/src/connectors/wasm.js +113 -0
  46. package/dist/src/connectors/wasm.js.map +1 -0
  47. package/dist/src/index.d.ts +28 -0
  48. package/dist/src/index.d.ts.map +1 -0
  49. package/dist/src/index.js +25 -0
  50. package/dist/src/index.js.map +1 -0
  51. package/dist/src/make-client.d.ts +35 -0
  52. package/dist/src/make-client.d.ts.map +1 -0
  53. package/dist/src/make-client.js +52 -0
  54. package/dist/src/make-client.js.map +1 -0
  55. package/dist/{types → src}/preagg/PreAggregator.d.ts +64 -94
  56. package/dist/src/preagg/PreAggregator.d.ts.map +1 -0
  57. package/dist/src/preagg/PreAggregator.js +382 -0
  58. package/dist/src/preagg/PreAggregator.js.map +1 -0
  59. package/dist/{types → src}/preagg/preagg-columns.d.ts +10 -8
  60. package/dist/src/preagg/preagg-columns.d.ts.map +1 -0
  61. package/dist/src/preagg/preagg-columns.js +95 -0
  62. package/dist/src/preagg/preagg-columns.js.map +1 -0
  63. package/dist/src/preagg/sufficient-statistics.d.ts +14 -0
  64. package/dist/src/preagg/sufficient-statistics.d.ts.map +1 -0
  65. package/dist/src/preagg/sufficient-statistics.js +446 -0
  66. package/dist/src/preagg/sufficient-statistics.js.map +1 -0
  67. package/dist/{types → src}/types.d.ts +23 -9
  68. package/dist/src/types.d.ts.map +1 -0
  69. package/dist/src/types.js +2 -0
  70. package/dist/src/types.js.map +1 -0
  71. package/dist/{types → src}/util/AsyncDispatch.d.ts +53 -32
  72. package/dist/src/util/AsyncDispatch.d.ts.map +1 -0
  73. package/dist/src/util/AsyncDispatch.js +188 -0
  74. package/dist/src/util/AsyncDispatch.js.map +1 -0
  75. package/dist/src/util/cache.d.ts +19 -0
  76. package/dist/src/util/cache.d.ts.map +1 -0
  77. package/dist/src/util/cache.js +66 -0
  78. package/dist/src/util/cache.js.map +1 -0
  79. package/dist/src/util/decode-ipc.d.ts +12 -0
  80. package/dist/src/util/decode-ipc.d.ts.map +1 -0
  81. package/{src → dist/src}/util/decode-ipc.js +5 -6
  82. package/dist/src/util/decode-ipc.js.map +1 -0
  83. package/dist/src/util/distinct.d.ts +3 -0
  84. package/dist/src/util/distinct.d.ts.map +1 -0
  85. package/dist/src/util/distinct.js +16 -0
  86. package/dist/src/util/distinct.js.map +1 -0
  87. package/dist/src/util/field-info.d.ts +26 -0
  88. package/dist/src/util/field-info.d.ts.map +1 -0
  89. package/dist/src/util/field-info.js +91 -0
  90. package/dist/src/util/field-info.js.map +1 -0
  91. package/dist/src/util/hash.d.ts +2 -0
  92. package/dist/src/util/hash.d.ts.map +1 -0
  93. package/dist/src/util/hash.js +26 -0
  94. package/dist/src/util/hash.js.map +1 -0
  95. package/dist/src/util/is-activatable.d.ts +8 -0
  96. package/dist/src/util/is-activatable.d.ts.map +1 -0
  97. package/dist/src/util/is-activatable.js +10 -0
  98. package/dist/src/util/is-activatable.js.map +1 -0
  99. package/dist/src/util/is-arrow-table.d.ts +9 -0
  100. package/dist/src/util/is-arrow-table.d.ts.map +1 -0
  101. package/dist/src/util/is-arrow-table.js +11 -0
  102. package/dist/src/util/is-arrow-table.js.map +1 -0
  103. package/dist/src/util/js-type.d.ts +9 -0
  104. package/dist/src/util/js-type.d.ts.map +1 -0
  105. package/dist/src/util/js-type.js +59 -0
  106. package/dist/src/util/js-type.js.map +1 -0
  107. package/dist/{types → src}/util/priority-queue.d.ts +12 -14
  108. package/dist/src/util/priority-queue.d.ts.map +1 -0
  109. package/dist/src/util/priority-queue.js +81 -0
  110. package/dist/src/util/priority-queue.js.map +1 -0
  111. package/dist/src/util/query-result.d.ts +47 -0
  112. package/dist/src/util/query-result.d.ts.map +1 -0
  113. package/dist/src/util/query-result.js +83 -0
  114. package/dist/src/util/query-result.js.map +1 -0
  115. package/dist/src/util/synchronizer.d.ts +36 -0
  116. package/dist/src/util/synchronizer.d.ts.map +1 -0
  117. package/dist/src/util/synchronizer.js +52 -0
  118. package/dist/src/util/synchronizer.js.map +1 -0
  119. package/dist/src/util/throttle.d.ts +12 -0
  120. package/dist/src/util/throttle.d.ts.map +1 -0
  121. package/dist/src/util/throttle.js +51 -0
  122. package/dist/src/util/throttle.js.map +1 -0
  123. package/dist/src/util/to-data-columns.d.ts +22 -0
  124. package/dist/src/util/to-data-columns.d.ts.map +1 -0
  125. package/dist/src/util/to-data-columns.js +51 -0
  126. package/dist/src/util/to-data-columns.js.map +1 -0
  127. package/dist/src/util/void-logger.d.ts +13 -0
  128. package/dist/src/util/void-logger.d.ts.map +1 -0
  129. package/dist/src/util/void-logger.js +13 -0
  130. package/dist/src/util/void-logger.js.map +1 -0
  131. package/package.json +15 -13
  132. package/src/Coordinator.ts +367 -0
  133. package/src/{MosaicClient.js → MosaicClient.ts} +49 -43
  134. package/src/{Param.js → Param.ts} +29 -28
  135. package/src/{QueryConsolidator.js → QueryConsolidator.ts} +81 -58
  136. package/src/{QueryManager.js → QueryManager.ts} +61 -54
  137. package/src/Selection.ts +388 -0
  138. package/src/SelectionClause.ts +275 -0
  139. package/src/connectors/Connector.ts +6 -6
  140. package/src/connectors/rest.ts +56 -0
  141. package/src/connectors/{socket.js → socket.ts} +53 -42
  142. package/src/connectors/{wasm.js → wasm.ts} +46 -62
  143. package/src/{index.js → index.ts} +13 -1
  144. package/src/make-client.ts +93 -0
  145. package/src/preagg/{PreAggregator.js → PreAggregator.ts} +164 -145
  146. package/src/preagg/{preagg-columns.js → preagg-columns.ts} +27 -24
  147. package/src/preagg/{sufficient-statistics.js → sufficient-statistics.ts} +161 -110
  148. package/src/types.ts +24 -9
  149. package/src/util/{AsyncDispatch.js → AsyncDispatch.ts} +62 -43
  150. package/src/util/{cache.js → cache.ts} +25 -15
  151. package/src/util/decode-ipc.ts +15 -0
  152. package/src/util/{distinct.js → distinct.ts} +3 -3
  153. package/src/util/{field-info.js → field-info.ts} +31 -32
  154. package/src/util/{hash.js → hash.ts} +4 -4
  155. package/src/util/is-activatable.ts +11 -0
  156. package/src/util/is-arrow-table.ts +12 -0
  157. package/src/util/{js-type.js → js-type.ts} +7 -5
  158. package/src/util/{priority-queue.js → priority-queue.ts} +32 -20
  159. package/src/util/{query-result.js → query-result.ts} +24 -17
  160. package/src/util/synchronizer.ts +56 -0
  161. package/src/util/throttle.ts +59 -0
  162. package/src/util/to-data-columns.ts +65 -0
  163. package/src/util/void-logger.ts +23 -0
  164. package/dist/types/Coordinator.d.ts +0 -164
  165. package/dist/types/Param.d.ts +0 -47
  166. package/dist/types/QueryConsolidator.d.ts +0 -9
  167. package/dist/types/QueryManager.d.ts +0 -91
  168. package/dist/types/Selection.d.ts +0 -235
  169. package/dist/types/SelectionClause.d.ts +0 -105
  170. package/dist/types/connectors/rest.d.ts +0 -13
  171. package/dist/types/connectors/socket.d.ts +0 -100
  172. package/dist/types/connectors/wasm.d.ts +0 -135
  173. package/dist/types/index-types.d.ts +0 -4
  174. package/dist/types/index.d.ts +0 -19
  175. package/dist/types/make-client.d.ts +0 -78
  176. package/dist/types/preagg/sufficient-statistics.d.ts +0 -13
  177. package/dist/types/util/cache.d.ts +0 -17
  178. package/dist/types/util/decode-ipc.d.ts +0 -12
  179. package/dist/types/util/distinct.d.ts +0 -2
  180. package/dist/types/util/field-info.d.ts +0 -23
  181. package/dist/types/util/hash.d.ts +0 -1
  182. package/dist/types/util/is-activatable.d.ts +0 -6
  183. package/dist/types/util/is-arrow-table.d.ts +0 -8
  184. package/dist/types/util/js-type.d.ts +0 -7
  185. package/dist/types/util/query-result.d.ts +0 -44
  186. package/dist/types/util/selection-types.d.ts +0 -114
  187. package/dist/types/util/synchronizer.d.ts +0 -29
  188. package/dist/types/util/throttle.d.ts +0 -13
  189. package/dist/types/util/to-data-columns.d.ts +0 -29
  190. package/dist/types/util/void-logger.d.ts +0 -10
  191. package/jsconfig.json +0 -11
  192. package/src/Coordinator.js +0 -337
  193. package/src/Selection.js +0 -380
  194. package/src/SelectionClause.js +0 -159
  195. package/src/connectors/rest.js +0 -38
  196. package/src/index-types.ts +0 -4
  197. package/src/make-client.js +0 -101
  198. package/src/util/is-activatable.js +0 -8
  199. package/src/util/is-arrow-table.js +0 -10
  200. package/src/util/selection-types.ts +0 -137
  201. package/src/util/synchronizer.js +0 -47
  202. package/src/util/throttle.js +0 -54
  203. package/src/util/to-data-columns.js +0 -60
  204. package/src/util/void-logger.js +0 -13
  205. package/tsconfig.json +0 -11
  206. package/vitest.config.ts +0 -3
@@ -1,10 +1,30 @@
1
- /**
2
- * @typedef {object} PreAggregateOptions
3
- * @property {string} [schema] Database schema (namespace) in which to write
4
- * pre-aggregated materialzied views (default 'mosaic').
5
- * @property {boolean} [options.enabled=true] Flag to enable or disable the
6
- * pre-aggregation. This flag can be updated later via the `enabled` property.
7
- */
1
+ import { ExprNode, SelectQuery, MaybeArray } from '@uwdata/mosaic-sql';
2
+ import type { Coordinator } from '../Coordinator.js';
3
+ import type { MosaicClient } from '../MosaicClient.js';
4
+ import type { Selection } from '../Selection.js';
5
+ import type { ClauseSource, SelectionClause } from '../SelectionClause.js';
6
+ declare const Skip: {
7
+ skip: boolean;
8
+ result: null;
9
+ };
10
+ export interface PreAggregateOptions {
11
+ /** Database schema (namespace) in which to write pre-aggregated materialized views (default 'mosaic'). */
12
+ schema?: string;
13
+ /** Flag to enable or disable the pre-aggregation. This flag can be updated later via the `enabled` property. */
14
+ enabled?: boolean;
15
+ }
16
+ type ActivePredicate = (p?: ExprNode) => MaybeArray<ExprNode> | undefined;
17
+ interface ActiveColumnsResult {
18
+ source: ClauseSource | null;
19
+ columns?: Record<string, ExprNode>;
20
+ predicate?: ActivePredicate;
21
+ }
22
+ interface PreAggregateInfoOptions {
23
+ table: string;
24
+ create: string;
25
+ active: ActiveColumnsResult;
26
+ select: SelectQuery;
27
+ }
8
28
  /**
9
29
  * Build and query optimized pre-aggregated materaialized views, for fast
10
30
  * computation of groupby aggregate queries over compatible client queries
@@ -24,33 +44,29 @@
24
44
  * schema. This may be needed if the original tables have updated data, but
25
45
  * should be used with care.
26
46
  */
27
- export class PreAggregator {
47
+ export declare class PreAggregator {
48
+ entries: Map<MosaicClient, PreAggregateInfo | typeof Skip | null>;
49
+ private active;
50
+ private mc;
51
+ private _schema;
52
+ private _enabled;
28
53
  /**
29
54
  * Create a new manager of materialized views of pre-aggregated data.
30
- * @param {Coordinator} coordinator A Mosaic coordinator.
31
- * @param {PreAggregateOptions} [options] Pre-aggregation options.
55
+ * @param coordinator A Mosaic coordinator.
56
+ * @param options Pre-aggregation options.
32
57
  */
33
58
  constructor(coordinator: Coordinator, { schema, enabled }?: PreAggregateOptions);
34
- /** @type {Map<MosaicClient, PreAggregateInfo | Skip | null>} */
35
- entries: Map<MosaicClient, PreAggregateInfo | {
36
- skip: boolean;
37
- result: any;
38
- } | null>;
39
- active: any;
40
- mc: Coordinator;
41
- _schema: string;
42
- _enabled: boolean;
43
59
  /**
44
60
  * Set the enabled state of this manager. If false, any local state is
45
61
  * cleared and subsequent request calls will return null until re-enabled.
46
62
  * This method has no effect on any pre-aggregated tables already in the
47
63
  * database.
48
- * @param {boolean} [state] The enabled state to set.
64
+ * @param state The enabled state to set.
49
65
  */
50
66
  set enabled(state: boolean);
51
67
  /**
52
68
  * Get the enabled state of this manager.
53
- * @returns {boolean} The current enabled state.
69
+ * @returns The current enabled state.
54
70
  */
55
71
  get enabled(): boolean;
56
72
  /**
@@ -58,12 +74,12 @@ export class PreAggregator {
58
74
  * Upon changes, any local state is cleared. This method does _not_ drop any
59
75
  * existing materialized views, use `dropSchema` before changing the schema
60
76
  * to also remove existing materalized views in the database.
61
- * @param {string} [schema] The schema name to set.
77
+ * @param schema The schema name to set.
62
78
  */
63
79
  set schema(schema: string);
64
80
  /**
65
81
  * Get the database schema used for pre-aggregated materialized view tables.
66
- * @returns {string} The current schema name.
82
+ * @returns The current schema name.
67
83
  */
68
84
  get schema(): string;
69
85
  /**
@@ -75,7 +91,7 @@ export class PreAggregator {
75
91
  * the schema will be repopulated by future pre-aggregation requests.
76
92
  * @returns A query result promise.
77
93
  */
78
- dropSchema(): import("../util/query-result.js").QueryResult;
94
+ dropSchema(): Promise<unknown>;
79
95
  /**
80
96
  * Clear the cache of pre-aggregation entries for the current active
81
97
  * selection clause. This method does _not_ drop any existing materialized
@@ -88,17 +104,14 @@ export class PreAggregator {
88
104
  * client-selection pair, or null if the client has unstable filters.
89
105
  * This method has multiple possible side effects, including materialized
90
106
  * view creation and updating internal caches.
91
- * @param {MosaicClient} client A Mosaic client.
92
- * @param {Selection} selection A Mosaic selection to filter the client by.
93
- * @param {SelectionClause} activeClause A representative active selection
107
+ * @param client A Mosaic client.
108
+ * @param selection A Mosaic selection to filter the client by.
109
+ * @param activeClause A representative active selection
94
110
  * clause for which to generate materialized views of pre-aggregates.
95
- * @returns {PreAggregateInfo | Skip | null} Information and query generator
111
+ * @returns Information and query generator
96
112
  * for pre-aggregated tables, or null if the client has unstable filters.
97
113
  */
98
- request(client: MosaicClient, selection: Selection, activeClause: SelectionClause): PreAggregateInfo | {
99
- skip: boolean;
100
- result: any;
101
- } | null;
114
+ request(client: MosaicClient, selection: Selection, activeClause: SelectionClause | null): PreAggregateInfo | typeof Skip | null;
102
115
  }
103
116
  /**
104
117
  * Metadata and query generator for materialized views of pre-aggregated data.
@@ -106,75 +119,32 @@ export class PreAggregator {
106
119
  * materialized views for a client-selection pair relative to a specific
107
120
  * active clause and selection state.
108
121
  */
109
- export class PreAggregateInfo {
110
- /**
111
- * Create a new pre-aggregation information instance.
112
- * @param {object} options Options object.
113
- * @param {string} options.table The materialized view table name.
114
- * @param {string} options.create The table creation query.
115
- * @param {*} options.active Active column information.
116
- * @param {SelectQuery} options.select Base query for requesting updates
117
- * using a pre-aggregated materialized view.
118
- */
119
- constructor({ table, create, active, select }: {
120
- table: string;
121
- create: string;
122
- active: any;
123
- select: SelectQuery;
124
- });
125
- /**
126
- * The name of the materialized view.
127
- * @type {string}
128
- */
122
+ export declare class PreAggregateInfo {
123
+ /** The name of the materialized view. */
129
124
  table: string;
130
- /**
131
- * The SQL query used to generate the materialized view.
132
- * @type {string}
133
- */
125
+ /** The SQL query used to generate the materialized view. */
134
126
  create: string;
135
- /**
136
- * A result promise returned for the materialized view creation query.
137
- * @type {Promise | null}
138
- */
139
- result: Promise<any> | null;
140
- /**
141
- * Definitions and predicate function for the active columns,
142
- * which are dynamically filtered by the active clause.
143
- */
144
- active: any;
145
- /**
146
- * Select query (sans where clause) for materialized views.
147
- * @type {SelectQuery}
148
- */
127
+ /** A result promise returned for the materialized view creation query. */
128
+ result: Promise<unknown> | null;
129
+ /** Definitions and predicate function for the active columns,
130
+ * which are dynamically filtered by the active clause. */
131
+ active: ActiveColumnsResult;
132
+ /** Select query (sans where clause) for materialized views. */
149
133
  select: SelectQuery;
134
+ /** Boolean flag indicating a client that should be skipped.
135
+ * This value is always false for a created materialized view. */
136
+ skip: boolean;
150
137
  /**
151
- * Boolean flag indicating a client that should be skipped.
152
- * This value is always false for a created materialized view.
153
- * @type {boolean}
138
+ * Create a new pre-aggregation information instance.
139
+ * @param options Options object.
154
140
  */
155
- skip: boolean;
141
+ constructor({ table, create, active, select }: PreAggregateInfoOptions);
156
142
  /**
157
143
  * Generate a materialized view query for the given predicate.
158
- * @param {ExprNode} predicate The current active clause predicate.
159
- * @returns {SelectQuery} A materialized view query.
144
+ * @param predicate The current active clause predicate.
145
+ * @returns A materialized view query.
160
146
  */
161
147
  query(predicate: ExprNode): SelectQuery;
162
148
  }
163
- export type PreAggregateOptions = {
164
- /**
165
- * Database schema (namespace) in which to write
166
- * pre-aggregated materialzied views (default 'mosaic').
167
- */
168
- schema?: string;
169
- /**
170
- * Flag to enable or disable the
171
- * pre-aggregation. This flag can be updated later via the `enabled` property.
172
- */
173
- enabled?: boolean;
174
- };
175
- import type { MosaicClient } from '../MosaicClient.js';
176
- import type { Coordinator } from '../Coordinator.js';
177
- import type { Selection } from '../Selection.js';
178
- import type { SelectionClause } from '../util/selection-types.js';
179
- import type { SelectQuery } from '@uwdata/mosaic-sql';
180
- import type { ExprNode } from '@uwdata/mosaic-sql';
149
+ export {};
150
+ //# sourceMappingURL=PreAggregator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreAggregator.d.ts","sourceRoot":"","sources":["../../../src/preagg/PreAggregator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAgB,WAAW,EAAoB,UAAU,EAAwC,MAAM,oBAAoB,CAAC;AAC7I,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAa,YAAY,EAAoB,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAKxG,QAAA,MAAM,IAAI;;;CAA+B,CAAC;AAE1C,MAAM,WAAW,mBAAmB;IAClC,0GAA0G;IAC1G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gHAAgH;IAChH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,KAAK,eAAe,GAAG,CAAC,CAAC,CAAC,EAAE,QAAQ,KAAK,UAAU,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;AAE1E,UAAU,mBAAmB;IAC3B,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACnC,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,UAAU,uBAAuB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,mBAAmB,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AE,OAAO,CAAC;IAEd;;;OAGG;gBACS,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,uBAAuB;IAStE;;;;OAIG;IACH,KAAK,CAAC,SAAS,EAAE,QAAQ,GAAG,WAAW;CAGxC"}
@@ -0,0 +1,382 @@
1
+ import { Query as QueryBuilder, and, asNode, ceil, collectColumns, createTable, float64, floor, isBetween, int32, mul, round, scaleTransform, sub, isSelectQuery, isAggregateExpression, ColumnNameRefNode } from '@uwdata/mosaic-sql';
2
+ import { preaggColumns } from './preagg-columns.js';
3
+ import { fnv_hash } from '../util/hash.js';
4
+ const Skip = { skip: true, result: null };
5
+ /**
6
+ * Build and query optimized pre-aggregated materaialized views, for fast
7
+ * computation of groupby aggregate queries over compatible client queries
8
+ * and selections. The materialized views contains pre-aggregated data for a
9
+ * Mosaic client, subdivided by possible query values from an active selection
10
+ * clause. These materialized views are database tables that can be queried
11
+ * for rapid updates.
12
+ *
13
+ * Compatible client queries must consist of only groupby dimensions and
14
+ * supported aggregate functions. Compatible selections must contain an active
15
+ * clause that exposes metadata for an interval or point value predicate.
16
+ *
17
+ * Materialized views are written to a dedicated schema (namespace) that
18
+ * can be set using the *schema* constructor option. This schema acts as a
19
+ * persistent cache, and materialized view tables may be used across sessions.
20
+ * The `dropSchema` method issues a query to remove *all* tables within this
21
+ * schema. This may be needed if the original tables have updated data, but
22
+ * should be used with care.
23
+ */
24
+ export class PreAggregator {
25
+ entries;
26
+ active;
27
+ mc;
28
+ _schema;
29
+ _enabled;
30
+ /**
31
+ * Create a new manager of materialized views of pre-aggregated data.
32
+ * @param coordinator A Mosaic coordinator.
33
+ * @param options Pre-aggregation options.
34
+ */
35
+ constructor(coordinator, { schema = 'mosaic', enabled = true } = {}) {
36
+ this.entries = new Map();
37
+ this.active = null;
38
+ this.mc = coordinator;
39
+ this._schema = schema;
40
+ this._enabled = enabled;
41
+ }
42
+ /**
43
+ * Set the enabled state of this manager. If false, any local state is
44
+ * cleared and subsequent request calls will return null until re-enabled.
45
+ * This method has no effect on any pre-aggregated tables already in the
46
+ * database.
47
+ * @param state The enabled state to set.
48
+ */
49
+ set enabled(state) {
50
+ if (this._enabled !== state) {
51
+ if (!state)
52
+ this.clear();
53
+ this._enabled = state;
54
+ }
55
+ }
56
+ /**
57
+ * Get the enabled state of this manager.
58
+ * @returns The current enabled state.
59
+ */
60
+ get enabled() {
61
+ return this._enabled;
62
+ }
63
+ /**
64
+ * Set the database schema used for pre-aggregated materialized view tables.
65
+ * Upon changes, any local state is cleared. This method does _not_ drop any
66
+ * existing materialized views, use `dropSchema` before changing the schema
67
+ * to also remove existing materalized views in the database.
68
+ * @param schema The schema name to set.
69
+ */
70
+ set schema(schema) {
71
+ if (this._schema !== schema) {
72
+ this.clear();
73
+ this._schema = schema;
74
+ }
75
+ }
76
+ /**
77
+ * Get the database schema used for pre-aggregated materialized view tables.
78
+ * @returns The current schema name.
79
+ */
80
+ get schema() {
81
+ return this._schema;
82
+ }
83
+ /**
84
+ * Issues a query through the coordinator to drop the current schema for
85
+ * pre-aggregated materialized views. *All* materialized view tables in the
86
+ * schema will be removed and local state is cleared. Call this method if
87
+ * the underlying base tables have been updated, causing materialized view
88
+ * to become stale and inaccurate. Use this method with care! Once dropped,
89
+ * the schema will be repopulated by future pre-aggregation requests.
90
+ * @returns A query result promise.
91
+ */
92
+ dropSchema() {
93
+ this.clear();
94
+ return this.mc.exec(`DROP SCHEMA IF EXISTS "${this.schema}" CASCADE`);
95
+ }
96
+ /**
97
+ * Clear the cache of pre-aggregation entries for the current active
98
+ * selection clause. This method does _not_ drop any existing materialized
99
+ * views. Use `dropSchema` to remove existing materialized view tables from
100
+ * the database.
101
+ */
102
+ clear() {
103
+ this.entries.clear();
104
+ this.active = null;
105
+ }
106
+ /**
107
+ * Return pre-aggregation information for the active state of a
108
+ * client-selection pair, or null if the client has unstable filters.
109
+ * This method has multiple possible side effects, including materialized
110
+ * view creation and updating internal caches.
111
+ * @param client A Mosaic client.
112
+ * @param selection A Mosaic selection to filter the client by.
113
+ * @param activeClause A representative active selection
114
+ * clause for which to generate materialized views of pre-aggregates.
115
+ * @returns Information and query generator
116
+ * for pre-aggregated tables, or null if the client has unstable filters.
117
+ */
118
+ request(client, selection, activeClause) {
119
+ // if not enabled, do nothing
120
+ if (!this.enabled || activeClause == null)
121
+ return null;
122
+ const { entries, mc, schema } = this;
123
+ const { source } = activeClause;
124
+ // if there is no clause source to track, do nothing
125
+ if (!source)
126
+ return null;
127
+ // if we have cached active columns, check for updates or exit
128
+ if (this.active) {
129
+ // if the active clause source has changed, clear the state
130
+ // this cancels outstanding requests and clears the local cache
131
+ // a clear also sets this.active to null
132
+ if (this.active.source !== source)
133
+ this.clear();
134
+ // if we've seen this source and it has unstable filters, do nothing
135
+ if (this.active?.source === null)
136
+ return null;
137
+ }
138
+ // the current active columns cache value
139
+ let { active } = this;
140
+ // if cached active columns are unset, analyze the active clause
141
+ if (!active) {
142
+ // if active clause predicate is null, we can't analyze it
143
+ // return null to backoff to standard client query
144
+ // non-null clauses may come later, so don't set active state
145
+ if (activeClause.predicate == null)
146
+ return null;
147
+ // generate active dimension columns to select over
148
+ // will return an object with null source if it has unstable filters
149
+ this.active = active = activeColumns(activeClause);
150
+ // if the active clause has unstable filters, exit now
151
+ if (active.source === null)
152
+ return null;
153
+ }
154
+ // if we have cached pre-aggregate info, return that
155
+ if (entries.has(client)) {
156
+ return entries.get(client);
157
+ }
158
+ // get non-active materialized view columns
159
+ const preaggCols = preaggColumns(client);
160
+ let info;
161
+ if (!preaggCols) {
162
+ // if client is not indexable, record null info
163
+ info = null;
164
+ }
165
+ else if (selection.skip(client, activeClause)) {
166
+ // skip client if untouched by cross-filtering
167
+ info = Skip;
168
+ }
169
+ else {
170
+ // generate materialized view table
171
+ const filter = selection.remove(source).predicate(client);
172
+ info = preaggregateInfo(client.query(filter), active, preaggCols, schema);
173
+ info.result = mc.exec([
174
+ `CREATE SCHEMA IF NOT EXISTS ${schema}`,
175
+ createTable(info.table, info.create, { temp: false })
176
+ ]);
177
+ info.result.catch((e) => mc.logger().error(e));
178
+ }
179
+ entries.set(client, info);
180
+ return info;
181
+ }
182
+ }
183
+ /**
184
+ * Determines the active dimension columns to select over. Returns an object
185
+ * with the clause source, column definitions, and a predicate generator
186
+ * function for the active dimensions of a pre-aggregated materialized view.
187
+ * If the active clause is not indexable or is missing metadata, this method
188
+ * returns an object with a null source property.
189
+ * @param clause The active selection clause to analyze.
190
+ */
191
+ function activeColumns(clause) {
192
+ const { source, meta } = clause;
193
+ const clausePred = clause.predicate;
194
+ const clauseCols = collectColumns(clausePred).map(c => c.column);
195
+ let predicate;
196
+ let columns;
197
+ if (!meta || !clauseCols) {
198
+ return { source: null, columns, predicate };
199
+ }
200
+ switch (meta.type) {
201
+ case 'point':
202
+ predicate = x => x;
203
+ columns = Object.fromEntries(clauseCols.map(col => [`${col}`, asNode(col)]));
204
+ break;
205
+ case 'interval': {
206
+ const { scales, bin, pixelSize = 1 } = meta;
207
+ if (!scales)
208
+ break;
209
+ // determine pixel-level binning
210
+ const bins = scales.map((s) => binInterval(s, pixelSize, bin));
211
+ if (bins.some(b => !b)) {
212
+ // bail if a scale type is unsupported
213
+ }
214
+ else if (bins.length === 1) {
215
+ // selection clause predicate has type BetweenOpNode
216
+ // single interval selection
217
+ predicate = (p) => p
218
+ ? isBetween('active0', p.extent?.map(bins[0]))
219
+ : [];
220
+ columns = { active0: bins[0](clausePred.expr) };
221
+ }
222
+ else {
223
+ // selection clause predicate has type AndNode<BetweenOpNode>
224
+ // multiple interval selection
225
+ predicate = (p) => p
226
+ ? and(p.clauses.map((c, i) => isBetween(`active${i}`, c.extent?.map(bins[i]))))
227
+ : [];
228
+ columns = Object.fromEntries(clausePred.clauses.map((p, i) => [`active${i}`, bins[i](p.expr)]));
229
+ }
230
+ }
231
+ }
232
+ return { source: columns ? source : null, columns, predicate };
233
+ }
234
+ const BIN = { ceil, round };
235
+ /**
236
+ * Returns a bin function generator to discretize a selection interval domain.
237
+ * @param scale A scale that maps domain values to the output range
238
+ * (typically pixels).
239
+ * @param pixelSize The interactive pixel size. This value indicates
240
+ * the bin step size and may be greater than an actual screen pixel.
241
+ * @param bin The binning method to apply, one of `floor`, `ceil', or `round`.
242
+ * @returns A bin function generator.
243
+ */
244
+ function binInterval(scale, pixelSize, bin) {
245
+ const { type, domain, range, apply, sqlApply } = scaleTransform(scale);
246
+ if (!apply)
247
+ return; // unsupported scale type
248
+ const binFn = BIN[`${bin}`.toLowerCase()] || floor;
249
+ const dom = domain.map(x => Number(x));
250
+ const lo = apply(Math.min(...dom));
251
+ const hi = apply(Math.max(...dom));
252
+ const s = (type === 'identity'
253
+ ? 1
254
+ : Math.abs(range[1] - range[0]) / (hi - lo)) / pixelSize;
255
+ const scalar = s === 1
256
+ ? (x) => x
257
+ : (x) => mul(float64(s), x);
258
+ const diff = lo === 0
259
+ ? (x) => x
260
+ : (x) => sub(x, float64(lo));
261
+ return value => int32(binFn(scalar(diff(sqlApply(value)))));
262
+ }
263
+ /**
264
+ * Generate pre-aggregate query information.
265
+ * @param clientQuery The original client query.
266
+ * @param active Active (selected) columns.
267
+ * @param preaggCols Pre-aggregation columns.
268
+ * @param schema Database schema name.
269
+ * @returns Pre-aggregation information.
270
+ */
271
+ function preaggregateInfo(clientQuery, active, preaggCols, schema) {
272
+ const { group, output, preagg } = preaggCols;
273
+ const { columns } = active;
274
+ // build materialized view construction query
275
+ const query = clientQuery
276
+ .setSelect({ ...preagg, ...columns })
277
+ .groupby(Object.keys(columns));
278
+ // ensure active clause columns are selected by subqueries
279
+ const [subq] = query.subqueries;
280
+ if (subq) {
281
+ const cols = Object.values(columns)
282
+ .flatMap(c => collectColumns(c).map(c => c.column));
283
+ subqueryPushdown(subq, cols);
284
+ }
285
+ // push any having or orderby criteria to output queries
286
+ const having = query._having;
287
+ const order = query._orderby;
288
+ query._having = [];
289
+ query._orderby = [];
290
+ // generate creation query string and hash id
291
+ const create = query.toString();
292
+ const id = (fnv_hash(create) >>> 0).toString(16);
293
+ const table = `${schema}.preagg_${id}`;
294
+ // generate preaggregate select query
295
+ const select = QueryBuilder
296
+ .select(group, output)
297
+ .from(table)
298
+ .groupby(group)
299
+ .having(having)
300
+ .orderby(order);
301
+ return new PreAggregateInfo({ table, create, active, select });
302
+ }
303
+ /**
304
+ * Push column selections down to subqueries.
305
+ * @param query The (sub)query to push down to.
306
+ * @param cols The column names to push down.
307
+ */
308
+ function subqueryPushdown(query, cols) {
309
+ const memo = new Set();
310
+ const pushdown = (q) => {
311
+ // it is possible to have duplicate subqueries
312
+ // so we memoize and exit early if already seen
313
+ if (memo.has(q))
314
+ return;
315
+ memo.add(q);
316
+ if (isSelectQuery(q) && q._from.length) {
317
+ // select the pushed down columns
318
+ // note that the select method will deduplicate for us
319
+ q.select(cols);
320
+ if (isAggregateQuery(q)) {
321
+ // if an aggregation query, we need to push to groupby as well
322
+ // we also deduplicate as the column may already be present
323
+ const set = new Set(q._groupby.flatMap(x => x instanceof ColumnNameRefNode ? [x.name] : []));
324
+ q.groupby(cols.filter(c => !set.has(c)));
325
+ }
326
+ }
327
+ q.subqueries.forEach(pushdown);
328
+ };
329
+ pushdown(query);
330
+ }
331
+ /**
332
+ * Test if a query performs aggregation.
333
+ * @param query Select query to test.
334
+ * @returns True if query performs aggregation.
335
+ */
336
+ function isAggregateQuery(query) {
337
+ return query._groupby.length > 0
338
+ || query._select.some(node => isAggregateExpression(node));
339
+ }
340
+ /**
341
+ * Metadata and query generator for materialized views of pre-aggregated data.
342
+ * This object provides the information needed to generate and query the
343
+ * materialized views for a client-selection pair relative to a specific
344
+ * active clause and selection state.
345
+ */
346
+ export class PreAggregateInfo {
347
+ /** The name of the materialized view. */
348
+ table;
349
+ /** The SQL query used to generate the materialized view. */
350
+ create;
351
+ /** A result promise returned for the materialized view creation query. */
352
+ result;
353
+ /** Definitions and predicate function for the active columns,
354
+ * which are dynamically filtered by the active clause. */
355
+ active;
356
+ /** Select query (sans where clause) for materialized views. */
357
+ select;
358
+ /** Boolean flag indicating a client that should be skipped.
359
+ * This value is always false for a created materialized view. */
360
+ skip;
361
+ /**
362
+ * Create a new pre-aggregation information instance.
363
+ * @param options Options object.
364
+ */
365
+ constructor({ table, create, active, select }) {
366
+ this.table = table;
367
+ this.create = create;
368
+ this.result = null;
369
+ this.active = active;
370
+ this.select = select;
371
+ this.skip = false;
372
+ }
373
+ /**
374
+ * Generate a materialized view query for the given predicate.
375
+ * @param predicate The current active clause predicate.
376
+ * @returns A materialized view query.
377
+ */
378
+ query(predicate) {
379
+ return this.select.clone().where(this.active.predicate(predicate));
380
+ }
381
+ }
382
+ //# sourceMappingURL=PreAggregator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PreAggregator.js","sourceRoot":"","sources":["../../../src/preagg/PreAggregator.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,EAAE,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,aAAa,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvO,OAAO,EAAE,aAAa,EAAuB,MAAM,qBAAqB,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;AAwB1C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,OAAO,aAAa;IACjB,OAAO,CAA2D;IACjE,MAAM,CAA6B;IACnC,EAAE,CAAc;IAChB,OAAO,CAAS;IAChB,QAAQ,CAAU;IAE1B;;;;OAIG;IACH,YAAY,WAAwB,EAAE,EACpC,MAAM,GAAG,QAAQ,EACjB,OAAO,GAAG,IAAI,KACS,EAAE;QACzB,IAAI,CA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AAM,GAAG,CAAC;WAC3B,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAC3B,yCAAyC;IACzC,KAAK,CAAS;IACd,4DAA4D;IAC5D,MAAM,CAAS;IACf,0EAA0E;IAC1E,MAAM,CAA0B;IAChC;8DAC0D;IAC1D,MAAM,CAAsB;IAC5B,+DAA+D;IAC/D,MAAM,CAAc;IACpB;qEACiE;IACjE,IAAI,CAAU;IAEd;;;OAGG;IACH,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAA2B;QACpE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC;IACpB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,SAAmB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,SAAU,CAAC,SAAS,CAAE,CAAC,CAAC;IACvE,CAAC;CACF"}
@@ -1,14 +1,16 @@
1
+ import type { ExprNode } from '@uwdata/mosaic-sql';
2
+ import type { MosaicClient } from '../MosaicClient.js';
3
+ export interface PreAggColumnsResult {
4
+ group: string[];
5
+ preagg: Record<string, ExprNode>;
6
+ output: Record<string, ExprNode>;
7
+ }
1
8
  /**
2
9
  * Determine pre-aggregation columns for a given Mosaic client.
3
- * @param {MosaicClient} client The Mosaic client.
10
+ * @param client The Mosaic client.
4
11
  * @returns An object with necessary column data to generate pre-aggregated
5
12
  * columns, or null if the client can't be optimized or the client query
6
13
  * contains an invalid or unsupported expression.
7
14
  */
8
- export function preaggColumns(client: MosaicClient): {
9
- group: string[];
10
- preagg: Record<string, ExprNode>;
11
- output: Record<string, ExprNode>;
12
- };
13
- import type { MosaicClient } from '../MosaicClient.js';
14
- import type { ExprNode } from '@uwdata/mosaic-sql';
15
+ export declare function preaggColumns(client: MosaicClient): PreAggColumnsResult | null;
16
+ //# sourceMappingURL=preagg-columns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preagg-columns.d.ts","sourceRoot":"","sources":["../../../src/preagg/preagg-columns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgC,QAAQ,EAAsB,MAAM,oBAAoB,CAAC;AACrG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IACjC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,GAAG,mBAAmB,GAAG,IAAI,CA0D9E"}