mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: InfluxQL: handle empty tag values when generating query (#34463)
This commit is contained in:
@@ -17,8 +17,8 @@ function renderTagCondition(tag: { operator: any; value: string; condition: any;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// quote value unless regex or number
|
// quote value unless regex or number, or if empty-string
|
||||||
if (operator !== '=~' && operator !== '!~' && isNaN(+value)) {
|
if (value === '' || (operator !== '=~' && operator !== '!~' && isNaN(+value))) {
|
||||||
value = "'" + value + "'";
|
value = "'" + value + "'";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,5 +159,41 @@ describe('InfluxQueryBuilder', () => {
|
|||||||
const query = builder.buildExploreQuery('RETENTION POLICIES');
|
const query = builder.buildExploreQuery('RETENTION POLICIES');
|
||||||
expect(query).toBe('SHOW RETENTION POLICIES on "site"');
|
expect(query).toBe('SHOW RETENTION POLICIES on "site"');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should handle tag-value=number-ish when getting measurements', () => {
|
||||||
|
const builder = new InfluxQueryBuilder(
|
||||||
|
{ measurement: undefined, tags: [{ key: 'app', value: '42', operator: '==' }] },
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
const query = builder.buildExploreQuery('MEASUREMENTS');
|
||||||
|
expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == 42 LIMIT 100`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle tag-value=number-ish getting tag-keys', () => {
|
||||||
|
const builder = new InfluxQueryBuilder(
|
||||||
|
{ measurement: undefined, tags: [{ key: 'app', value: '42', operator: '==' }] },
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
const query = builder.buildExploreQuery('TAG_KEYS');
|
||||||
|
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == 42`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle tag-value=emptry-string when getting measurements', () => {
|
||||||
|
const builder = new InfluxQueryBuilder(
|
||||||
|
{ measurement: undefined, tags: [{ key: 'app', value: '', operator: '==' }] },
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
const query = builder.buildExploreQuery('MEASUREMENTS');
|
||||||
|
expect(query).toBe(`SHOW MEASUREMENTS WHERE "app" == '' LIMIT 100`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle tag-value=emptry-string when getting tag-keys', () => {
|
||||||
|
const builder = new InfluxQueryBuilder(
|
||||||
|
{ measurement: undefined, tags: [{ key: 'app', value: '', operator: '==' }] },
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
const query = builder.buildExploreQuery('TAG_KEYS');
|
||||||
|
expect(query).toBe(`SHOW TAG KEYS WHERE "app" == ''`);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user