From fa48d4ea7d0e5009110a6e2d53ce7516b52d9b3f Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Wed, 8 Nov 2023 18:02:42 -0800 Subject: [PATCH] use is not distinct from (#15349) --- licenses.yaml | 2 +- web-console/package-lock.json | 14 +++---- web-console/package.json | 2 +- .../modules/table-react-module.tsx | 41 +++++++++---------- 4 files changed, 29 insertions(+), 30 deletions(-) diff --git a/licenses.yaml b/licenses.yaml index eb2d63dd2456..6f3fc81f49d0 100644 --- a/licenses.yaml +++ b/licenses.yaml @@ -4987,7 +4987,7 @@ license_category: binary module: web-console license_name: Apache License version 2.0 copyright: Imply Data -version: 0.21.1 +version: 0.21.4 --- diff --git a/web-console/package-lock.json b/web-console/package-lock.json index 3aad3ec2b956..42228155346d 100644 --- a/web-console/package-lock.json +++ b/web-console/package-lock.json @@ -14,7 +14,7 @@ "@blueprintjs/datetime2": "^0.9.35", "@blueprintjs/icons": "^4.16.0", "@blueprintjs/popover2": "^1.14.9", - "@druid-toolkit/query": "^0.21.1", + "@druid-toolkit/query": "^0.21.4", "@druid-toolkit/visuals-core": "^0.3.3", "@druid-toolkit/visuals-react": "^0.3.3", "ace-builds": "~1.4.14", @@ -2344,9 +2344,9 @@ } }, "node_modules/@druid-toolkit/query": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/@druid-toolkit/query/-/query-0.21.1.tgz", - "integrity": "sha512-p9bE0mlE0Lv6w1HOOr6m/NB1l4oQy0ew6HFa3hSZ1T/qlDx8CPT5MXRRhruEmgtneZx4UrN6RqFULJNFVv+aWg==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@druid-toolkit/query/-/query-0.21.4.tgz", + "integrity": "sha512-rZYRrtahy68ZMp3XDWa2Z3Pa28yiQMgDVHbB7ZAqynNFbKOgqS1j08LS122CRmNrvpAUyzwCnMj3Og4BvWeq1Q==", "dependencies": { "tslib": "^2.5.2" } @@ -26105,9 +26105,9 @@ "dev": true }, "@druid-toolkit/query": { - "version": "0.21.1", - "resolved": "https://registry.npmjs.org/@druid-toolkit/query/-/query-0.21.1.tgz", - "integrity": "sha512-p9bE0mlE0Lv6w1HOOr6m/NB1l4oQy0ew6HFa3hSZ1T/qlDx8CPT5MXRRhruEmgtneZx4UrN6RqFULJNFVv+aWg==", + "version": "0.21.4", + "resolved": "https://registry.npmjs.org/@druid-toolkit/query/-/query-0.21.4.tgz", + "integrity": "sha512-rZYRrtahy68ZMp3XDWa2Z3Pa28yiQMgDVHbB7ZAqynNFbKOgqS1j08LS122CRmNrvpAUyzwCnMj3Og4BvWeq1Q==", "requires": { "tslib": "^2.5.2" } diff --git a/web-console/package.json b/web-console/package.json index d43d6615ba41..1cd3fd894ad4 100644 --- a/web-console/package.json +++ b/web-console/package.json @@ -68,7 +68,7 @@ "@blueprintjs/datetime2": "^0.9.35", "@blueprintjs/icons": "^4.16.0", "@blueprintjs/popover2": "^1.14.9", - "@druid-toolkit/query": "^0.21.1", + "@druid-toolkit/query": "^0.21.4", "@druid-toolkit/visuals-core": "^0.3.3", "@druid-toolkit/visuals-react": "^0.3.3", "ace-builds": "~1.4.14", diff --git a/web-console/src/views/explore-view/modules/table-react-module.tsx b/web-console/src/views/explore-view/modules/table-react-module.tsx index dabe6217c9be..6dacaf477a16 100644 --- a/web-console/src/views/explore-view/modules/table-react-module.tsx +++ b/web-console/src/views/explore-view/modules/table-react-module.tsx @@ -16,11 +16,12 @@ * limitations under the License. */ -import type { SqlColumn, SqlOrderByExpression } from '@druid-toolkit/query'; +import type { SqlOrderByExpression } from '@druid-toolkit/query'; import { C, F, SqlCase, + SqlColumn, SqlExpression, SqlFunction, SqlLiteral, @@ -72,20 +73,6 @@ const KNOWN_AGGREGATIONS = [ 'ANY_VALUE', ]; -const NULL_REPLACEMENT = SqlLiteral.create('__VIS_NULL__'); - -function nullableColumn(column: ExpressionMeta) { - return column.sqlType !== 'TIMESTAMP'; -} - -function nvl(ex: SqlExpression): SqlExpression { - return SqlFunction.simple('NVL', [ex.cast('VARCHAR'), NULL_REPLACEMENT]); -} - -function joinEquals(c1: SqlColumn, c2: SqlColumn, nullable: boolean): SqlExpression { - return c1.applyIf(nullable, nvl).equal(c2.applyIf(nullable, nvl)); -} - function toGroupByExpression( splitColumn: ExpressionMeta, timeBucket: string, @@ -144,6 +131,20 @@ function toShowColumnExpression( return ex.as(showColumn.name); } +function shiftTimeInWhere(where: SqlExpression, period: string): SqlExpression { + return where.walk(q => { + if ( + (q instanceof SqlColumn && q.getName() === '__time') || + (q instanceof SqlFunction && q.getEffectiveFunctionName() === 'TIME_SHIFT') || + (q instanceof SqlFunction && q.getEffectiveFunctionName() === 'MAX_DATA_TIME') + ) { + return SqlFunction.simple('TIME_SHIFT', [q, period, 1]); + } else { + return q; + } + }) as SqlExpression; +} + interface QueryAndHints { query: SqlQuery; groupHints: string[]; @@ -370,7 +371,7 @@ function TableModule(props: TableModuleProps) { compares.map((comparePeriod, i) => SqlWithPart.simple( `compare${i}`, - getInitQuery(table, where) + getInitQuery(table, shiftTimeInWhere(where, comparePeriod)) .applyForEach(splitColumns, (q, splitColumn) => q.addSelect(toGroupByExpression(splitColumn, timeBucket, comparePeriod), { addToGroupBy: 'end', @@ -417,11 +418,9 @@ function TableModule(props: TableModuleProps) { T(`compare${i}`), SqlExpression.and( ...splitColumns.map(splitColumn => - joinEquals( - main.column(splitColumn.name), - T(`compare${i}`).column(splitColumn.name), - nullableColumn(splitColumn), - ), + main + .column(splitColumn.name) + .isNotDistinctFrom(T(`compare${i}`).column(splitColumn.name)), ), ), ),