[v9.5.x] InfluxDB: Fix adding FROM statement when the measurement is an empty string (#67835)

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

(cherry picked from commit 764f87b485)

Co-authored-by: ismail simsek <ismailsimsek09@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2023-05-04 16:29:05 +03:00
committed by GitHub
co-authored by ismail simsek
parent afa03930ec
commit aebf6e7fc1
2 changed files with 17 additions and 2 deletions
@@ -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');
});
});
});