From 8ffc92d544d751ff75b9f1453f3c631fc71f6074 Mon Sep 17 00:00:00 2001 From: jheer Date: Thu, 21 Sep 2023 14:56:41 -0700 Subject: [PATCH] fix: Push orderby to data cube index queries. --- dev/index.html | 1 + dev/yaml/highlight-cube.yaml | 46 ++++++++++++++++++++++++++++ packages/core/src/DataCubeIndexer.js | 11 +++++-- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 dev/yaml/highlight-cube.yaml diff --git a/dev/index.html b/dev/index.html index 49aead67..66ddf3ff 100644 --- a/dev/index.html +++ b/dev/index.html @@ -22,6 +22,7 @@ + diff --git a/dev/yaml/highlight-cube.yaml b/dev/yaml/highlight-cube.yaml new file mode 100644 index 00000000..869530e0 --- /dev/null +++ b/dev/yaml/highlight-cube.yaml @@ -0,0 +1,46 @@ +data: + athletes: { file: data/athletes.csv } +params: + query: { select: crossfilter } + selectNationality: { select: single } + selectSport: { select: single } +vconcat: + - plot: + - mark: barX + data: { from: athletes, filterBy: $query } + x: { count: } + y: nationality + order: nationality + sort: { + y: '-x', + limit: 10 + } + - select: highlight + by: $selectNationality + - select: toggleY + as: $selectNationality + - select: toggleY + as: $query + width: 600 + height: 400 + marginLeft: 80 + - vspace: 10 + - plot: + - mark: barX + data: { from: athletes, filterBy: $query } + x: { count: } + y: sport + order: sport + sort: { + y: '-x', + limit: 10 + } + - select: highlight + by: $selectSport + - select: toggleY + as: $selectSport + - select: toggleY + as: $query + width: 600 + height: 400 + marginLeft: 80 \ No newline at end of file diff --git a/packages/core/src/DataCubeIndexer.js b/packages/core/src/DataCubeIndexer.js index b361fab9..f3957b6f 100644 --- a/packages/core/src/DataCubeIndexer.js +++ b/packages/core/src/DataCubeIndexer.js @@ -87,11 +87,15 @@ export class DataCubeIndexer { subqueryPushdown(subq, cols); } + // push orderby criteria to later cube queries + const order = query.orderby(); + query.query.orderby = []; + const sql = query.toString(); const id = (fnv_hash(sql) >>> 0).toString(16); const table = `cube_index_${id}`; const result = mc.exec(create(table, sql, { temp })); - indices.set(client, { table, result, ...index }); + indices.set(client, { table, result, order, ...index }); } } @@ -111,12 +115,13 @@ export class DataCubeIndexer { filter = this.activeView.predicate(this.selection.active.predicate); } - const { table, dims, aggr } = index; + const { table, dims, aggr, order = [] } = index; const query = Query .select(dims, aggr) .from(table) .groupby(dims) - .where(filter); + .where(filter) + .orderby(order); return this.mc.updateClient(client, query); } }