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

Commit 3bad7cc

Browse files
authored
Merge pull request #160 from doitintl/issue-153
Solves #153
2 parents 744e7d4 + e15bd64 commit 3bad7cc

File tree

5 files changed

+19
-126
lines changed

5 files changed

+19
-126
lines changed

dist/module.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59479,7 +59479,6 @@ function () {
5947959479
q = _this._updateAlias(q, modOptions, query.refId);
5948059480
}
5948159481

59482-
console.log(q);
5948359482
var limit = q.match(/[^]+(\bLIMIT\b)/gi);
5948459483

5948559484
if (limit == null) {
@@ -59786,12 +59785,15 @@ function () {
5978659785
});
5978759786
}
5978859787

59788+
var rawSql = this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable);
5978959789
var query = {
5979059790
datasourceId: this.id,
5979159791
format: "table",
59792-
rawSql: this.templateSrv.replace(options.annotation.rawQuery, options.scopedVars, this.interpolateVariable),
59792+
rawSql: rawSql,
5979359793
refId: options.annotation.name
5979459794
};
59795+
this.queryModel.target.rawSql = query.rawSql;
59796+
query.rawSql = this.queryModel.expend_macros(options);
5979559797
return this.backendSrv.datasourceRequest({
5979659798
data: {
5979759799
query: query.rawSql,
@@ -61447,9 +61449,9 @@ function () {
6144761449
var row = _a[_i];
6144861450
list.push({
6144961451
annotation: options.annotation,
61450-
tags: row[tagsColumnIndex] ? row[tagsColumnIndex].trim().split(/\s*,\s*/) : [],
61452+
tags: row.f[tagsColumnIndex].v ? row.f[tagsColumnIndex].v.trim().split(/\s*,\s*/) : [],
6145161453
text: row.f[textColumnIndex],
61452-
time: new Date(Number(Math.floor(Number(row.f[timeColumnIndex].v))) * 1000).toString(),
61454+
time: Number(Math.floor(Number(row.f[timeColumnIndex].v))) * 1000,
6145361455
title: row.f[titleColumnIndex]
6145461456
});
6145561457
}

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/datasource.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ export class BigQueryDatasource {
236236
if (query.refId.search(Shifted) > -1) {
237237
q = this._updateAlias(q, modOptions, query.refId);
238238
}
239-
console.log(q)
240239
const limit = q.match(/[^]+(\bLIMIT\b)/gi);
241240
if (limit == null) {
242241
q += " LIMIT " + options.maxDataPoints;
@@ -396,17 +395,20 @@ export class BigQueryDatasource {
396395
message: "Query missing in annotation definition"
397396
});
398397
}
398+
const rawSql = this.templateSrv.replace(
399+
options.annotation.rawQuery,
400+
options.scopedVars,
401+
this.interpolateVariable
402+
);
399403

400404
const query = {
401405
datasourceId: this.id,
402406
format: "table",
403-
rawSql: this.templateSrv.replace(
404-
options.annotation.rawQuery,
405-
options.scopedVars,
406-
this.interpolateVariable
407-
),
407+
rawSql,
408408
refId: options.annotation.name
409409
};
410+
this.queryModel.target.rawSql = query.rawSql;
411+
query.rawSql = this.queryModel.expend_macros(options);
410412
return this.backendSrv
411413
.datasourceRequest({
412414
data: {
@@ -418,7 +420,7 @@ export class BigQueryDatasource {
418420
},
419421
method: "POST",
420422
requestId: options.annotation.name,
421-
url: url
423+
url
422424
})
423425
.then(data =>
424426
this.responseParser.transformAnnotationResponse(options, data)

src/response_parser.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ export default class ResponseParser {
260260
const titleColumnIndex = -1;
261261
let textColumnIndex = -1;
262262
let tagsColumnIndex = -1;
263-
264263
for (let i = 0; i < data.data.schema.fields.length; i++) {
265264
if (data.data.schema.fields[i].name === "time") {
266265
timeColumnIndex = i;
@@ -279,19 +278,16 @@ export default class ResponseParser {
279278
for (const row of table.rows) {
280279
list.push({
281280
annotation: options.annotation,
282-
tags: row[tagsColumnIndex]
283-
? row[tagsColumnIndex].trim().split(/\s*,\s*/)
281+
tags: row.f[tagsColumnIndex].v
282+
? row.f[tagsColumnIndex].v.trim().split(/\s*,\s*/)
284283
: [],
285284
text: row.f[textColumnIndex],
286-
time: new Date(
287-
Number(Math.floor(Number(row.f[timeColumnIndex].v))) * 1000
288-
).toString(),
285+
time: Number(Math.floor(Number(row.f[timeColumnIndex].v))) * 1000,
289286
title: row.f[titleColumnIndex]
290287
});
291288
}
292289
return list;
293290
}
294-
295291
private _handelWildCardTables(tables) {
296292
let sorted = new Map();
297293
let newTables = [];

src/specs/datasource.test.ts

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -358,113 +358,6 @@ describe("BigQueryDatasource", () => {
358358
expect(results.length).toBe(6);
359359
});
360360
});
361-
362-
describe("When performing annotationQuery", () => {
363-
let results;
364-
365-
const annotationName = "MyAnno";
366-
367-
const options = {
368-
annotation: {
369-
name: annotationName,
370-
rawQuery: "select time, title, text, tags from table;"
371-
},
372-
range: {
373-
from: moment(1432288354),
374-
to: moment(1432288401)
375-
}
376-
};
377-
const response = {
378-
kind: "bigquery#queryResponse",
379-
schema: {
380-
fields: [
381-
{
382-
name: "time",
383-
type: "TIMESTAMP",
384-
mode: "NULLABLE"
385-
},
386-
{
387-
name: "text",
388-
type: "text",
389-
mode: "NULLABLE"
390-
}
391-
]
392-
},
393-
jobReference: {
394-
projectId: "aviv-playground",
395-
jobId: "job_fB4qCDAO-TKg1Orc-OrkdIRxCGN5",
396-
location: "US"
397-
},
398-
totalRows: "3",
399-
rows: [
400-
{
401-
f: [
402-
{
403-
v: "1.521578851E9"
404-
},
405-
{
406-
v: "some text"
407-
}
408-
]
409-
},
410-
{
411-
f: [
412-
{
413-
v: "1.521578916E9"
414-
},
415-
{
416-
v: "some text2"
417-
}
418-
]
419-
},
420-
{
421-
f: [
422-
{
423-
v: "1.521578927E9"
424-
},
425-
{
426-
v: "some text3"
427-
}
428-
]
429-
}
430-
],
431-
totalBytesProcessed: "23289520",
432-
jobComplete: true,
433-
cacheHit: false
434-
};
435-
/* const response = {
436-
results: {
437-
MyAnno: {
438-
refId: annotationName,
439-
data: [
440-
{
441-
columns: [{ text: "time" }, { text: "text" }, { text: "tags" }],
442-
rows: [
443-
[1432288355, "some text", "TagA,TagB"],
444-
[1432288390, "some text2", " TagB , TagC"],
445-
[1432288400, "some text3"]
446-
]
447-
}
448-
]
449-
}
450-
}
451-
};*/
452-
453-
beforeEach(() => {
454-
ctx.backendSrv.datasourceRequest = jest.fn(options => {
455-
return Promise.resolve({ data: response, status: 200 });
456-
});
457-
ctx.ds.annotationQuery(options).then(data => {
458-
results = data;
459-
});
460-
});
461-
it("should return annotation list", () => {
462-
expect(results.length).toBe(3);
463-
464-
expect(results[0].text.v).toBe("some text");
465-
});
466-
});
467-
468361
describe("When performing getProjects", () => {
469362
let queryResults;
470363
const response = {

0 commit comments

Comments
 (0)