|
1 | 1 | import _ from "lodash"; |
2 | | -import {BigQueryDatasource} from "./datasource"; |
| 2 | +import { BigQueryDatasource } from "./datasource"; |
3 | 3 |
|
4 | 4 | export default class BigQueryQuery { |
5 | 5 | public static quoteLiteral(value) { |
@@ -44,8 +44,12 @@ export default class BigQueryQuery { |
44 | 44 | ? q.match(/(\$__timeGroupAlias\(([\w._]+,)).*?(?=\))/g) |
45 | 45 | : q.match(/(\$__timeGroup\(([\w_.]+,)).*?(?=\))/g); |
46 | 46 | if (res) { |
47 | | - interval[0] = res[0].split(",")[1] ? res[0].split(",")[1].trim() : res[0].split(",")[1]; |
48 | | - interval[1] = res[0].split(",")[2] ? res[0].split(",")[2].trim() : res[0].split(",")[2]; |
| 47 | + interval[0] = res[0].split(",")[1] |
| 48 | + ? res[0].split(",")[1].trim() |
| 49 | + : res[0].split(",")[1]; |
| 50 | + interval[1] = res[0].split(",")[2] |
| 51 | + ? res[0].split(",")[2].trim() |
| 52 | + : res[0].split(",")[2]; |
49 | 53 | } |
50 | 54 | return interval; |
51 | 55 | } |
@@ -117,7 +121,7 @@ export default class BigQueryQuery { |
117 | 121 | target.metricColumn = target.metricColumn || "none"; |
118 | 122 | target.group = target.group || []; |
119 | 123 | target.where = target.where || [ |
120 | | - { type: "macro", name: "$__timeFilter", params: [] }, |
| 124 | + { type: "macro", name: "$__timeFilter", params: [] } |
121 | 125 | ]; |
122 | 126 | target.select = target.select || [ |
123 | 127 | [{ type: "column", params: ["-- value --"] }] |
@@ -316,7 +320,6 @@ export default class BigQueryQuery { |
316 | 320 | return query; |
317 | 321 | } |
318 | 322 |
|
319 | | - |
320 | 323 | public buildValueColumn(column) { |
321 | 324 | const columnName = _.find(column, (g: any) => g.type === "column"); |
322 | 325 | let query = BigQueryQuery.quoteFiledName(columnName.params[0]); |
@@ -659,15 +662,9 @@ export default class BigQueryQuery { |
659 | 662 | " AND " + |
660 | 663 | to; |
661 | 664 | const fromRange = |
662 | | - BigQueryQuery.quoteFiledName(this.target.timeColumn) + |
663 | | - " > " + |
664 | | - from + |
665 | | - " "; |
| 665 | + BigQueryQuery.quoteFiledName(this.target.timeColumn) + " > " + from + " "; |
666 | 666 | const toRange = |
667 | | - BigQueryQuery.quoteFiledName(this.target.timeColumn) + |
668 | | - " < " + |
669 | | - to + |
670 | | - " "; |
| 667 | + BigQueryQuery.quoteFiledName(this.target.timeColumn) + " < " + to + " "; |
671 | 668 | q = q.replace(/\$__timeFilter\(([\w_.]+)\)/g, range); |
672 | 669 | q = q.replace(/\$__timeFrom\(([\w_.]+)\)/g, fromRange); |
673 | 670 | q = q.replace(/\$__timeTo\(([\w_.]+)\)/g, toRange); |
|
0 commit comments