Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/store/reducers/executeTopQueries/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {ITopQueriesFilters} from './types';

const endTimeColumn = 'EndTime';
const intervalEndColumn = 'IntervalEnd';

const getMaxIntervalSubquery = (path: string) => `(
SELECT
MAX(IntervalEnd)
MAX(${intervalEndColumn})
FROM \`${path}/.sys/top_queries_by_cpu_time_one_hour\`
)`;

Expand All @@ -17,15 +20,18 @@ export function getFiltersConditions(path: string, filters?: ITopQueriesFilters)
// matching `from` & `to` is an edge case
// other cases should not include the starting point, since intervals are stored using the ending time
const gt = filters.to === filters.from ? '>=' : '>';
conditions.push(`IntervalEnd ${gt} Timestamp('${new Date(filters.from).toISOString()}')`);
conditions.push(
`${endTimeColumn} ${gt} Timestamp('${new Date(filters.from).toISOString()}')`,
);
}

if (filters?.to) {
conditions.push(`IntervalEnd <= Timestamp('${new Date(filters.to).toISOString()}')`);
conditions.push(`${endTimeColumn} <= Timestamp('${new Date(filters.to).toISOString()}')`);
}

// If there is no filters, return queries, that were executed in the last hour
if (!filters?.from && !filters?.to) {
conditions.push(`IntervalEnd IN ${getMaxIntervalSubquery(path)}`);
conditions.push(`${intervalEndColumn} IN ${getMaxIntervalSubquery(path)}`);
}

if (filters?.text) {
Expand Down