@uwdata/mosaic-core 0.14.1 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/types/Coordinator.d.ts +37 -42
- package/dist/types/MosaicClient.d.ts +76 -44
- package/dist/types/QueryManager.d.ts +42 -17
- package/dist/types/Selection.d.ts +1 -1
- package/dist/types/SelectionClause.d.ts +1 -1
- package/dist/types/connectors/Connector.d.ts +25 -0
- package/dist/types/connectors/rest.d.ts +13 -17
- package/dist/types/connectors/socket.d.ts +98 -16
- package/dist/types/connectors/wasm.d.ts +133 -14
- package/dist/types/index-types.d.ts +1 -0
- package/dist/types/make-client.d.ts +51 -21
- package/dist/types/preagg/PreAggregator.d.ts +18 -16
- package/dist/types/preagg/preagg-columns.d.ts +2 -2
- package/dist/types/preagg/sufficient-statistics.d.ts +2 -2
- package/dist/types/types.d.ts +21 -0
- package/dist/types/util/cache.d.ts +14 -10
- package/dist/types/util/decode-ipc.d.ts +9 -4
- package/dist/types/util/void-logger.d.ts +3 -0
- package/package.json +4 -4
- package/src/Coordinator.js +36 -44
- package/src/MosaicClient.js +110 -46
- package/src/QueryConsolidator.js +2 -1
- package/src/QueryManager.js +31 -0
- package/src/Selection.js +4 -2
- package/src/SelectionClause.js +5 -2
- package/src/connectors/Connector.ts +30 -0
- package/src/connectors/rest.js +14 -12
- package/src/connectors/socket.js +112 -77
- package/src/connectors/wasm.js +118 -55
- package/src/index-types.ts +1 -0
- package/src/make-client.js +68 -31
- package/src/preagg/PreAggregator.js +20 -17
- package/src/preagg/preagg-columns.js +5 -2
- package/src/preagg/sufficient-statistics.js +2 -1
- package/src/types.ts +23 -0
- package/src/util/cache.js +20 -5
- package/src/util/decode-ipc.js +9 -5
- package/src/util/field-info.js +2 -1
- package/src/util/js-type.js +3 -1
- package/src/util/void-logger.js +4 -1
|
@@ -1,16 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {object} DuckDBWASMOptions
|
|
3
|
+
* @property {boolean} [log] Flag to enable logging.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {object} DuckDBWASMConnectorOptions
|
|
7
|
+
* @property {boolean} [log] Flag to enable logging.
|
|
8
|
+
* @property {ExtractionOptions} [ipc]
|
|
9
|
+
* Arrow IPC extraction options.
|
|
10
|
+
* @property {duckdb.AsyncDuckDB} [duckdb]
|
|
11
|
+
* Optional pre-existing DuckDB-WASM instance.
|
|
12
|
+
* @property {duckdb.AsyncDuckDBConnection} [connection]
|
|
13
|
+
* Optional pre-existing DuckDB-WASM connection.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Connect to a DuckDB-WASM instance.
|
|
17
|
+
* @param {DuckDBWASMConnectorOptions} [options] Connector options.
|
|
18
|
+
* @returns {DuckDBWASMConnector} A connector instance.
|
|
19
|
+
*/
|
|
20
|
+
export function wasmConnector(options?: DuckDBWASMConnectorOptions): DuckDBWASMConnector;
|
|
21
|
+
/**
|
|
22
|
+
* DuckDB-WASM connector.
|
|
23
|
+
* @implements {Connector}
|
|
24
|
+
*/
|
|
25
|
+
export class DuckDBWASMConnector implements Connector {
|
|
26
|
+
/**
|
|
27
|
+
* Create a new DuckDB-WASM connector instance.
|
|
28
|
+
* @param {DuckDBWASMConnectorOptions} [options]
|
|
29
|
+
*/
|
|
30
|
+
constructor(options?: DuckDBWASMConnectorOptions);
|
|
31
|
+
/** @type {ExtractionOptions} */
|
|
32
|
+
_ipc: ExtractionOptions;
|
|
33
|
+
/** @type {DuckDBWASMOptions} */
|
|
34
|
+
_options: DuckDBWASMOptions;
|
|
35
|
+
/** @type {duckdb.AsyncDuckDB} */
|
|
36
|
+
_db: duckdb.AsyncDuckDB;
|
|
37
|
+
/** @type {duckdb.AsyncDuckDBConnection} */
|
|
38
|
+
_con: duckdb.AsyncDuckDBConnection;
|
|
39
|
+
/** @type {Promise<unknown>} */
|
|
40
|
+
_loadPromise: Promise<unknown>;
|
|
41
|
+
/**
|
|
42
|
+
* Get the backing DuckDB-WASM instance.
|
|
43
|
+
* Lazily initializes DuckDB-WASM if not already loaded.
|
|
44
|
+
* @returns {Promise<duckdb.AsyncDuckDB>} The DuckDB-WASM instance.
|
|
45
|
+
*/
|
|
46
|
+
getDuckDB(): Promise<duckdb.AsyncDuckDB>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the backing DuckDB-WASM connection.
|
|
49
|
+
* Lazily initializes DuckDB-WASM if not already loaded.
|
|
50
|
+
* @returns {Promise<duckdb.AsyncDuckDBConnection>} The DuckDB-WASM connection.
|
|
51
|
+
*/
|
|
52
|
+
getConnection(): Promise<duckdb.AsyncDuckDBConnection>;
|
|
53
|
+
/**
|
|
54
|
+
* @overload
|
|
55
|
+
* @param {ArrowQueryRequest} query
|
|
56
|
+
* @returns {Promise<Table>}
|
|
57
|
+
*
|
|
58
|
+
* @overload
|
|
59
|
+
* @param {ExecQueryRequest} query
|
|
60
|
+
* @returns {Promise<void>}
|
|
61
|
+
*
|
|
62
|
+
* @overload
|
|
63
|
+
* @param {JSONQueryRequest} query
|
|
64
|
+
* @returns {Promise<Record<string, any>[]>}
|
|
65
|
+
*
|
|
66
|
+
* @param {ArrowQueryRequest | ExecQueryRequest | JSONQueryRequest} query
|
|
67
|
+
* @returns {Promise<Table | void | Record<string, any>[]>}}
|
|
68
|
+
*/
|
|
69
|
+
query(query: ArrowQueryRequest): Promise<Table>;
|
|
70
|
+
/**
|
|
71
|
+
* @overload
|
|
72
|
+
* @param {ArrowQueryRequest} query
|
|
73
|
+
* @returns {Promise<Table>}
|
|
74
|
+
*
|
|
75
|
+
* @overload
|
|
76
|
+
* @param {ExecQueryRequest} query
|
|
77
|
+
* @returns {Promise<void>}
|
|
78
|
+
*
|
|
79
|
+
* @overload
|
|
80
|
+
* @param {JSONQueryRequest} query
|
|
81
|
+
* @returns {Promise<Record<string, any>[]>}
|
|
82
|
+
*
|
|
83
|
+
* @param {ArrowQueryRequest | ExecQueryRequest | JSONQueryRequest} query
|
|
84
|
+
* @returns {Promise<Table | void | Record<string, any>[]>}}
|
|
85
|
+
*/
|
|
86
|
+
query(query: ExecQueryRequest): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* @overload
|
|
89
|
+
* @param {ArrowQueryRequest} query
|
|
90
|
+
* @returns {Promise<Table>}
|
|
91
|
+
*
|
|
92
|
+
* @overload
|
|
93
|
+
* @param {ExecQueryRequest} query
|
|
94
|
+
* @returns {Promise<void>}
|
|
95
|
+
*
|
|
96
|
+
* @overload
|
|
97
|
+
* @param {JSONQueryRequest} query
|
|
98
|
+
* @returns {Promise<Record<string, any>[]>}
|
|
99
|
+
*
|
|
100
|
+
* @param {ArrowQueryRequest | ExecQueryRequest | JSONQueryRequest} query
|
|
101
|
+
* @returns {Promise<Table | void | Record<string, any>[]>}}
|
|
102
|
+
*/
|
|
103
|
+
query(query: JSONQueryRequest): Promise<Record<string, any>[]>;
|
|
104
|
+
}
|
|
105
|
+
export type DuckDBWASMOptions = {
|
|
106
|
+
/**
|
|
107
|
+
* Flag to enable logging.
|
|
108
|
+
*/
|
|
109
|
+
log?: boolean;
|
|
110
|
+
};
|
|
111
|
+
export type DuckDBWASMConnectorOptions = {
|
|
112
|
+
/**
|
|
113
|
+
* Flag to enable logging.
|
|
114
|
+
*/
|
|
115
|
+
log?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Arrow IPC extraction options.
|
|
118
|
+
*/
|
|
119
|
+
ipc?: ExtractionOptions;
|
|
120
|
+
/**
|
|
121
|
+
* Optional pre-existing DuckDB-WASM instance.
|
|
122
|
+
*/
|
|
123
|
+
duckdb?: duckdb.AsyncDuckDB;
|
|
124
|
+
/**
|
|
125
|
+
* Optional pre-existing DuckDB-WASM connection.
|
|
126
|
+
*/
|
|
127
|
+
connection?: duckdb.AsyncDuckDBConnection;
|
|
15
128
|
};
|
|
129
|
+
import type { Connector } from './Connector.js';
|
|
130
|
+
import type { ExtractionOptions } from '@uwdata/flechette';
|
|
16
131
|
import * as duckdb from '@duckdb/duckdb-wasm';
|
|
132
|
+
import type { ArrowQueryRequest } from './Connector.js';
|
|
133
|
+
import type { Table } from '@uwdata/flechette';
|
|
134
|
+
import type { ExecQueryRequest } from './Connector.js';
|
|
135
|
+
import type { JSONQueryRequest } from './Connector.js';
|
|
@@ -1,48 +1,78 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {Object} MakeClientOptions
|
|
3
|
-
* @property {
|
|
4
|
-
*
|
|
5
|
-
* @property {
|
|
6
|
-
*
|
|
7
|
-
* @property {
|
|
8
|
-
*
|
|
9
|
-
* @property {
|
|
3
|
+
* @property {Coordinator} [coordinator] Mosaic coordinator.
|
|
4
|
+
* Defaults to the global coordinator.
|
|
5
|
+
* @property {Selection|null} [selection] A selection whose predicates are
|
|
6
|
+
* fed into the query function to produce the SQL query.
|
|
7
|
+
* @property {boolean} [enabled] A flag (default `true`) indicating if the
|
|
8
|
+
* client should initially be enabled or not.
|
|
9
|
+
* @property {boolean} [filterStable] A flag (default `true`) indicating if the
|
|
10
|
+
* if client queries can be sped up using pre-aggregated data. Should be set
|
|
11
|
+
* to `false` if filtering changes the groupby domain of the query.
|
|
12
|
+
* @property {function(): Promise<void>} [prepare]
|
|
13
|
+
* An async function to prepare the client before running queries.
|
|
14
|
+
* @property {function(any): any} [query]
|
|
15
|
+
* A function that returns a query from a list of selection predicates.
|
|
16
|
+
* @property {function(any): void} [queryResult]
|
|
17
|
+
* Called by the coordinator to return a query result.
|
|
18
|
+
* @property {function(): void} [queryPending]
|
|
19
|
+
* Called by the coordinator to report a query execution error.
|
|
20
|
+
* @property {function(any): void} [queryError]
|
|
21
|
+
* Called by the coordinator to inform the client that a query is pending.
|
|
10
22
|
*/
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
23
|
+
/**
|
|
24
|
+
* Make a new client with the given options, and connect the client to the
|
|
25
|
+
* provided coordinator.
|
|
26
|
+
* @param {MakeClientOptions} options The options for making the client.
|
|
27
|
+
* @returns {MosaicClient & { destroy: () => void }} The resulting client,
|
|
28
|
+
* along with a method to destroy the client when no longer needed.
|
|
14
29
|
*/
|
|
15
30
|
export function makeClient(options: MakeClientOptions): MosaicClient & {
|
|
16
31
|
destroy: () => void;
|
|
17
32
|
};
|
|
18
33
|
export type MakeClientOptions = {
|
|
19
34
|
/**
|
|
20
|
-
*
|
|
35
|
+
* Mosaic coordinator.
|
|
36
|
+
* Defaults to the global coordinator.
|
|
37
|
+
*/
|
|
38
|
+
coordinator?: Coordinator;
|
|
39
|
+
/**
|
|
40
|
+
* A selection whose predicates are
|
|
41
|
+
* fed into the query function to produce the SQL query.
|
|
42
|
+
*/
|
|
43
|
+
selection?: Selection | null;
|
|
44
|
+
/**
|
|
45
|
+
* A flag (default `true`) indicating if the
|
|
46
|
+
* client should initially be enabled or not.
|
|
21
47
|
*/
|
|
22
|
-
|
|
48
|
+
enabled?: boolean;
|
|
23
49
|
/**
|
|
24
|
-
*
|
|
50
|
+
* A flag (default `true`) indicating if the
|
|
51
|
+
* if client queries can be sped up using pre-aggregated data. Should be set
|
|
52
|
+
* to `false` if filtering changes the groupby domain of the query.
|
|
25
53
|
*/
|
|
26
|
-
|
|
54
|
+
filterStable?: boolean;
|
|
27
55
|
/**
|
|
28
|
-
*
|
|
56
|
+
* An async function to prepare the client before running queries.
|
|
29
57
|
*/
|
|
30
58
|
prepare?: () => Promise<void>;
|
|
31
59
|
/**
|
|
32
|
-
*
|
|
60
|
+
* A function that returns a query from a list of selection predicates.
|
|
33
61
|
*/
|
|
34
|
-
query
|
|
62
|
+
query?: (arg0: any) => any;
|
|
35
63
|
/**
|
|
36
|
-
*
|
|
64
|
+
* Called by the coordinator to return a query result.
|
|
37
65
|
*/
|
|
38
66
|
queryResult?: (arg0: any) => void;
|
|
39
67
|
/**
|
|
40
|
-
*
|
|
68
|
+
* Called by the coordinator to report a query execution error.
|
|
41
69
|
*/
|
|
42
70
|
queryPending?: () => void;
|
|
43
71
|
/**
|
|
44
|
-
*
|
|
72
|
+
* Called by the coordinator to inform the client that a query is pending.
|
|
45
73
|
*/
|
|
46
74
|
queryError?: (arg0: any) => void;
|
|
47
75
|
};
|
|
48
|
-
import { MosaicClient } from
|
|
76
|
+
import { MosaicClient } from './MosaicClient.js';
|
|
77
|
+
import type { Coordinator } from './Coordinator.js';
|
|
78
|
+
import type { Selection } from './Selection.js';
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
export class PreAggregator {
|
|
28
28
|
/**
|
|
29
29
|
* Create a new manager of materialized views of pre-aggregated data.
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {Coordinator} coordinator A Mosaic coordinator.
|
|
31
31
|
* @param {PreAggregateOptions} [options] Pre-aggregation options.
|
|
32
32
|
*/
|
|
33
|
-
constructor(coordinator:
|
|
34
|
-
/** @type {Map<
|
|
35
|
-
entries: Map<
|
|
33
|
+
constructor(coordinator: Coordinator, { schema, enabled }?: PreAggregateOptions);
|
|
34
|
+
/** @type {Map<MosaicClient, PreAggregateInfo | Skip | null>} */
|
|
35
|
+
entries: Map<MosaicClient, PreAggregateInfo | {
|
|
36
36
|
skip: boolean;
|
|
37
37
|
result: any;
|
|
38
38
|
} | null>;
|
|
39
39
|
active: any;
|
|
40
|
-
mc:
|
|
40
|
+
mc: Coordinator;
|
|
41
41
|
_schema: string;
|
|
42
42
|
_enabled: boolean;
|
|
43
43
|
/**
|
|
@@ -88,16 +88,14 @@ export class PreAggregator {
|
|
|
88
88
|
* client-selection pair, or null if the client has unstable filters.
|
|
89
89
|
* This method has multiple possible side effects, including materialized
|
|
90
90
|
* view creation and updating internal caches.
|
|
91
|
-
* @param {
|
|
92
|
-
* @param {
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
* A representative active selection clause for which to (possibly) generate
|
|
96
|
-
* materialized views of pre-aggregates.
|
|
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
|
|
94
|
+
* clause for which to generate materialized views of pre-aggregates.
|
|
97
95
|
* @returns {PreAggregateInfo | Skip | null} Information and query generator
|
|
98
96
|
* for pre-aggregated tables, or null if the client has unstable filters.
|
|
99
97
|
*/
|
|
100
|
-
request(client:
|
|
98
|
+
request(client: MosaicClient, selection: Selection, activeClause: SelectionClause): PreAggregateInfo | {
|
|
101
99
|
skip: boolean;
|
|
102
100
|
result: any;
|
|
103
101
|
} | null;
|
|
@@ -157,11 +155,10 @@ export class PreAggregateInfo {
|
|
|
157
155
|
skip: boolean;
|
|
158
156
|
/**
|
|
159
157
|
* Generate a materialized view query for the given predicate.
|
|
160
|
-
* @param {
|
|
161
|
-
* active clause predicate.
|
|
158
|
+
* @param {ExprNode} predicate The current active clause predicate.
|
|
162
159
|
* @returns {SelectQuery} A materialized view query.
|
|
163
160
|
*/
|
|
164
|
-
query(predicate:
|
|
161
|
+
query(predicate: ExprNode): SelectQuery;
|
|
165
162
|
}
|
|
166
163
|
export type PreAggregateOptions = {
|
|
167
164
|
/**
|
|
@@ -175,4 +172,9 @@ export type PreAggregateOptions = {
|
|
|
175
172
|
*/
|
|
176
173
|
enabled?: boolean;
|
|
177
174
|
};
|
|
178
|
-
import {
|
|
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';
|
|
@@ -10,5 +10,5 @@ export function preaggColumns(client: MosaicClient): {
|
|
|
10
10
|
preagg: Record<string, ExprNode>;
|
|
11
11
|
output: Record<string, ExprNode>;
|
|
12
12
|
};
|
|
13
|
-
import { MosaicClient } from '../MosaicClient.js';
|
|
14
|
-
import { ExprNode } from '@uwdata/mosaic-sql';
|
|
13
|
+
import type { MosaicClient } from '../MosaicClient.js';
|
|
14
|
+
import type { ExprNode } from '@uwdata/mosaic-sql';
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* sufficient statistics to service updates.
|
|
10
10
|
*/
|
|
11
11
|
export function sufficientStatistics(node: AggregateNode, preagg: Record<string, ExprNode>, avg: any): ExprNode;
|
|
12
|
-
import { AggregateNode } from '@uwdata/mosaic-sql';
|
|
13
|
-
import { ExprNode } from '@uwdata/mosaic-sql';
|
|
12
|
+
import type { AggregateNode } from '@uwdata/mosaic-sql';
|
|
13
|
+
import type { ExprNode } from '@uwdata/mosaic-sql';
|
package/dist/types/types.d.ts
CHANGED
|
@@ -40,3 +40,24 @@ export interface Activatable {
|
|
|
40
40
|
*/
|
|
41
41
|
activate(): void;
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Interface for cache implementations.
|
|
45
|
+
*/
|
|
46
|
+
export interface Cache {
|
|
47
|
+
get(key: string): any;
|
|
48
|
+
set(key: string, value: any): any;
|
|
49
|
+
clear(): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Interface for logger implementations
|
|
53
|
+
*/
|
|
54
|
+
export interface Logger {
|
|
55
|
+
debug(...args: any[]): void;
|
|
56
|
+
info(...args: any[]): void;
|
|
57
|
+
log(...args: any[]): void;
|
|
58
|
+
warn(...args: any[]): void;
|
|
59
|
+
error(...args: any[]): void;
|
|
60
|
+
group(label?: any): void;
|
|
61
|
+
groupCollapsed(label?: any): void;
|
|
62
|
+
groupEnd(): void;
|
|
63
|
+
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a new cache that ignores all values.
|
|
3
|
+
* @returns {Cache}
|
|
4
|
+
*/
|
|
5
|
+
export function voidCache(): Cache;
|
|
6
|
+
/**
|
|
7
|
+
* Create a new cache that uses an LRU eviction policy.
|
|
8
|
+
* @param {object} [options] Cache options.
|
|
9
|
+
* @param {number} [options.max] Maximum number of cache entries.
|
|
10
|
+
* @param {number} [options.ttl] Time-to-live for cache entries.
|
|
11
|
+
* @returns {Cache}
|
|
12
|
+
*/
|
|
1
13
|
export function lruCache({ max, ttl }?: {
|
|
2
14
|
max?: number;
|
|
3
15
|
ttl?: number;
|
|
4
|
-
}):
|
|
5
|
-
|
|
6
|
-
set(key: any, value: any): any;
|
|
7
|
-
clear(): void;
|
|
8
|
-
};
|
|
9
|
-
export function voidCache(): {
|
|
10
|
-
get: () => any;
|
|
11
|
-
set: (key: any, value: any) => any;
|
|
12
|
-
clear: () => void;
|
|
13
|
-
};
|
|
16
|
+
}): Cache;
|
|
17
|
+
import type { Cache } from '../types.js';
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Decode Arrow IPC bytes to a table instance
|
|
3
|
-
* timestamp values to JS Date objects.
|
|
2
|
+
* Decode Arrow IPC bytes to a table instance.
|
|
3
|
+
* The default options map date and timestamp values to JS Date objects.
|
|
4
4
|
* @param {ArrayBuffer | Uint8Array} data Arrow IPC bytes.
|
|
5
|
-
* @
|
|
5
|
+
* @param {ExtractionOptions} [options] Arrow IPC extraction options.
|
|
6
|
+
* If unspecified, the default options will extract date and timestamp
|
|
7
|
+
* values to JS Date objects.
|
|
8
|
+
* @returns {Table} A table instance.
|
|
6
9
|
*/
|
|
7
|
-
export function decodeIPC(data: ArrayBuffer | Uint8Array):
|
|
10
|
+
export function decodeIPC(data: ArrayBuffer | Uint8Array, options?: ExtractionOptions): Table;
|
|
11
|
+
import type { ExtractionOptions } from '@uwdata/flechette';
|
|
12
|
+
import type { Table } from '@uwdata/flechette';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uwdata/mosaic-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Scalable and extensible linked data views.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mosaic",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@duckdb/duckdb-wasm": "^1.29.0",
|
|
34
34
|
"@uwdata/flechette": "^2.0.0",
|
|
35
|
-
"@uwdata/mosaic-sql": "^0.
|
|
35
|
+
"@uwdata/mosaic-sql": "^0.16.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@uwdata/mosaic-duckdb": "^0.
|
|
38
|
+
"@uwdata/mosaic-duckdb": "^0.16.1"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "e12af9927b0a35a0e3194850ef569d0d24a022ce"
|
|
41
41
|
}
|
package/src/Coordinator.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
/** @import { Connector } from './connectors/Connector.js' */
|
|
2
|
+
/** @import { PreAggregateOptions } from './preagg/PreAggregator.js' */
|
|
3
|
+
/** @import { QueryResult } from './util/query-result.js' */
|
|
4
|
+
/** @import { SelectionClause } from './util/selection-types.js' */
|
|
5
|
+
/** @import { MosaicClient } from './MosaicClient.js' */
|
|
6
|
+
/** @import { Selection } from './Selection.js' */
|
|
7
|
+
/** @import { Logger, QueryType } from './types.js' */
|
|
1
8
|
import { socketConnector } from './connectors/socket.js';
|
|
2
9
|
import { PreAggregator } from './preagg/PreAggregator.js';
|
|
3
|
-
import { queryFieldInfo } from './util/field-info.js';
|
|
4
|
-
import { QueryResult } from './util/query-result.js';
|
|
5
10
|
import { voidLogger } from './util/void-logger.js';
|
|
6
|
-
import { MosaicClient } from './MosaicClient.js';
|
|
7
11
|
import { QueryManager, Priority } from './QueryManager.js';
|
|
8
12
|
|
|
9
13
|
/**
|
|
@@ -30,16 +34,17 @@ export function coordinator(instance) {
|
|
|
30
34
|
* A Mosaic Coordinator manages all database communication for clients and
|
|
31
35
|
* handles selection updates. The Coordinator also performs optimizations
|
|
32
36
|
* including query caching, consolidation, and pre-aggregation.
|
|
33
|
-
* @param {*} [db] Database connector. Defaults to a web socket connection.
|
|
34
|
-
* @param {object} [options] Coordinator options.
|
|
35
|
-
* @param {*} [options.logger=console] The logger to use, defaults to `console`.
|
|
36
|
-
* @param {*} [options.manager] The query manager to use.
|
|
37
|
-
* @param {boolean} [options.cache=true] Boolean flag to enable/disable query caching.
|
|
38
|
-
* @param {boolean} [options.consolidate=true] Boolean flag to enable/disable query consolidation.
|
|
39
|
-
* @param {import('./preagg/PreAggregator.js').PreAggregateOptions} [options.preagg]
|
|
40
|
-
* Options for the Pre-aggregator.
|
|
41
37
|
*/
|
|
42
38
|
export class Coordinator {
|
|
39
|
+
/**
|
|
40
|
+
* @param {Connector} [db] Database connector. Defaults to a web socket connection.
|
|
41
|
+
* @param {object} [options] Coordinator options.
|
|
42
|
+
* @param {Logger} [options.logger=console] The logger to use, defaults to `console`.
|
|
43
|
+
* @param {QueryManager} [options.manager] The query manager to use.
|
|
44
|
+
* @param {boolean} [options.cache=true] Boolean flag to enable/disable query caching.
|
|
45
|
+
* @param {boolean} [options.consolidate=true] Boolean flag to enable/disable query consolidation.
|
|
46
|
+
* @param {PreAggregateOptions} [options.preagg] Options for the Pre-aggregator.
|
|
47
|
+
*/
|
|
43
48
|
constructor(db = socketConnector(), {
|
|
44
49
|
logger = console,
|
|
45
50
|
manager = new QueryManager(),
|
|
@@ -76,8 +81,8 @@ export class Coordinator {
|
|
|
76
81
|
|
|
77
82
|
/**
|
|
78
83
|
* Get or set the database connector.
|
|
79
|
-
* @param {
|
|
80
|
-
* @returns The current database connector.
|
|
84
|
+
* @param {Connector} [db] The database connector to use.
|
|
85
|
+
* @returns {Connector} The current database connector.
|
|
81
86
|
*/
|
|
82
87
|
databaseConnector(db) {
|
|
83
88
|
return this.manager.connector(db);
|
|
@@ -85,8 +90,8 @@ export class Coordinator {
|
|
|
85
90
|
|
|
86
91
|
/**
|
|
87
92
|
* Get or set the logger.
|
|
88
|
-
* @param {
|
|
89
|
-
* @returns The current logger
|
|
93
|
+
* @param {Logger} [logger] The logger to use.
|
|
94
|
+
* @returns {Logger} The current logger
|
|
90
95
|
*/
|
|
91
96
|
logger(logger) {
|
|
92
97
|
if (arguments.length) {
|
|
@@ -110,8 +115,7 @@ export class Coordinator {
|
|
|
110
115
|
|
|
111
116
|
/**
|
|
112
117
|
* Issue a query for which no result (return value) is needed.
|
|
113
|
-
* @param {
|
|
114
|
-
* import('./types.js').QueryType} query The query or an array of queries.
|
|
118
|
+
* @param {QueryType[] | QueryType} query The query or an array of queries.
|
|
115
119
|
* Each query should be either a Query builder object or a SQL string.
|
|
116
120
|
* @param {object} [options] An options object.
|
|
117
121
|
* @param {number} [options.priority] The query priority, defaults to
|
|
@@ -126,8 +130,8 @@ export class Coordinator {
|
|
|
126
130
|
/**
|
|
127
131
|
* Issue a query to the backing database. The submitted query may be
|
|
128
132
|
* consolidate with other queries and its results may be cached.
|
|
129
|
-
* @param {
|
|
130
|
-
*
|
|
133
|
+
* @param {QueryType} query The query as either a Query builder objec
|
|
134
|
+
* or a SQL string.
|
|
131
135
|
* @param {object} [options] An options object.
|
|
132
136
|
* @param {'arrow' | 'json'} [options.type] The query result format type.
|
|
133
137
|
* @param {boolean} [options.cache=true] If true, cache the query result
|
|
@@ -150,8 +154,8 @@ export class Coordinator {
|
|
|
150
154
|
/**
|
|
151
155
|
* Issue a query to prefetch data for later use. The query result is cached
|
|
152
156
|
* for efficient future access.
|
|
153
|
-
* @param {
|
|
154
|
-
*
|
|
157
|
+
* @param {QueryType} query The query as either a Query builder object
|
|
158
|
+
* or a SQL string.
|
|
155
159
|
* @param {object} [options] An options object.
|
|
156
160
|
* @param {'arrow' | 'json'} [options.type] The query result format type.
|
|
157
161
|
* @returns {QueryResult} A query result promise.
|
|
@@ -190,7 +194,7 @@ export class Coordinator {
|
|
|
190
194
|
* Update client data by submitting the given query and returning the
|
|
191
195
|
* data (or error) to the client.
|
|
192
196
|
* @param {MosaicClient} client A Mosaic client.
|
|
193
|
-
* @param {
|
|
197
|
+
* @param {QueryType} query The data query.
|
|
194
198
|
* @param {number} [priority] The query priority.
|
|
195
199
|
* @returns {Promise} A Promise that resolves upon completion of the update.
|
|
196
200
|
*/
|
|
@@ -209,7 +213,7 @@ export class Coordinator {
|
|
|
209
213
|
* the client is simply updated. Otherwise `updateClient` is called. As a
|
|
210
214
|
* side effect, this method clears the current preaggregator state.
|
|
211
215
|
* @param {MosaicClient} client The client to update.
|
|
212
|
-
* @param {
|
|
216
|
+
* @param {QueryType | null} [query] The query to issue.
|
|
213
217
|
*/
|
|
214
218
|
requestQuery(client, query) {
|
|
215
219
|
this.preaggregator.clear();
|
|
@@ -236,26 +240,12 @@ export class Coordinator {
|
|
|
236
240
|
client.coordinator = this;
|
|
237
241
|
|
|
238
242
|
// initialize client lifecycle
|
|
239
|
-
client.
|
|
243
|
+
client.initialize();
|
|
240
244
|
|
|
241
245
|
// connect filter selection
|
|
242
246
|
connectSelection(this, client.filterBy, client);
|
|
243
247
|
}
|
|
244
248
|
|
|
245
|
-
async initializeClient(client) {
|
|
246
|
-
// retrieve field statistics
|
|
247
|
-
const fields = client.fields();
|
|
248
|
-
if (fields?.length) {
|
|
249
|
-
client.fieldInfo(await queryFieldInfo(this, fields));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
// prepare the client
|
|
253
|
-
await client.prepare();
|
|
254
|
-
|
|
255
|
-
// request data query
|
|
256
|
-
return client.requestQuery();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
249
|
/**
|
|
260
250
|
* Disconnect a client from the coordinator.
|
|
261
251
|
* @param {MosaicClient} client The Mosaic client to disconnect.
|
|
@@ -276,7 +266,7 @@ export class Coordinator {
|
|
|
276
266
|
/**
|
|
277
267
|
* Connect a selection-client pair to the coordinator to process updates.
|
|
278
268
|
* @param {Coordinator} mc The Mosaic coordinator.
|
|
279
|
-
* @param {
|
|
269
|
+
* @param {Selection} selection A selection.
|
|
280
270
|
* @param {MosaicClient} client A Mosiac client that is filtered by the
|
|
281
271
|
* given selection.
|
|
282
272
|
*/
|
|
@@ -308,15 +298,16 @@ function connectSelection(mc, selection, client) {
|
|
|
308
298
|
* next updates. Activation provides a preview of likely next events,
|
|
309
299
|
* enabling potential precomputation to optimize updates.
|
|
310
300
|
* @param {Coordinator} mc The Mosaic coordinator.
|
|
311
|
-
* @param {
|
|
312
|
-
* @param {
|
|
313
|
-
* selection clause representative of the activation.
|
|
301
|
+
* @param {Selection} selection A selection.
|
|
302
|
+
* @param {SelectionClause} clause A selection clause for the activation.
|
|
314
303
|
*/
|
|
315
304
|
function activateSelection(mc, selection, clause) {
|
|
316
305
|
const { preaggregator, filterGroups } = mc;
|
|
317
306
|
const { clients } = filterGroups.get(selection);
|
|
318
307
|
for (const client of clients) {
|
|
319
|
-
|
|
308
|
+
if (client.enabled) {
|
|
309
|
+
preaggregator.request(client, selection, clause);
|
|
310
|
+
}
|
|
320
311
|
}
|
|
321
312
|
}
|
|
322
313
|
|
|
@@ -324,7 +315,7 @@ function activateSelection(mc, selection, clause) {
|
|
|
324
315
|
* Process an updated selection value, querying filtered data for any
|
|
325
316
|
* associated clients.
|
|
326
317
|
* @param {Coordinator} mc The Mosaic coordinator.
|
|
327
|
-
* @param {
|
|
318
|
+
* @param {Selection} selection A selection.
|
|
328
319
|
* @returns {Promise} A Promise that resolves when the update completes.
|
|
329
320
|
*/
|
|
330
321
|
function updateSelection(mc, selection) {
|
|
@@ -332,6 +323,7 @@ function updateSelection(mc, selection) {
|
|
|
332
323
|
const { clients } = filterGroups.get(selection);
|
|
333
324
|
const { active } = selection;
|
|
334
325
|
return Promise.allSettled(Array.from(clients, client => {
|
|
326
|
+
if (!client.enabled) return client.requestQuery();
|
|
335
327
|
const info = preaggregator.request(client, selection, active);
|
|
336
328
|
const filter = info ? null : selection.predicate(client);
|
|
337
329
|
|