Commit f231af07 by Clicky

Parse additional group by columns from a raw query

This needs some further polishing but now parse out additional group by
columns from a raw query, although it really only supports one
additional column.
parent 3da1c276
......@@ -17,7 +17,6 @@ function (angular, _, kbn) {
this.username = datasource.username;
this.password = datasource.password;
this.name = datasource.name;
this.templateSettings = {
interpolate : /\[\[([\s\S]+?)\]\]/g,
};
......@@ -33,6 +32,7 @@ function (angular, _, kbn) {
}
var timeFilter = getTimeFilter(options);
var additionalGroups = [];
if (target.rawQuery) {
query = target.query;
......@@ -43,6 +43,17 @@ function (angular, _, kbn) {
var groupByIndex = lowerCaseQueryElements.indexOf("group");
var orderIndex = lowerCaseQueryElements.indexOf("order");
var afterGroup = _.rest(lowerCaseQueryElements, groupByIndex);
for (var i = 0; i < afterGroup.length; i++) {
var el = afterGroup[i];
if (el === "order") break;
if ( /,$/.test(el) &&
_.size(afterGroup) > i &&
! /^time\(/.test(afterGroup[i + 1])) {
additionalGroups.push(queryElements[groupByIndex + i + 1]);
}
}
if (whereIndex !== -1) {
queryElements.splice(whereIndex+1, 0, timeFilter, "and");
}
......@@ -88,7 +99,7 @@ function (angular, _, kbn) {
target.query = query;
}
return this.doInfluxRequest(query, target.alias).then(handleInfluxQueryResponse);
return this.doInfluxRequest(query, target.alias).then(handleInfluxQueryResponse(additionalGroups));
}, this);
......@@ -157,21 +168,25 @@ function (angular, _, kbn) {
return deferred.promise;
};
function handleInfluxQueryResponse(data) {
function handleInfluxQueryResponse(additionalGroup) {
return function(data) {
var output = [];
_.each(data, function(series) {
var timeCol = series.columns.indexOf('time');
var groupByColumn = series.columns.indexOf('host');
var groupCols = _.map(additionalGroup, function(col) {
return series.columns.indexOf(col);
});
var groupByColumn = _.find(groupCols, function(col) { return col > -1; });
_.each(series.columns, function(column, index) {
if (column === "time" || column === "sequence_number" || column === "host") {
if (column === "time" || column === "sequence_number" || _.contains(additionalGroup, column)) {
return;
}
var target = data.alias || series.name + "." + column;
var datapoints = _.groupBy(series.points, function (point) {
if (groupByColumn == -1 ) return null;
if (groupByColumn == undefined) return null;
else return point[groupByColumn];
});
datapoints = _.map(_.pairs(datapoints), function(values) {
......@@ -190,6 +205,7 @@ function (angular, _, kbn) {
return output;
}
}
function getTimeFilter(options) {
var from = getInfluxTime(options.range.from);
......
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