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:
ismail simsek 2023-05-04 16:21:08 +03:00 committed by GitHub
parent 37378c4dd8
commit 764f87b485
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -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) {

View File

@ -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');
});
});
});