InfluxDB: auto escape column names with special characters, Closes #1296

This commit is contained in:
Torkel Ödegaard 2015-01-06 13:26:09 +01:00
parent 47e4b77140
commit d4c3463f68
3 changed files with 12 additions and 17 deletions

View File

@ -2,6 +2,7 @@
**Enhancements** **Enhancements**
- [Issue #1297](https://github.com/grafana/grafana/issues/1297). Graphite: Added cumulative and minimumBelow graphite functions - [Issue #1297](https://github.com/grafana/grafana/issues/1297). Graphite: Added cumulative and minimumBelow graphite functions
- [Issue #1296](https://github.com/grafana/grafana/issues/1296). InfluxDB: Auto escape column names with special characters. Thanks @steven-aerts
# 1.9.1 (2014-12-29) # 1.9.1 (2014-12-29)

View File

@ -74,16 +74,19 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
}; };
InfluxDatasource.prototype.listColumns = function(seriesName) { InfluxDatasource.prototype.listColumns = function(seriesName) {
var interpolated = templateSrv.replace(seriesName); seriesName = templateSrv.replace(seriesName);
if (interpolated[0] !== '/') {
interpolated = '/' + interpolated + '/'; if(!seriesName.match('^/.*/') && !seriesName.match(/^merge\(.*\)/)) {
seriesName = '"' + seriesName+ '"';
} }
return this._seriesQuery('select * from ' + interpolated + ' limit 1').then(function(data) { return this._seriesQuery('select * from ' + seriesName + ' limit 1').then(function(data) {
if (!data) { if (!data) {
return []; return [];
} }
return data[0].columns; return data[0].columns.map(function(item) {
return /^\w+$/.test(item) ? item : ('"' + item + '"');
});
}); });
}; };
@ -97,17 +100,9 @@ function (angular, _, kbn, InfluxSeries, InfluxQueryBuilder) {
if (!data || data.length === 0) { if (!data || data.length === 0) {
return []; return [];
} }
// influxdb >= 1.8 return _.map(data[0].points, function(point) {
if (data[0].points.length > 0) { return point[1];
return _.map(data[0].points, function(point) { });
return point[1];
});
}
else { // influxdb <= 1.7
return _.map(data, function(series) {
return series.name; // influxdb < 1.7
});
}
}); });
}; };

View File

@ -88,7 +88,6 @@ function (angular, _) {
seriesList = []; seriesList = [];
$scope.datasource.listSeries(query).then(function(series) { $scope.datasource.listSeries(query).then(function(series) {
seriesList = series; seriesList = series;
console.log(series);
callback(seriesList); callback(seriesList);
}); });
} }