Commit 209f2deb by Omkar Wagh

If retention policy is set for influxDB, preprend that to the measurement name

for exploration queries.
parent 68829a82
......@@ -42,13 +42,16 @@ function (_) {
p.buildExploreQuery = function(type, withKey, withMeasurementFilter) {
var query;
var measurement;
var policy;
if (type === 'TAG_KEYS') {
query = 'SHOW TAG KEYS';
measurement = this.target.measurement;
policy = this.target.policy;
} else if (type === 'TAG_VALUES') {
query = 'SHOW TAG VALUES';
measurement = this.target.measurement;
policy = this.target.policy;
} else if (type === 'MEASUREMENTS') {
query = 'SHOW MEASUREMENTS';
if (withMeasurementFilter)
......@@ -56,11 +59,18 @@ function (_) {
query += ' WITH MEASUREMENT =~ /' + withMeasurementFilter +'/';
}
} else if (type === 'FIELDS') {
if (!this.target.measurement.match('^/.*/')) {
return 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"';
} else {
return 'SHOW FIELD KEYS FROM ' + this.target.measurement;
measurement = this.target.measurement;
policy = this.target.policy;
if (!measurement.match('^/.*/')) {
measurement = '"' + measurement + '"';
if (policy) {
if (!policy.match('^/.*/')) {
policy = '"' + policy + '"';
}
measurement = policy + '.' + measurement;
}
}
return 'SHOW FIELD KEYS FROM ' + measurement;
} else if (type === 'RETENTION POLICIES') {
query = 'SHOW RETENTION POLICIES on "' + this.database + '"';
return query;
......@@ -70,6 +80,12 @@ function (_) {
if (!measurement.match('^/.*/') && !measurement.match(/^merge\(.*\)/)) {
measurement = '"' + measurement+ '"';
}
if (policy) {
if (!policy.match('^/.*/') && !policy.match(/^merge\(.*\)/)) {
policy = '"' + policy + '"';
}
measurement = policy + '.' + measurement;
}
query += ' FROM ' + measurement;
}
......
......@@ -73,6 +73,17 @@ describe('InfluxQueryBuilder', function() {
expect(query).to.be('SHOW TAG VALUES FROM "cpu" WITH KEY = "app" WHERE "host" = \'server1\'');
});
it ('should select from policy correctly if policy is specified', function() {
var builder = new InfluxQueryBuilder({
measurement: 'cpu',
policy: 'one_week',
tags: [{key: 'app', value: 'email'},
{key: 'host', value: 'server1'}]
});
var query = builder.buildExploreQuery('TAG_VALUES', 'app');
expect(query).to.be('SHOW TAG VALUES FROM "one_week"."cpu" WITH KEY = "app" WHERE "host" = \'server1\'');
});
it('should switch to regex operator in tag condition', function() {
var builder = new InfluxQueryBuilder({
measurement: 'cpu',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment