Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.

Commit 19a8f49

Browse files
authored
Merge pull request #236 from ptomasroos/fix-235
Math.round causes overflow in timegroups, we should ceil instead
2 parents 30c3a67 + 94b2341 commit 19a8f49

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/bigquery_query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ export default class BigQueryQuery {
693693
const seconds =
694694
(this.templateSrv.timeRange.to._d - this.templateSrv.timeRange.from._d) /
695695
1000;
696-
return Math.round(seconds / options.maxDataPoints) + "s";
696+
return Math.ceil(seconds / options.maxDataPoints) + "s";
697697
}
698698
private _getDateRangePart(part) {
699699
if (this.target.timeColumnType === "DATE") {

src/specs/bigquery_query.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,15 @@ describe("BigQueryQuery", () => {
331331
where: []
332332
};
333333
const query = new BigQueryQuery(target, templateSrv);
334+
const time = {
335+
from: { _d: 1588147101364 },
336+
to: { _d: 1588148901364 }
337+
};
338+
query.templateSrv.timeRange = time;
339+
340+
expect(query.getIntervalStr("auto", undefined, { maxDataPoints: 1742 })).toBe(
341+
"TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(`my_data`), 2) * 2) AS time"
342+
);
334343
expect(query.getIntervalStr("1s", "0", null)).toBe(
335344
"TIMESTAMP_SECONDS(DIV(UNIX_SECONDS(`my_data`), 1) * 1) AS time"
336345
);

0 commit comments

Comments
 (0)