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

Commit a55a626

Browse files
committed
Fixes #107
1 parent 5d335ba commit a55a626

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

dist/module.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51270,7 +51270,18 @@ function () {
5127051270
};
5127151271

5127251272
BigQueryQuery.quoteFiledName = function (value) {
51273-
return "`" + String(value) + "`";
51273+
var vals = value.split(".");
51274+
var res = "";
51275+
51276+
for (var i = 0; i < vals.length; i++) {
51277+
res = res + "`" + String(vals[i]) + "`";
51278+
51279+
if (vals.length > 1 && i + 1 < vals.length) {
51280+
res = res + ".";
51281+
}
51282+
}
51283+
51284+
return res;
5127451285
};
5127551286

5127651287
BigQueryQuery.formatDateToString = function (date, separator, addtime) {
@@ -51449,7 +51460,7 @@ function () {
5144951460

5145051461
BigQueryQuery.prototype.buildMetricColumn = function () {
5145151462
if (this.hasMetricColumn()) {
51452-
return BigQueryQuery.quoteFiledName(this.target.metricColumn) + " AS metric";
51463+
return "CAST (" + BigQueryQuery.quoteFiledName(this.target.metricColumn) + "AS String ) AS metric";
5145351464
}
5145451465

5145551466
return "";

dist/module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bigquery_query.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ export default class BigQueryQuery {
1111
}
1212

1313
public static quoteFiledName(value) {
14-
return "`" + String(value) + "`";
14+
const vals = value.split(".");
15+
let res = "";
16+
for (let i = 0; i < vals.length; i++) {
17+
res = res + "`" + String(vals[i]) + "`";
18+
if (vals.length > 1 && i + 1 < vals.length) {
19+
res = res + ".";
20+
}
21+
}
22+
return res;
1523
}
1624
public static formatDateToString(date, separator = "", addtime = false) {
1725
// 01, 02, 03, ... 29, 30, 31
@@ -206,7 +214,9 @@ export default class BigQueryQuery {
206214
public buildMetricColumn() {
207215
if (this.hasMetricColumn()) {
208216
return (
209-
BigQueryQuery.quoteFiledName(this.target.metricColumn) + " AS metric"
217+
"CAST (" +
218+
BigQueryQuery.quoteFiledName(this.target.metricColumn) +
219+
"AS String ) AS metric"
210220
);
211221
}
212222

src/specs/bigquery_query.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ describe("BigQueryQuery", () => {
5353
const query = new BigQueryQuery({}, templateSrv);
5454
expect(query.buildMetricColumn()).toBe("");
5555
query.target.metricColumn = "host";
56-
expect(query.buildMetricColumn()).toBe("`host` AS metric");
56+
expect(query.buildMetricColumn()).toBe("CAST (`host`AS String ) AS metric");
5757
query.target.metricColumn = '"host"';
58-
expect(query.buildMetricColumn()).toBe( "`\"host\"` AS metric");
58+
expect(query.buildMetricColumn()).toBe( "CAST (`\"host\"`AS String ) AS metric");
5959
});
6060

6161
describe("When generating value column SQL", () => {
@@ -226,7 +226,7 @@ describe("BigQueryQuery", () => {
226226

227227
query.target.metricColumn = "m";
228228
result =
229-
"#standardSQL\nSELECT\n `t` AS time,\n `m` AS metric,\n `value`\nFROM `undefined.undefined.table`\nORDER BY 1,2";
229+
"#standardSQL\nSELECT\n `t` AS time,\n CAST (`m`AS String ) AS metric,\n `value`\nFROM `undefined.undefined.table`\nORDER BY 1,2";
230230
expect(query.buildQuery()).toBe(result);
231231
});
232232

0 commit comments

Comments
 (0)