Skip to content

Commit

Permalink
Moved OFFSET removal logic to a seperate function
Browse files Browse the repository at this point in the history
  • Loading branch information
praveen5959 authored Nov 11, 2024
1 parent 1e736d6 commit 2ad5c21
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/pages/Stream/components/EventTimeLineGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ const { makeTimeRangeLabel } = timeRangeUtils;
type CompactInterval = 'minute' | 'day' | 'hour' | 'quarter-hour' | 'half-hour' | 'month';

function extractWhereClause(sql: string) {
const whereClauseRegex = /WHERE\s+(.*?)(?=\s*(ORDER\s+BY|GROUP\s+BY|OFFSET|LIMIT|$))/i;
const whereClauseRegex = /WHERE\s+(.*?)(?=\s*(ORDER\s+BY|GROUP\s+BY|LIMIT|$))/i;
const match = sql.match(whereClauseRegex);
if (match) {
return match[1].trim();
}
return '(1 = 1)';
}

function removeOffsetFromQuery(query: string): string {
const offsetRegex = /\sOFFSET\s+\d+/i;
return query.replace(offsetRegex, '');
}

const getCompactType = (interval: number): CompactInterval => {
const totalMinutes = interval / (1000 * 60);
if (totalMinutes <= 60) {
Expand Down Expand Up @@ -283,10 +288,11 @@ const EventTimeLineGraph = () => {
? extractWhereClause(custSearchQuery)
: parseQuery(queryEngine, appliedQuery, localStream).where;
const query = generateCountQuery(localStream, modifiedStartTime, modifiedEndTime, compactType, whereClause);
const graphQuery = removeOffsetFromQuery(query);
fetchQueryMutation.mutate({
queryEngine: 'Parseable', // query for graph should always hit the endpoint for parseable query
logsQuery,
query,
query: graphQuery,
});
}, [localStream, startTime.toISOString(), endTime.toISOString(), custSearchQuery]);

Expand Down

0 comments on commit 2ad5c21

Please sign in to comment.