@perspective-dev/client 4.2.0 → 4.4.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.d.ts +10 -0
- package/dist/esm/perspective.node.js +95 -9
- package/dist/esm/perspective.node.js.map +2 -2
- package/dist/esm/ts-rs/GroupRollupMode.d.ts +1 -0
- package/dist/esm/ts-rs/JoinOptions.d.ts +9 -0
- package/dist/esm/ts-rs/JoinType.d.ts +1 -0
- package/dist/esm/ts-rs/ViewConfig.d.ts +2 -0
- package/dist/esm/ts-rs/ViewConfigUpdate.d.ts +2 -0
- package/dist/esm/ts-rs/ViewWindow.d.ts +0 -1
- package/dist/esm/virtual_server.d.ts +7 -0
- 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.d.ts +5 -0
- 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 +41 -5
- package/dist/wasm/perspective-js.js +90 -11
- package/dist/wasm/perspective-js.wasm +0 -0
- package/dist/wasm/perspective-js.wasm.d.ts +8 -5
- package/package.json +5 -5
- package/src/rust/client.rs +70 -1
- package/src/rust/generic_sql_model.rs +16 -0
- package/src/rust/lib.rs +4 -0
- package/src/rust/utils/errors.rs +4 -0
- package/src/rust/utils/futures.rs +5 -6
- package/src/rust/view.rs +13 -4
- package/src/rust/virtual_server.rs +68 -1
- package/src/ts/perspective.node.ts +18 -0
- package/src/ts/ts-rs/GroupRollupMode.ts +3 -0
- package/src/ts/ts-rs/JoinOptions.ts +7 -0
- package/src/ts/ts-rs/JoinType.ts +3 -0
- package/src/ts/ts-rs/ViewConfig.ts +2 -1
- package/src/ts/ts-rs/ViewConfigUpdate.ts +2 -1
- package/src/ts/ts-rs/ViewWindow.ts +1 -1
- package/src/ts/virtual_server.ts +5 -0
- package/src/ts/virtual_servers/clickhouse.ts +3 -13
- package/src/ts/virtual_servers/duckdb.ts +39 -69
- package/tsconfig.json +1 -0
|
@@ -76,60 +76,47 @@ const FILTER_OPS = [
|
|
|
76
76
|
];
|
|
77
77
|
|
|
78
78
|
function duckdbTypeToPsp(name: string): ColumnType {
|
|
79
|
-
|
|
79
|
+
name = name.toLowerCase();
|
|
80
|
+
if (name === "varchar" || name == "utf8") {
|
|
80
81
|
return "string";
|
|
81
82
|
}
|
|
82
83
|
|
|
83
84
|
if (
|
|
84
|
-
name === "
|
|
85
|
-
name === "
|
|
86
|
-
name === "
|
|
87
|
-
name === "
|
|
88
|
-
name.startsWith("
|
|
85
|
+
name === "double" ||
|
|
86
|
+
name === "bigint" ||
|
|
87
|
+
name === "hugeint" ||
|
|
88
|
+
name === "float64" ||
|
|
89
|
+
name.startsWith("decimal")
|
|
89
90
|
) {
|
|
90
91
|
return "float";
|
|
91
92
|
}
|
|
92
93
|
|
|
93
|
-
if (name.startsWith("
|
|
94
|
+
if (name.startsWith("int")) {
|
|
94
95
|
return "integer";
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
if (name
|
|
98
|
-
return "integer";
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (name === "DATE" || name.startsWith("Date")) {
|
|
98
|
+
if (name.startsWith("date")) {
|
|
102
99
|
return "date";
|
|
103
100
|
}
|
|
104
101
|
|
|
105
|
-
if (name
|
|
102
|
+
if (name.startsWith("bool")) {
|
|
106
103
|
return "boolean";
|
|
107
104
|
}
|
|
108
105
|
|
|
109
|
-
if (name
|
|
106
|
+
if (name.startsWith("timestamp")) {
|
|
110
107
|
return "datetime";
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
function convertDecimalToNumber(value: any, dtypeString: string) {
|
|
117
|
-
if (!(value instanceof Uint32Array || value instanceof Int32Array)) {
|
|
118
|
-
return value;
|
|
110
|
+
if (name.startsWith("json")) {
|
|
111
|
+
return "string";
|
|
119
112
|
}
|
|
120
113
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
bigIntValue |= BigInt(value[i]) << BigInt(i * 32);
|
|
114
|
+
if (name.startsWith("struct")) {
|
|
115
|
+
return "string";
|
|
124
116
|
}
|
|
125
117
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const scale = parseInt(scaleMatch[1]);
|
|
129
|
-
return Number(bigIntValue) / Math.pow(10, scale);
|
|
130
|
-
} else {
|
|
131
|
-
return Number(bigIntValue);
|
|
132
|
-
}
|
|
118
|
+
console.warn(`Unknown type '${name}'`);
|
|
119
|
+
return "string";
|
|
133
120
|
}
|
|
134
121
|
|
|
135
122
|
async function runQuery(
|
|
@@ -202,6 +189,7 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
202
189
|
split_by: true,
|
|
203
190
|
sort: true,
|
|
204
191
|
expressions: true,
|
|
192
|
+
group_rollup_mode: ["rollup", "flat", "total"],
|
|
205
193
|
filter_ops: {
|
|
206
194
|
integer: FILTER_OPS,
|
|
207
195
|
float: FILTER_OPS,
|
|
@@ -250,12 +238,10 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
250
238
|
async viewColumnSize(viewId: string, config: ViewConfig) {
|
|
251
239
|
const query = this.sqlBuilder.viewColumnSize(viewId);
|
|
252
240
|
const results = await runQuery(this.db, query);
|
|
253
|
-
const gs = config.group_by?.length || 0;
|
|
254
241
|
const count = Number(Object.values(results[0].toJSON())[0]);
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
);
|
|
242
|
+
const gs = config.group_by?.length || 0;
|
|
243
|
+
const is_flat = config.group_rollup_mode === "flat";
|
|
244
|
+
return count - (gs === 0 ? 0 : is_flat ? gs : gs + 1);
|
|
259
245
|
}
|
|
260
246
|
|
|
261
247
|
async tableSize(tableId: string) {
|
|
@@ -285,6 +271,20 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
285
271
|
await runQuery(this.db, query);
|
|
286
272
|
}
|
|
287
273
|
|
|
274
|
+
async viewGetMinMax(
|
|
275
|
+
viewId: string,
|
|
276
|
+
columnName: string,
|
|
277
|
+
config: ViewConfig,
|
|
278
|
+
) {
|
|
279
|
+
const query = this.sqlBuilder.viewGetMinMax(viewId, columnName, config);
|
|
280
|
+
const results = await runQuery(this.db, query);
|
|
281
|
+
const row = results[0].toJSON();
|
|
282
|
+
let [min, max] = Object.values(row);
|
|
283
|
+
if (typeof min === "bigint") min = Number(min);
|
|
284
|
+
if (typeof max === "bigint") max = Number(max);
|
|
285
|
+
return { min: min ?? null, max: max ?? null };
|
|
286
|
+
}
|
|
287
|
+
|
|
288
288
|
async viewGetData(
|
|
289
289
|
viewId: string,
|
|
290
290
|
config: ViewConfig,
|
|
@@ -292,8 +292,6 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
292
292
|
viewport: ViewWindow,
|
|
293
293
|
dataSlice: perspective.VirtualDataSlice,
|
|
294
294
|
) {
|
|
295
|
-
const is_group_by = config.group_by?.length > 0;
|
|
296
|
-
const is_split_by = config.split_by?.length > 0;
|
|
297
295
|
const query = this.sqlBuilder.viewGetData(
|
|
298
296
|
viewId,
|
|
299
297
|
config,
|
|
@@ -301,38 +299,10 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
|
|
|
301
299
|
schema,
|
|
302
300
|
);
|
|
303
301
|
|
|
304
|
-
const
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
for (let cidx = 0; cidx < columns.length; cidx++) {
|
|
309
|
-
if (cidx === 0 && is_group_by && !is_split_by) {
|
|
310
|
-
// This is the grouping_id column, skip it
|
|
311
|
-
continue;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
let col = columns[cidx];
|
|
315
|
-
if (is_split_by && !col.startsWith("__ROW_PATH_")) {
|
|
316
|
-
col = col.replaceAll("_", "|");
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
const dtype = duckdbTypeToPsp(dtypes[cidx]) as ColumnType;
|
|
320
|
-
|
|
321
|
-
const isDecimal = dtypes[cidx].startsWith("Decimal");
|
|
322
|
-
for (let ridx = 0; ridx < rows.length; ridx++) {
|
|
323
|
-
const rowArray = rows[ridx].toArray();
|
|
324
|
-
const grouping_id = Number(rowArray[0]);
|
|
325
|
-
let value = rowArray[cidx];
|
|
326
|
-
if (isDecimal) {
|
|
327
|
-
value = convertDecimalToNumber(value, dtypes[cidx]);
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (typeof value === "bigint") {
|
|
331
|
-
value = Number(value);
|
|
332
|
-
}
|
|
302
|
+
const ipc = await this.db.useUnsafe((bindings, conn) =>
|
|
303
|
+
bindings.runQuery(conn, query),
|
|
304
|
+
);
|
|
333
305
|
|
|
334
|
-
|
|
335
|
-
}
|
|
336
|
-
}
|
|
306
|
+
dataSlice.fromArrowIpc(ipc);
|
|
337
307
|
}
|
|
338
308
|
}
|