@perspective-dev/client 5.1.0 → 5.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/perspective.js +2 -2
- package/dist/cdn/perspective.js.map +3 -3
- package/dist/esm/perspective.inline.js +2 -2
- package/dist/esm/perspective.inline.js.map +3 -3
- package/dist/esm/perspective.js +2 -2
- package/dist/esm/perspective.js.map +3 -3
- package/dist/esm/perspective.node.js +36 -22
- package/dist/esm/perspective.node.js.map +2 -2
- package/dist/esm/ts-rs/Features.d.ts +10 -3
- package/dist/esm/ts-rs/ListFlatten.d.ts +1 -0
- package/dist/esm/ts-rs/SplitRollupMode.d.ts +9 -0
- package/dist/esm/ts-rs/TableInitOptions.d.ts +9 -0
- package/dist/esm/ts-rs/ViewConfig.d.ts +2 -0
- package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +15 -0
- package/dist/esm/ts-rs/WindowAggSpec.d.ts +25 -0
- package/dist/esm/ts-rs/WindowSpec.d.ts +3 -2
- package/dist/esm/virtual_servers/clickhouse.js +1 -1
- package/dist/esm/virtual_servers/clickhouse.js.map +3 -3
- package/dist/esm/virtual_servers/duckdb.js +1 -1
- package/dist/esm/virtual_servers/duckdb.js.map +3 -3
- package/dist/wasm/perspective-js.d.ts +9 -8
- package/dist/wasm/perspective-js.js +38 -24
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +7 -6
- package/package.json +1 -1
- package/src/rust/generic_sql_model.rs +8 -1
- package/src/rust/lib.rs +1 -1
- package/src/rust/typed_array.rs +22 -3
- package/src/rust/utils/futures.rs +95 -8
- package/src/ts/ts-rs/Features.ts +10 -3
- package/src/ts/ts-rs/ListFlatten.ts +3 -0
- package/src/ts/ts-rs/SplitRollupMode.ts +11 -0
- package/src/ts/ts-rs/TableInitOptions.ts +10 -1
- package/src/ts/ts-rs/ViewConfig.ts +2 -1
- package/src/ts/ts-rs/ViewConfigUpdate.ts +15 -1
- package/src/ts/ts-rs/WindowAggSpec.ts +25 -0
- package/src/ts/ts-rs/WindowSpec.ts +3 -2
- package/src/ts/virtual_servers/clickhouse.ts +67 -24
- package/src/ts/virtual_servers/duckdb.ts +135 -50
- package/dist/esm/ts-rs/WindowAggregate.d.ts +0 -1
- package/src/ts/ts-rs/WindowAggregate.ts +0 -3
|
@@ -26,7 +26,7 @@ import type { ColumnType } from "@perspective-dev/client/dist/esm/ts-rs/ColumnTy
|
|
|
26
26
|
import type { ViewConfig } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts";
|
|
27
27
|
import type { ViewConfigUpdate } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfigUpdate.d.ts";
|
|
28
28
|
import type { ViewWindow } from "@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts";
|
|
29
|
-
import type {
|
|
29
|
+
import type { WindowAggSpec } from "@perspective-dev/client/dist/esm/ts-rs/WindowAggSpec.d.ts";
|
|
30
30
|
import type * as clickhouse from "@clickhouse/client-web";
|
|
31
31
|
|
|
32
32
|
const NUMBER_AGGS = [
|
|
@@ -65,40 +65,70 @@ const STRING_AGGS = [
|
|
|
65
65
|
"string_agg",
|
|
66
66
|
];
|
|
67
67
|
|
|
68
|
-
//
|
|
69
|
-
//
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
"
|
|
81
|
-
"
|
|
68
|
+
// Window functions. Renamed from Perspective's `stddev`/`var` to the SQL
|
|
69
|
+
// standard spellings DuckDB and ClickHouse both accept, since the advertised
|
|
70
|
+
// name is now emitted verbatim.
|
|
71
|
+
//
|
|
72
|
+
// NOTE: this set is inherited from the DuckDB handler and has NOT been audited
|
|
73
|
+
// against a live ClickHouse - see the aggregate lists below, which have the
|
|
74
|
+
// same problem. ClickHouse's own navigation functions are `lagInFrame` /
|
|
75
|
+
// `leadInFrame`, and its ranking set differs; both need verifying before being
|
|
76
|
+
// advertised here.
|
|
77
|
+
const FRAMES = ["rows", "range", "cumulative"];
|
|
78
|
+
|
|
79
|
+
const WINDOW_AGGREGATES: WindowAggSpec[] = [
|
|
80
|
+
{ name: "sum", frames: FRAMES, result_type: "float" },
|
|
81
|
+
{ name: "avg", frames: FRAMES, result_type: "float" },
|
|
82
|
+
{ name: "count", frames: FRAMES, result_type: "float" },
|
|
83
|
+
{ name: "min", frames: FRAMES },
|
|
84
|
+
{ name: "max", frames: FRAMES },
|
|
85
|
+
{ name: "stddev_samp", frames: FRAMES, result_type: "float" },
|
|
86
|
+
{ name: "var_samp", frames: FRAMES, result_type: "float" },
|
|
87
|
+
{ name: "lag", offset: true },
|
|
88
|
+
{ name: "lead", offset: true },
|
|
89
|
+
{ name: "diff", offset: true, result_type: "float" },
|
|
90
|
+
{ name: "rate", frames: ["range"], result_type: "float" },
|
|
82
91
|
];
|
|
83
92
|
|
|
84
|
-
const WINDOW_AGGREGATES_ANY:
|
|
85
|
-
"count",
|
|
86
|
-
"min",
|
|
87
|
-
"max",
|
|
88
|
-
"lag",
|
|
89
|
-
"lead",
|
|
93
|
+
const WINDOW_AGGREGATES_ANY: WindowAggSpec[] = [
|
|
94
|
+
{ name: "count", frames: FRAMES, result_type: "float" },
|
|
95
|
+
{ name: "min", frames: FRAMES },
|
|
96
|
+
{ name: "max", frames: FRAMES },
|
|
97
|
+
{ name: "lag", offset: true },
|
|
98
|
+
{ name: "lead", offset: true },
|
|
90
99
|
];
|
|
91
100
|
|
|
92
101
|
const FILTER_OPS = [
|
|
93
102
|
"==",
|
|
94
103
|
"!=",
|
|
95
|
-
"LIKE",
|
|
96
104
|
"IS DISTINCT FROM",
|
|
97
105
|
"IS NOT DISTINCT FROM",
|
|
98
106
|
">=",
|
|
99
107
|
"<=",
|
|
100
108
|
">",
|
|
101
109
|
"<",
|
|
110
|
+
"is null",
|
|
111
|
+
"is not null",
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
// Perspective's canonical string ops (translated to `ILIKE` / `match` by the
|
|
115
|
+
// SQL builder), plus ClickHouse's raw infix pattern ops spliced verbatim.
|
|
116
|
+
const STRING_FILTER_OPS = [
|
|
117
|
+
...FILTER_OPS,
|
|
118
|
+
"begins with",
|
|
119
|
+
"not begins with",
|
|
120
|
+
"contains",
|
|
121
|
+
"not contains",
|
|
122
|
+
"ends with",
|
|
123
|
+
"not ends with",
|
|
124
|
+
"matches",
|
|
125
|
+
"not matches",
|
|
126
|
+
"in",
|
|
127
|
+
"not in",
|
|
128
|
+
"LIKE",
|
|
129
|
+
"NOT LIKE",
|
|
130
|
+
"ILIKE",
|
|
131
|
+
"NOT ILIKE",
|
|
102
132
|
];
|
|
103
133
|
|
|
104
134
|
function duckdbTypeToPsp(name: string): ColumnType {
|
|
@@ -241,6 +271,8 @@ export class ClickhouseHandler implements perspective.VirtualServerHandler {
|
|
|
241
271
|
create_entity: "VIEW",
|
|
242
272
|
grouping_fn: "GROUPING",
|
|
243
273
|
column_separator: "|",
|
|
274
|
+
backslash_escaped_literals: true,
|
|
275
|
+
regex_fn: "match",
|
|
244
276
|
});
|
|
245
277
|
}
|
|
246
278
|
|
|
@@ -266,7 +298,7 @@ export class ClickhouseHandler implements perspective.VirtualServerHandler {
|
|
|
266
298
|
filter_ops: {
|
|
267
299
|
integer: FILTER_OPS,
|
|
268
300
|
float: FILTER_OPS,
|
|
269
|
-
string:
|
|
301
|
+
string: STRING_FILTER_OPS,
|
|
270
302
|
boolean: FILTER_OPS,
|
|
271
303
|
date: FILTER_OPS,
|
|
272
304
|
datetime: FILTER_OPS,
|
|
@@ -327,7 +359,18 @@ export class ClickhouseHandler implements perspective.VirtualServerHandler {
|
|
|
327
359
|
viewId: string,
|
|
328
360
|
config: ViewConfigUpdate,
|
|
329
361
|
) {
|
|
330
|
-
|
|
362
|
+
// Window order keys need column types for `range` frame emission.
|
|
363
|
+
const schema = Object.keys(config.windows ?? {}).length
|
|
364
|
+
? await this.tableSchema(tableId)
|
|
365
|
+
: undefined;
|
|
366
|
+
|
|
367
|
+
const query = this.sqlBuilder.tableMakeView(
|
|
368
|
+
tableId,
|
|
369
|
+
viewId,
|
|
370
|
+
config,
|
|
371
|
+
schema,
|
|
372
|
+
);
|
|
373
|
+
|
|
331
374
|
await runQuery(this.db, query, { execute: true });
|
|
332
375
|
}
|
|
333
376
|
|
|
@@ -26,7 +26,7 @@ import type { ColumnType } from "@perspective-dev/client/dist/esm/ts-rs/ColumnTy
|
|
|
26
26
|
import type { ViewConfig } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfig.d.ts";
|
|
27
27
|
import type { ViewConfigUpdate } from "@perspective-dev/client/dist/esm/ts-rs/ViewConfigUpdate.d.ts";
|
|
28
28
|
import type { ViewWindow } from "@perspective-dev/client/dist/esm/ts-rs/ViewWindow.d.ts";
|
|
29
|
-
import type {
|
|
29
|
+
import type { WindowAggSpec } from "@perspective-dev/client/dist/esm/ts-rs/WindowAggSpec.d.ts";
|
|
30
30
|
import type { Scalar } from "@perspective-dev/client/dist/esm/ts-rs/Scalar.d.ts";
|
|
31
31
|
import type * as duckdb from "@duckdb/duckdb-wasm";
|
|
32
32
|
|
|
@@ -66,87 +66,158 @@ const STRING_AGGS = [
|
|
|
66
66
|
"string_agg",
|
|
67
67
|
];
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const WINDOW_AGGREGATES:
|
|
72
|
-
"sum",
|
|
73
|
-
"avg",
|
|
74
|
-
"count",
|
|
75
|
-
"min",
|
|
76
|
-
"max",
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
"
|
|
69
|
+
const FRAMES = ["rows", "range", "cumulative"];
|
|
70
|
+
|
|
71
|
+
const WINDOW_AGGREGATES: WindowAggSpec[] = [
|
|
72
|
+
{ name: "sum", frames: FRAMES, result_type: "float" },
|
|
73
|
+
{ name: "avg", frames: FRAMES, result_type: "float" },
|
|
74
|
+
{ name: "count", frames: FRAMES, result_type: "float" },
|
|
75
|
+
{ name: "min", frames: FRAMES },
|
|
76
|
+
{ name: "max", frames: FRAMES },
|
|
77
|
+
{ name: "product", frames: FRAMES, result_type: "float" },
|
|
78
|
+
{ name: "median", frames: FRAMES, result_type: "float" },
|
|
79
|
+
// DuckDB spells sample and population variants separately, so both are
|
|
80
|
+
// offered rather than one being picked on the user's behalf.
|
|
81
|
+
{ name: "stddev_samp", frames: FRAMES, result_type: "float" },
|
|
82
|
+
{ name: "stddev_pop", frames: FRAMES, result_type: "float" },
|
|
83
|
+
{ name: "var_samp", frames: FRAMES, result_type: "float" },
|
|
84
|
+
{ name: "var_pop", frames: FRAMES, result_type: "float" },
|
|
85
|
+
// Navigation.
|
|
86
|
+
{ name: "first_value", frames: FRAMES },
|
|
87
|
+
{ name: "last_value", frames: FRAMES },
|
|
88
|
+
{ name: "nth_value", frames: FRAMES, offset: true },
|
|
89
|
+
{ name: "lag", offset: true },
|
|
90
|
+
{ name: "lead", offset: true },
|
|
91
|
+
// Ranking. These take no source column - the window's `order_by` is their
|
|
92
|
+
// input - but Perspective requires one, so the choice of source is
|
|
93
|
+
// immaterial for them.
|
|
94
|
+
{ name: "row_number", result_type: "float" },
|
|
95
|
+
{ name: "rank", result_type: "float" },
|
|
96
|
+
{ name: "dense_rank", result_type: "float" },
|
|
97
|
+
{ name: "percent_rank", result_type: "float" },
|
|
98
|
+
{ name: "cume_dist", result_type: "float" },
|
|
99
|
+
// `ntile`'s argument is a bucket count rather than a row offset.
|
|
100
|
+
{ name: "ntile", offset: true, result_type: "float" },
|
|
101
|
+
// Perspective's own, with no DuckDB equivalent - the SQL translation
|
|
102
|
+
// synthesizes them from `lag` and `first_value`.
|
|
103
|
+
{ name: "diff", offset: true, result_type: "float" },
|
|
104
|
+
{ name: "rate", frames: ["range"], result_type: "float" },
|
|
83
105
|
];
|
|
84
106
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
107
|
+
// Arithmetic is undefined for the non-numeric types; ordering and navigation
|
|
108
|
+
// are not.
|
|
109
|
+
const WINDOW_AGGREGATES_ANY: WindowAggSpec[] = [
|
|
110
|
+
{ name: "count", frames: FRAMES, result_type: "float" },
|
|
111
|
+
{ name: "min", frames: FRAMES },
|
|
112
|
+
{ name: "max", frames: FRAMES },
|
|
113
|
+
{ name: "first_value", frames: FRAMES },
|
|
114
|
+
{ name: "last_value", frames: FRAMES },
|
|
115
|
+
{ name: "nth_value", frames: FRAMES, offset: true },
|
|
116
|
+
{ name: "lag", offset: true },
|
|
117
|
+
{ name: "lead", offset: true },
|
|
118
|
+
{ name: "row_number", result_type: "float" },
|
|
119
|
+
{ name: "rank", result_type: "float" },
|
|
120
|
+
{ name: "dense_rank", result_type: "float" },
|
|
121
|
+
{ name: "percent_rank", result_type: "float" },
|
|
122
|
+
{ name: "cume_dist", result_type: "float" },
|
|
123
|
+
{ name: "ntile", offset: true, result_type: "float" },
|
|
91
124
|
];
|
|
92
125
|
|
|
93
126
|
const FILTER_OPS = [
|
|
94
127
|
"==",
|
|
95
128
|
"!=",
|
|
96
|
-
"LIKE",
|
|
97
129
|
"IS DISTINCT FROM",
|
|
98
130
|
"IS NOT DISTINCT FROM",
|
|
99
131
|
">=",
|
|
100
132
|
"<=",
|
|
101
133
|
">",
|
|
102
134
|
"<",
|
|
135
|
+
"is null",
|
|
136
|
+
"is not null",
|
|
137
|
+
];
|
|
138
|
+
|
|
139
|
+
// Perspective's canonical string ops (translated to `ILIKE` / `regexp_matches`
|
|
140
|
+
// by the SQL builder), plus DuckDB's raw infix pattern ops spliced verbatim.
|
|
141
|
+
const STRING_FILTER_OPS = [
|
|
142
|
+
...FILTER_OPS,
|
|
143
|
+
"begins with",
|
|
144
|
+
"not begins with",
|
|
145
|
+
"contains",
|
|
146
|
+
"not contains",
|
|
147
|
+
"ends with",
|
|
148
|
+
"not ends with",
|
|
149
|
+
"matches",
|
|
150
|
+
"not matches",
|
|
151
|
+
"in",
|
|
152
|
+
"not in",
|
|
153
|
+
"LIKE",
|
|
154
|
+
"NOT LIKE",
|
|
155
|
+
"ILIKE",
|
|
156
|
+
"NOT ILIKE",
|
|
103
157
|
];
|
|
104
158
|
|
|
159
|
+
/**
|
|
160
|
+
* Convert a DuckDB `dtype` to a Perspective `ColumnType`.
|
|
161
|
+
*/
|
|
105
162
|
function duckdbTypeToPsp(name: string): ColumnType {
|
|
106
163
|
name = name.toLowerCase();
|
|
107
|
-
|
|
108
|
-
|
|
164
|
+
|
|
165
|
+
if (name.startsWith("bool")) {
|
|
166
|
+
return "boolean";
|
|
109
167
|
}
|
|
110
168
|
|
|
169
|
+
// 32-bit and narrower - `coerce_column` widens these to `Int32`.
|
|
111
170
|
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
name.startsWith("decimal")
|
|
171
|
+
["tinyint", "smallint", "integer", "utinyint", "usmallint"].includes(
|
|
172
|
+
name,
|
|
173
|
+
) ||
|
|
174
|
+
["int8", "int16", "int32", "uint8", "uint16"].includes(name)
|
|
117
175
|
) {
|
|
118
|
-
return "
|
|
176
|
+
return "integer";
|
|
119
177
|
}
|
|
120
178
|
|
|
121
|
-
|
|
122
|
-
|
|
179
|
+
// Wider than `Int32`, or fractional - all coerce to `Float64`.
|
|
180
|
+
if (
|
|
181
|
+
["bigint", "hugeint", "uhugeint", "uinteger", "ubigint"].includes(
|
|
182
|
+
name,
|
|
183
|
+
) ||
|
|
184
|
+
["float", "real", "double", "varint"].includes(name) ||
|
|
185
|
+
["int64", "uint32", "uint64", "float32", "float64"].includes(name) ||
|
|
186
|
+
name.startsWith("decimal") ||
|
|
187
|
+
name.startsWith("numeric")
|
|
188
|
+
) {
|
|
189
|
+
return "float";
|
|
123
190
|
}
|
|
124
191
|
|
|
125
192
|
if (name.startsWith("date")) {
|
|
126
193
|
return "date";
|
|
127
194
|
}
|
|
128
195
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (name.startsWith("timestamp")) {
|
|
196
|
+
// `timestamp`, `timestamptz`, `timestamp_ns`, and `time`/`timetz`,
|
|
197
|
+
// which coerce to `Timestamp(Millisecond)` rather than to a number.
|
|
198
|
+
if (name.startsWith("time")) {
|
|
134
199
|
return "datetime";
|
|
135
200
|
}
|
|
136
201
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
202
|
+
// Everything else renders as text: `varchar`, `enum(...)` (which
|
|
203
|
+
// arrives dictionary-encoded), `json`, `uuid`, `blob`, `interval`,
|
|
204
|
+
// and the nested types.
|
|
205
|
+
if (
|
|
206
|
+
!(
|
|
207
|
+
name.startsWith("varchar") ||
|
|
208
|
+
name === "utf8" ||
|
|
209
|
+
name.startsWith("enum") ||
|
|
210
|
+
["json", "uuid", "blob", "bit", "interval"].includes(name) ||
|
|
211
|
+
name.startsWith("struct") ||
|
|
212
|
+
name.startsWith("map") ||
|
|
213
|
+
name.startsWith("union") ||
|
|
214
|
+
name.endsWith("[]")
|
|
215
|
+
)
|
|
216
|
+
) {
|
|
217
|
+
// Unknown, not fatal - the column still renders, as text.
|
|
218
|
+
console.warn(`Unknown type '${name}'`);
|
|
147
219
|
}
|
|
148
220
|
|
|
149
|
-
console.warn(`Unknown type '${name}'`);
|
|
150
221
|
return "string";
|
|
151
222
|
}
|
|
152
223
|
|
|
@@ -213,6 +284,8 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
213
284
|
this.db = db;
|
|
214
285
|
this.sqlBuilder = new mod!.GenericSQLVirtualServerModel({
|
|
215
286
|
column_separator: "|",
|
|
287
|
+
like_escape_clause: "\\",
|
|
288
|
+
regex_fn: "regexp_matches",
|
|
216
289
|
});
|
|
217
290
|
}
|
|
218
291
|
|
|
@@ -232,10 +305,11 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
232
305
|
boolean: WINDOW_AGGREGATES_ANY,
|
|
233
306
|
},
|
|
234
307
|
group_rollup_mode: ["rollup", "flat", "total"],
|
|
308
|
+
split_rollup_mode: ["flat", "rollup"],
|
|
235
309
|
filter_ops: {
|
|
236
310
|
integer: FILTER_OPS,
|
|
237
311
|
float: FILTER_OPS,
|
|
238
|
-
string:
|
|
312
|
+
string: STRING_FILTER_OPS,
|
|
239
313
|
boolean: FILTER_OPS,
|
|
240
314
|
date: FILTER_OPS,
|
|
241
315
|
datetime: FILTER_OPS,
|
|
@@ -297,7 +371,18 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
297
371
|
viewId: string,
|
|
298
372
|
config: ViewConfigUpdate,
|
|
299
373
|
) {
|
|
300
|
-
|
|
374
|
+
// Window order keys need column types for `range` frame emission.
|
|
375
|
+
const schema = Object.keys(config.windows ?? {}).length
|
|
376
|
+
? await this.tableSchema(tableId)
|
|
377
|
+
: undefined;
|
|
378
|
+
|
|
379
|
+
const query = this.sqlBuilder.tableMakeView(
|
|
380
|
+
tableId,
|
|
381
|
+
viewId,
|
|
382
|
+
config,
|
|
383
|
+
schema,
|
|
384
|
+
);
|
|
385
|
+
|
|
301
386
|
await runQuery(this.db, query);
|
|
302
387
|
}
|
|
303
388
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type WindowAggregate = "sum" | "avg" | "count" | "min" | "max" | "stddev" | "var" | "first" | "last" | "lag" | "lead" | "diff" | "rate" | "ema";
|