Skip to content

Commit

Permalink
use is not distinct from (apache#15349)
Browse files Browse the repository at this point in the history
  • Loading branch information
vogievetsky authored Nov 9, 2023
1 parent d12f557 commit fa48d4e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 30 deletions.
2 changes: 1 addition & 1 deletion licenses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

---

Expand Down
14 changes: 7 additions & 7 deletions web-console/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web-console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
41 changes: 20 additions & 21 deletions web-console/src/views/explore-view/modules/table-react-module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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[];
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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)),
),
),
),
Expand Down

0 comments on commit fa48d4e

Please sign in to comment.