Commit 52177a45 by Torkel Ödegaard

influxdb: use paranthesis for influxdb queries in frontend query builder, #9131

parent bdfbc245
......@@ -229,8 +229,11 @@ export default class InfluxQuery {
return this.renderTagCondition(tag, index, interpolate);
});
query += conditions.join(' ');
query += (conditions.length > 0 ? ' AND ' : '') + '$timeFilter';
if (conditions.length > 0) {
query += '(' + conditions.join(' ') + ') AND ';
}
query += '$timeFilter';
var groupBySection = "";
for (i = 0; i < this.groupByParts.length; i++) {
......
......@@ -57,7 +57,7 @@ describe('InfluxQuery', function() {
var queryText = query.render();
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE "hostname" = \'server\\\\1\' AND $timeFilter'
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE ("hostname" = \'server\\\\1\') AND $timeFilter'
+ ' GROUP BY time($__interval)');
});
......@@ -69,7 +69,7 @@ describe('InfluxQuery', function() {
}, templateSrv, {});
var queryText = query.render();
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE "app" =~ /e.*/ AND $timeFilter GROUP BY time($__interval)');
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE ("app" =~ /e.*/) AND $timeFilter GROUP BY time($__interval)');
});
});
......@@ -82,7 +82,7 @@ describe('InfluxQuery', function() {
}, templateSrv, {});
var queryText = query.render();
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE "hostname" = \'server1\' AND "app" = \'email\' AND ' +
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE ("hostname" = \'server1\' AND "app" = \'email\') AND ' +
'$timeFilter GROUP BY time($__interval)');
});
});
......@@ -96,7 +96,7 @@ describe('InfluxQuery', function() {
}, templateSrv, {});
var queryText = query.render();
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE "hostname" = \'server1\' OR "hostname" = \'server2\' AND ' +
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE ("hostname" = \'server1\' OR "hostname" = \'server2\') AND ' +
'$timeFilter GROUP BY time($__interval)');
});
});
......@@ -110,7 +110,7 @@ describe('InfluxQuery', function() {
}, templateSrv, {});
var queryText = query.render();
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE "value" > 5 AND $timeFilter');
expect(queryText).to.be('SELECT mean("value") FROM "cpu" WHERE ("value" > 5) AND $timeFilter');
});
});
......
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