diff --git a/src/store/reducers/executeTopQueries/utils.ts b/src/store/reducers/executeTopQueries/utils.ts index c3b2d26f79..210872bf62 100644 --- a/src/store/reducers/executeTopQueries/utils.ts +++ b/src/store/reducers/executeTopQueries/utils.ts @@ -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\` )`; @@ -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) {