@perspective-dev/client 4.2.0 → 4.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.
@@ -76,41 +76,47 @@ const FILTER_OPS = [
76
76
  ];
77
77
 
78
78
  function duckdbTypeToPsp(name: string): ColumnType {
79
- if (name === "VARCHAR" || name == "Utf8") {
79
+ name = name.toLowerCase();
80
+ if (name === "varchar" || name == "utf8") {
80
81
  return "string";
81
82
  }
82
83
 
83
84
  if (
84
- name === "DOUBLE" ||
85
- name === "BIGINT" ||
86
- name === "HUGEINT" ||
87
- name === "Float64" ||
88
- name.startsWith("Decimal")
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("Int") || name == "INTEGER") {
94
+ if (name.startsWith("int")) {
94
95
  return "integer";
95
96
  }
96
97
 
97
- if (name === "INTEGER") {
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 === "BOOLEAN" || name === "Bool") {
102
+ if (name.startsWith("bool")) {
106
103
  return "boolean";
107
104
  }
108
105
 
109
- if (name === "TIMESTAMP" || name.startsWith("Timestamp")) {
106
+ if (name.startsWith("timestamp")) {
110
107
  return "datetime";
111
108
  }
112
109
 
113
- throw new Error(`Unknown type '${name}'`);
110
+ if (name.startsWith("json")) {
111
+ return "string";
112
+ }
113
+
114
+ if (name.startsWith("struct")) {
115
+ return "string";
116
+ }
117
+
118
+ console.warn(`Unknown type '${name}'`);
119
+ return "string";
114
120
  }
115
121
 
116
122
  function convertDecimalToNumber(value: any, dtypeString: string) {
@@ -202,6 +208,7 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
202
208
  split_by: true,
203
209
  sort: true,
204
210
  expressions: true,
211
+ group_rollup_mode: ["rollup", "flat", "total"],
205
212
  filter_ops: {
206
213
  integer: FILTER_OPS,
207
214
  float: FILTER_OPS,
@@ -250,12 +257,10 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
250
257
  async viewColumnSize(viewId: string, config: ViewConfig) {
251
258
  const query = this.sqlBuilder.viewColumnSize(viewId);
252
259
  const results = await runQuery(this.db, query);
253
- const gs = config.group_by?.length || 0;
254
260
  const count = Number(Object.values(results[0].toJSON())[0]);
255
- return (
256
- count -
257
- (gs === 0 ? 0 : gs + (config.split_by?.length === 0 ? 1 : 0))
258
- );
261
+ const gs = config.group_by?.length || 0;
262
+ const is_flat = config.group_rollup_mode === "flat";
263
+ return count - (gs === 0 ? 0 : is_flat ? gs : gs + 1);
259
264
  }
260
265
 
261
266
  async tableSize(tableId: string) {
@@ -294,6 +299,8 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
294
299
  ) {
295
300
  const is_group_by = config.group_by?.length > 0;
296
301
  const is_split_by = config.split_by?.length > 0;
302
+ const is_flat = config.group_rollup_mode === "flat";
303
+ const has_grouping_id = is_group_by && !is_flat;
297
304
  const query = this.sqlBuilder.viewGetData(
298
305
  viewId,
299
306
  config,
@@ -306,22 +313,23 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
306
313
  });
307
314
 
308
315
  for (let cidx = 0; cidx < columns.length; cidx++) {
309
- if (cidx === 0 && is_group_by && !is_split_by) {
316
+ if (cidx === 0 && has_grouping_id) {
310
317
  // This is the grouping_id column, skip it
311
318
  continue;
312
319
  }
313
320
 
314
321
  let col = columns[cidx];
315
- if (is_split_by && !col.startsWith("__ROW_PATH_")) {
322
+ if (is_split_by && !col.startsWith("__")) {
316
323
  col = col.replaceAll("_", "|");
317
324
  }
318
325
 
319
326
  const dtype = duckdbTypeToPsp(dtypes[cidx]) as ColumnType;
320
-
321
327
  const isDecimal = dtypes[cidx].startsWith("Decimal");
322
328
  for (let ridx = 0; ridx < rows.length; ridx++) {
323
329
  const rowArray = rows[ridx].toArray();
324
- const grouping_id = Number(rowArray[0]);
330
+ const grouping_id = has_grouping_id
331
+ ? Number(rowArray[0])
332
+ : undefined;
325
333
  let value = rowArray[cidx];
326
334
  if (isDecimal) {
327
335
  value = convertDecimalToNumber(value, dtypes[cidx]);
@@ -331,6 +339,14 @@ export class DuckDBHandler implements perspective.VirtualServerHandler {
331
339
  value = Number(value);
332
340
  }
333
341
 
342
+ if (typeof value !== "string" && dtype === "string") {
343
+ try {
344
+ value = JSON.stringify(value);
345
+ } catch (e) {
346
+ value = `${value}`;
347
+ }
348
+ }
349
+
334
350
  dataSlice.setCol(dtype, col, ridx, value, grouping_id);
335
351
  }
336
352
  }
package/tsconfig.json CHANGED
@@ -16,6 +16,7 @@
16
16
  "./src/ts/perspective.node.ts",
17
17
  "./src/ts/perspective.cdn.ts",
18
18
  "./src/ts/virtual_servers/duckdb.ts",
19
+ "./src/ts/virtual_servers/clickhouse.ts",
19
20
  "./test/js/*.ts"
20
21
  ]
21
22
  }