Skip to content

Commit 8071934

Browse files
authored
feat(webui): Increase precision of time range in guided UI from seconds to milliseconds. (#1543)
1 parent ad7cffe commit 8071934

File tree

1 file changed

+11
-4
lines changed
  • components/webui/client/src/sql-parser

1 file changed

+11
-4
lines changed

components/webui/client/src/sql-parser/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ const validate = (sqlString: string) => {
7878
buildParser(sqlString).singleStatement();
7979
};
8080

81+
const MILLISECONDS_PER_SECOND = 1000;
82+
8183
/**
8284
* Constructs a SQL search query string from a set of structured components.
8385
*
@@ -104,7 +106,9 @@ const buildSearchQuery = ({
104106
timestampKey,
105107
}: BuildSearchQueryProps): string => {
106108
let queryString = `SELECT ${selectItemList} FROM ${databaseName}
107-
WHERE to_unixtime(${timestampKey}) BETWEEN ${startTimestamp.unix()} AND ${endTimestamp.unix()}`;
109+
WHERE to_unixtime(${timestampKey}) BETWEEN
110+
${startTimestamp.valueOf() / MILLISECONDS_PER_SECOND}
111+
AND ${endTimestamp.valueOf() / MILLISECONDS_PER_SECOND}`;
108112

109113
if ("undefined" !== typeof booleanExpression) {
110114
queryString += ` AND (${booleanExpression})`;
@@ -125,6 +129,7 @@ WHERE to_unixtime(${timestampKey}) BETWEEN ${startTimestamp.unix()} AND ${endTim
125129
return queryString;
126130
};
127131

132+
128133
/**
129134
* Constructs a bucketed timeline query.
130135
*
@@ -160,12 +165,14 @@ const buildTimelineQuery = ({
160165
SELECT
161166
width_bucket(
162167
to_unixtime(${timestampKey}),
163-
${startTimestamp.unix()},
164-
${endTimestamp.unix()},
168+
${startTimestamp.valueOf() / MILLISECONDS_PER_SECOND},
169+
${endTimestamp.valueOf() / MILLISECONDS_PER_SECOND},
165170
${bucketCount}) AS idx,
166171
COUNT(*) AS cnt
167172
FROM ${databaseName}
168-
WHERE to_unixtime(${timestampKey}) BETWEEN ${startTimestamp.unix()} AND ${endTimestamp.unix()}
173+
WHERE to_unixtime(${timestampKey}) BETWEEN
174+
${startTimestamp.valueOf() / MILLISECONDS_PER_SECOND}
175+
AND ${endTimestamp.valueOf() / MILLISECONDS_PER_SECOND}
169176
${booleanExpressionQuery}
170177
GROUP BY 1
171178
ORDER BY 1

0 commit comments

Comments
 (0)