From 863f3709e97c904f1c800ad98889dc272dbfddbd Mon Sep 17 00:00:00 2001 From: Ryan Woodring Date: Mon, 9 Sep 2024 11:19:47 -0400 Subject: [PATCH] fix(api-gateway): fixes an issue where queries to get the total count of results were incorrectly applying sorting from the original query and also were getting default ordering applied when the query ordering was stripped out (#8060) Thanks @rdwoodring! * fix(api-gateway) fix(schema-compiler): fixes an issue where queries to get the total count of results were incorrectly applying sorting from the original query and also were getting default ordering applied when the query ordering was stripped out * fix(api-gateway): add missing semicolon --------- Co-authored-by: Ryan Woodring --- packages/cubejs-api-gateway/src/gateway.ts | 4 ++++ packages/cubejs-schema-compiler/src/adapter/BaseQuery.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cubejs-api-gateway/src/gateway.ts b/packages/cubejs-api-gateway/src/gateway.ts index 5ee0f2af0ab25..6f2d0fa4e0f26 100644 --- a/packages/cubejs-api-gateway/src/gateway.ts +++ b/packages/cubejs-api-gateway/src/gateway.ts @@ -1552,9 +1552,13 @@ class ApiGateway { if (normalizedQuery.total) { const normalizedTotal = structuredClone(normalizedQuery); normalizedTotal.totalQuery = true; + + delete normalizedTotal.order; + normalizedTotal.limit = null; normalizedTotal.rowLimit = null; normalizedTotal.offset = null; + const [totalQuery] = await this.getSqlQueriesInternal( context, [normalizedTotal], diff --git a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js index 07ad2fdc528ff..9a0de0cd60cf3 100644 --- a/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js +++ b/packages/cubejs-schema-compiler/src/adapter/BaseQuery.js @@ -387,7 +387,7 @@ export class BaseQuery { } defaultOrder() { - if (this.options.preAggregationQuery) { + if (this.options.preAggregationQuery || this.options.totalQuery) { return []; }