@perspective-dev/client 5.1.0 → 5.2.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 +1 -1
- package/dist/cdn/perspective.js.map +2 -2
- package/dist/esm/perspective.inline.js +2 -2
- package/dist/esm/perspective.inline.js.map +3 -3
- package/dist/esm/perspective.js +1 -1
- package/dist/esm/perspective.js.map +2 -2
- package/dist/esm/perspective.node.js +9 -9
- package/dist/esm/perspective.node.js.map +1 -1
- 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 +6 -6
- package/dist/wasm/perspective-js.js +10 -10
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +5 -5
- package/package.json +1 -1
- package/src/rust/lib.rs +1 -1
- package/src/rust/typed_array.rs +22 -3
- 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 +55 -23
- package/src/ts/virtual_servers/duckdb.ts +123 -49
- package/dist/esm/ts-rs/WindowAggregate.d.ts +0 -1
- package/src/ts/ts-rs/WindowAggregate.ts +0 -3
package/src/rust/typed_array.rs
CHANGED
|
@@ -14,7 +14,7 @@ use std::io::Cursor;
|
|
|
14
14
|
|
|
15
15
|
use arrow_array::cast::AsArray;
|
|
16
16
|
use arrow_array::types::*;
|
|
17
|
-
use arrow_array::{Array as _, ArrowPrimitiveType, PrimitiveArray};
|
|
17
|
+
use arrow_array::{Array as _, ArrowPrimitiveType, DictionaryArray, PrimitiveArray, StringArray};
|
|
18
18
|
use arrow_ipc::reader::StreamReader;
|
|
19
19
|
use arrow_schema::{DataType, TimeUnit};
|
|
20
20
|
use js_sys::{Array, Function, JsString, Uint8Array};
|
|
@@ -219,13 +219,32 @@ pub(crate) async fn decode_and_call(
|
|
|
219
219
|
js_dicts.set(col_idx as u32, JsValue::NULL);
|
|
220
220
|
},
|
|
221
221
|
DataType::Dictionary(..) => {
|
|
222
|
-
let dict = col
|
|
222
|
+
let dict = col
|
|
223
|
+
.as_any()
|
|
224
|
+
.downcast_ref::<DictionaryArray<Int32Type>>()
|
|
225
|
+
.ok_or_else(|| {
|
|
226
|
+
JsValue::from_str(&format!(
|
|
227
|
+
"Unsupported dictionary key type for typed array: {}",
|
|
228
|
+
col.data_type()
|
|
229
|
+
))
|
|
230
|
+
})?;
|
|
231
|
+
|
|
223
232
|
let keys = dict.keys();
|
|
224
233
|
zero_invalid_slots(keys);
|
|
225
234
|
let arr = unsafe { js_sys::Int32Array::view(keys.values().as_ref()) };
|
|
226
235
|
js_values.set(col_idx as u32, arr.into());
|
|
227
236
|
|
|
228
|
-
let values = dict
|
|
237
|
+
let values = dict
|
|
238
|
+
.values()
|
|
239
|
+
.as_any()
|
|
240
|
+
.downcast_ref::<StringArray>()
|
|
241
|
+
.ok_or_else(|| {
|
|
242
|
+
JsValue::from_str(&format!(
|
|
243
|
+
"Unsupported dictionary value type for typed array: {}",
|
|
244
|
+
dict.values().data_type()
|
|
245
|
+
))
|
|
246
|
+
})?;
|
|
247
|
+
|
|
229
248
|
let js_dict = Array::new_with_length(values.len() as u32);
|
|
230
249
|
for i in 0..values.len() {
|
|
231
250
|
js_dict.set(i as u32, JsValue::from_str(values.value(i)));
|
package/src/ts/ts-rs/Features.ts
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
import type { AggSpec } from "./AggSpec.js";
|
|
3
3
|
import type { ColumnType } from "./ColumnType.js";
|
|
4
4
|
import type { GroupRollupMode } from "./GroupRollupMode.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { SplitRollupMode } from "./SplitRollupMode.js";
|
|
6
|
+
import type { WindowAggSpec } from "./WindowAggSpec.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Describes the capabilities supported by a virtual server handler.
|
|
@@ -24,6 +25,12 @@ group_rollup_mode?: Array<GroupRollupMode>,
|
|
|
24
25
|
* Whether split-by (pivot) operations are supported.
|
|
25
26
|
*/
|
|
26
27
|
split_by?: boolean,
|
|
28
|
+
/**
|
|
29
|
+
* Which `split_rollup_mode` options are supported. Empty (the default)
|
|
30
|
+
* means `["flat"]` - a server must opt in to `"rollup"` explicitly, as
|
|
31
|
+
* it requires emitting subtotal and grand-total column groups.
|
|
32
|
+
*/
|
|
33
|
+
split_rollup_mode?: Array<SplitRollupMode>,
|
|
27
34
|
/**
|
|
28
35
|
* Available filter operators per column type.
|
|
29
36
|
*/
|
|
@@ -41,9 +48,9 @@ sort?: boolean,
|
|
|
41
48
|
*/
|
|
42
49
|
expressions?: boolean,
|
|
43
50
|
/**
|
|
44
|
-
* Available window aggregates.
|
|
51
|
+
* Available window aggregates per column type.
|
|
45
52
|
*/
|
|
46
|
-
window_aggregates?: { [key in ColumnType]?: Array<
|
|
53
|
+
window_aggregates?: { [key in ColumnType]?: Array<WindowAggSpec> },
|
|
47
54
|
/**
|
|
48
55
|
* Whether update callbacks are supported.
|
|
49
56
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `split_by` corollary to [`GroupRollupMode`]. `Flat` (the default,
|
|
5
|
+
* matching this crate's historical behavior) emits only full-depth split
|
|
6
|
+
* combinations as columns; `Rollup` additionally emits grand-total and
|
|
7
|
+
* subtotal column groups in "totals before" order. There is no `Total`
|
|
8
|
+
* variant - an empty `split_by` already expresses a single grand-total
|
|
9
|
+
* column group.
|
|
10
|
+
*/
|
|
11
|
+
export type SplitRollupMode = "flat" | "rollup";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { ListFlatten } from "./ListFlatten.js";
|
|
2
3
|
import type { TableReadFormat } from "./TableReadFormat.js";
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -24,4 +25,12 @@ limit?: number,
|
|
|
24
25
|
* instead of memory. On native targets this is a memory-mapped file; on
|
|
25
26
|
* WASM it is OPFS (Worker only). Defaults to in-memory.
|
|
26
27
|
*/
|
|
27
|
-
page_to_disk?: boolean,
|
|
28
|
+
page_to_disk?: boolean,
|
|
29
|
+
/**
|
|
30
|
+
* How Arrow `LIST` and JSON `Array` columns are ingested. `zip` (the
|
|
31
|
+
* default) and `cartesian` expand a row into one row per list element,
|
|
32
|
+
* and are incompatible with `index`, as the rows of an expansion
|
|
33
|
+
* repeat their index. `stringify` encodes each list as a JSON array in
|
|
34
|
+
* a single string column instead.
|
|
35
|
+
*/
|
|
36
|
+
list_flatten?: ListFlatten, };
|
|
@@ -5,6 +5,7 @@ import type { Filter } from "./Filter.js";
|
|
|
5
5
|
import type { FilterReducer } from "./FilterReducer.js";
|
|
6
6
|
import type { GroupRollupMode } from "./GroupRollupMode.js";
|
|
7
7
|
import type { Sort } from "./Sort.js";
|
|
8
|
+
import type { SplitRollupMode } from "./SplitRollupMode.js";
|
|
8
9
|
import type { Windows } from "./Windows.js";
|
|
9
10
|
|
|
10
|
-
export type ViewConfig = { group_by: Array<string>, split_by: Array<string>, sort: Array<Sort>, filter: Array<Filter>, group_rollup_mode: GroupRollupMode, filter_op?: FilterReducer, expressions: Expressions, windows?: Windows, columns: Array<string | null>, aggregates: { [key in string]?: Aggregate }, group_by_depth?: number | null, };
|
|
11
|
+
export type ViewConfig = { group_by: Array<string>, split_by: Array<string>, sort: Array<Sort>, filter: Array<Filter>, group_rollup_mode: GroupRollupMode, split_rollup_mode: SplitRollupMode, filter_op?: FilterReducer, expressions: Expressions, windows?: Windows, columns: Array<string | null>, aggregates: { [key in string]?: Aggregate }, group_by_depth?: number | null, };
|
|
@@ -5,6 +5,7 @@ import type { Filter } from "./Filter.js";
|
|
|
5
5
|
import type { FilterReducer } from "./FilterReducer.js";
|
|
6
6
|
import type { GroupRollupMode } from "./GroupRollupMode.js";
|
|
7
7
|
import type { Sort } from "./Sort.js";
|
|
8
|
+
import type { SplitRollupMode } from "./SplitRollupMode.js";
|
|
8
9
|
import type { Windows } from "./Windows.js";
|
|
9
10
|
|
|
10
11
|
export type ViewConfigUpdate = {
|
|
@@ -63,6 +64,12 @@ filter?: Array<Filter>,
|
|
|
63
64
|
* name and a string sort direction. When `column-pivots` are applied,
|
|
64
65
|
* the additional sort directions `"col asc"` and `"col desc"` will
|
|
65
66
|
* determine the order of pivot columns groups.
|
|
67
|
+
*
|
|
68
|
+
* `sort` is the ONLY thing that orders a `View`'s rows — without it
|
|
69
|
+
* they keep the `Table`'s natural (insertion) order, which any
|
|
70
|
+
* consumer reading rows sequentially will reflect. Not to be
|
|
71
|
+
* confused with a window column's `order_by`, which orders rows
|
|
72
|
+
* WITHIN a window frame and does not reorder the `View`.
|
|
66
73
|
*/
|
|
67
74
|
sort?: Array<Sort>,
|
|
68
75
|
/**
|
|
@@ -93,5 +100,12 @@ windows?: Windows,
|
|
|
93
100
|
* Perspective provides a selection of aggregate functions that can be
|
|
94
101
|
* applied to columns in the `View` constructor using a dictionary of
|
|
95
102
|
* column name to aggregate function name.
|
|
103
|
+
*
|
|
104
|
+
* An aggregate also determines the column's RESULT TYPE, which need
|
|
105
|
+
* not match the input: `"count"` yields an `integer` whatever it
|
|
106
|
+
* counts, so a `date` column left on the default `"count"` is an
|
|
107
|
+
* `integer` in the resulting `View` — no longer a date. Set an
|
|
108
|
+
* aggregate that preserves the type (e.g. `"any"`, `"last"`) when
|
|
109
|
+
* the original type matters, such as a date used as a chart axis.
|
|
96
110
|
*/
|
|
97
|
-
aggregates?: { [key in string]?: Aggregate }, group_by_depth?: number, filter_op?: FilterReducer, group_rollup_mode?: GroupRollupMode, };
|
|
111
|
+
aggregates?: { [key in string]?: Aggregate }, group_by_depth?: number, filter_op?: FilterReducer, group_rollup_mode?: GroupRollupMode, split_rollup_mode?: SplitRollupMode, };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { ColumnType } from "./ColumnType.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Specification for a window aggregate.
|
|
6
|
+
*/
|
|
7
|
+
export type WindowAggSpec = { name: string,
|
|
8
|
+
/**
|
|
9
|
+
* Frame kinds this aggregate accepts (`rows`, `range`, `cumulative`).
|
|
10
|
+
* Empty means it takes no frame at all.
|
|
11
|
+
*/
|
|
12
|
+
frames?: Array<string>,
|
|
13
|
+
/**
|
|
14
|
+
* Takes a row offset, as `lag` / `lead` / `diff` do.
|
|
15
|
+
*/
|
|
16
|
+
offset?: boolean,
|
|
17
|
+
/**
|
|
18
|
+
* Takes a smoothing factor, as `ema` does.
|
|
19
|
+
*/
|
|
20
|
+
alpha?: boolean,
|
|
21
|
+
/**
|
|
22
|
+
* The output column type. `None` means the source column's type, which
|
|
23
|
+
* is what `min` / `max` / `lag` do.
|
|
24
|
+
*/
|
|
25
|
+
result_type?: ColumnType, };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
-
import type { WindowAggregate } from "./WindowAggregate.js";
|
|
3
2
|
import type { WindowSort } from "./WindowSort.js";
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -10,7 +9,7 @@ export type WindowSpec = {
|
|
|
10
9
|
* The input column - either a real `Table` column or an expression
|
|
11
10
|
* alias from the same `ViewConfig`.
|
|
12
11
|
*/
|
|
13
|
-
column: string, aggregate:
|
|
12
|
+
column: string, aggregate: string,
|
|
14
13
|
/**
|
|
15
14
|
* Columns whose distinct value tuples partition the rows; empty
|
|
16
15
|
* partitions the whole `Table` as one group.
|
|
@@ -18,6 +17,8 @@ column: string, aggregate: WindowAggregate,
|
|
|
18
17
|
partition_by?: Array<string>,
|
|
19
18
|
/**
|
|
20
19
|
* The `Table` column which orders each partition, and the direction.
|
|
20
|
+
* This orders rows WITHIN the window frame only — it does not
|
|
21
|
+
* reorder the `View`, which is what the view-level `sort` does.
|
|
21
22
|
*/
|
|
22
23
|
order_by?: WindowSort | null,
|
|
23
24
|
/**
|
|
@@ -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,
|
|
@@ -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",
|
|
103
137
|
];
|
|
104
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",
|
|
157
|
+
];
|
|
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,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type WindowAggregate = "sum" | "avg" | "count" | "min" | "max" | "stddev" | "var" | "first" | "last" | "lag" | "lead" | "diff" | "rate" | "ema";
|