mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 04:22:13 +08:00
refactor function handling in query builder
This commit is contained in:
@ -134,14 +134,21 @@ export default class PostgresQuery {
|
||||
let columnName = _.find(column, (g: any) => g.type === 'column');
|
||||
query = columnName.params[0];
|
||||
|
||||
let aggregate = _.find(column, (g: any) => g.type === 'aggregate');
|
||||
let aggregate = _.find(column, (g: any) => g.type === 'aggregate' || g.type === 'percentile');
|
||||
let special = _.find(column, (g: any) => g.type === 'window');
|
||||
|
||||
if (aggregate) {
|
||||
if (special) {
|
||||
query = aggregate.params[0] + '(' + query + ' ORDER BY ' + this.target.timeColumn + ')';
|
||||
} else {
|
||||
query = aggregate.params[0] + '(' + query + ')';
|
||||
switch (aggregate.type) {
|
||||
case 'aggregate':
|
||||
if (special) {
|
||||
query = aggregate.params[0] + '(' + query + ' ORDER BY ' + this.target.timeColumn + ')';
|
||||
} else {
|
||||
query = aggregate.params[0] + '(' + query + ')';
|
||||
}
|
||||
break;
|
||||
case 'percentile':
|
||||
query = aggregate.params[0] + '(' + aggregate.params[1] + ') WITHIN GROUP (ORDER BY ' + query + ')';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user