set explicit order for rate and increase

This commit is contained in:
Sven Klemm
2018-07-22 15:06:59 +02:00
parent 84d7743939
commit 7af9cd7dfc
2 changed files with 11 additions and 3 deletions

View File

@ -136,16 +136,24 @@ export default class PostgresQuery {
query = columnName.params[0];
let aggregate = _.find(column, (g: any) => g.type === 'aggregate');
let special = _.find(column, (g: any) => g.type === 'special');
if (aggregate) {
query = aggregate.params[0] + '(' + query + ')';
if (special) {
query = aggregate.params[0] + '(' + query + ' ORDER BY ' + this.target.timeColumn + ')';
} else {
query = aggregate.params[0] + '(' + query + ')';
}
}
let special = _.find(column, (g: any) => g.type === 'special');
if (special) {
let over = '';
if (this.hasMetricColumn()) {
over = 'PARTITION BY ' + this.target.metricColumn;
}
if (!aggregate) {
over += 'ORDER BY ' + this.target.timeColumn;
}
switch (special.params[0]) {
case 'increase':
query = query + ' - lag(' + query + ') OVER (' + over + ')';