mirror of
https://github.com/grafana/grafana.git
synced 2024-11-23 01:16:31 -06:00
InfluxDB: Fix adding FROM statement when the measurement is an empty string (#67827)
* If the measurement empty don't add FROM statement * Add comment line
This commit is contained in:
parent
37378c4dd8
commit
764f87b485
@ -64,7 +64,8 @@ export class InfluxQueryBuilder {
|
||||
measurement = this.target.measurement;
|
||||
policy = this.target.policy;
|
||||
|
||||
if (!measurement.match('^/.*/')) {
|
||||
// If there is a measurement and it is not empty string
|
||||
if (!measurement.match(/^\/.*\/|^$/)) {
|
||||
measurement = '"' + measurement + '"';
|
||||
|
||||
if (policy && policy !== 'default') {
|
||||
@ -73,6 +74,10 @@ export class InfluxQueryBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
if (measurement === '') {
|
||||
return 'SHOW FIELD KEYS';
|
||||
}
|
||||
|
||||
return 'SHOW FIELD KEYS FROM ' + measurement;
|
||||
} else if (type === 'RETENTION POLICIES') {
|
||||
query = 'SHOW RETENTION POLICIES on "' + this.database + '"';
|
||||
@ -89,7 +94,9 @@ export class InfluxQueryBuilder {
|
||||
measurement = policy + '.' + measurement;
|
||||
}
|
||||
|
||||
query += ' FROM ' + measurement;
|
||||
if (measurement !== '') {
|
||||
query += ' FROM ' + measurement;
|
||||
}
|
||||
}
|
||||
|
||||
if (withKey) {
|
||||
|
@ -213,5 +213,13 @@ describe('InfluxQueryBuilder', () => {
|
||||
const query = builder.buildExploreQuery('TAG_KEYS');
|
||||
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == ''`);
|
||||
});
|
||||
|
||||
it('should not add FROM statement if the measurement empty', () => {
|
||||
const builder = new InfluxQueryBuilder({ measurement: '', tags: [] });
|
||||
let query = builder.buildExploreQuery('TAG_KEYS');
|
||||
expect(query).toBe('SHOW TAG KEYS');
|
||||
query = builder.buildExploreQuery('FIELDS');
|
||||
expect(query).toBe('SHOW FIELD KEYS');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user