Skip to content

Commit

Permalink
read aggregate functions from database
Browse files Browse the repository at this point in the history
  • Loading branch information
svenklemm committed Mar 14, 2018
1 parent 0c3afd0 commit 46c2291
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion public/app/plugins/datasource/postgres/postgres_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ export default class PostgresQuery {
target.where = target.where || [];
target.select = target.select || [[{ type: 'column', params: ['value'] }]];

this.updateProjection();
// give interpolateQueryStr access to this
this.interpolateQueryStr = this.interpolateQueryStr.bind(this);

this.updateProjection();
}

quoteIdentifier(value) {
Expand Down
11 changes: 11 additions & 0 deletions public/app/plugins/datasource/postgres/query_ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,19 @@ export class PostgresQueryCtrl extends QueryCtrl {
});
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);

}

buildSelectMenu() {

if (!queryPart.hasAggregates()) {
this.datasource.metricFindQuery(this.queryBuilder.buildAggregateQuery())
.then(results => {
queryPart.clearAggregates();
_.map(results, segment => { queryPart.registerAggregate(segment.text); });
})
.catch(this.handleQueryError.bind(this));
}
var categories = queryPart.getCategories();
this.selectMenu = _.reduce(
categories,
Expand Down Expand Up @@ -279,6 +289,7 @@ export class PostgresQueryCtrl extends QueryCtrl {
var datatype = results[0].text;
switch (datatype) {
case "text":
case "character":
case "character varying":
return this.$q.when(this.uiSegmentSrv.newOperators(['=', '!=', '~', '~*','!~','!~*','IN']));
default:
Expand Down
17 changes: 17 additions & 0 deletions public/app/plugins/datasource/postgres/query_part.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ function register(options: any) {
options.category.push(index[options.type]);
}

function registerAggregate(name: string) {
register({
type: name,
addStrategy: replaceAggregationAddStrategy,
category: categories.Aggregations,
params: [],
defaultParams: [],
renderer: functionRenderer,
});
}

var groupByTimeFunctions = [];

function aliasRenderer(part, innerExpr) {
Expand Down Expand Up @@ -192,6 +203,12 @@ register({

export default {
create: createPart,
registerAggregate: registerAggregate,
clearAggregates: function() { categories.Aggregations = []; },
hasAggregates: function() {
// FIXME
return categories.Aggregations.length > 6;
},
getCategories: function() {
return categories;
},
Expand Down

0 comments on commit 46c2291

Please sign in to comment.