mirror of
https://github.com/grafana/grafana.git
synced 2025-09-29 08:44:39 +08:00
set explicit order for rate and increase
This commit is contained in:
@ -136,16 +136,24 @@ export default class PostgresQuery {
|
|||||||
query = columnName.params[0];
|
query = columnName.params[0];
|
||||||
|
|
||||||
let aggregate = _.find(column, (g: any) => g.type === 'aggregate');
|
let aggregate = _.find(column, (g: any) => g.type === 'aggregate');
|
||||||
|
let special = _.find(column, (g: any) => g.type === 'special');
|
||||||
|
|
||||||
if (aggregate) {
|
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) {
|
if (special) {
|
||||||
let over = '';
|
let over = '';
|
||||||
if (this.hasMetricColumn()) {
|
if (this.hasMetricColumn()) {
|
||||||
over = 'PARTITION BY ' + this.target.metricColumn;
|
over = 'PARTITION BY ' + this.target.metricColumn;
|
||||||
}
|
}
|
||||||
|
if (!aggregate) {
|
||||||
|
over += 'ORDER BY ' + this.target.timeColumn;
|
||||||
|
}
|
||||||
switch (special.params[0]) {
|
switch (special.params[0]) {
|
||||||
case 'increase':
|
case 'increase':
|
||||||
query = query + ' - lag(' + query + ') OVER (' + over + ')';
|
query = query + ' - lag(' + query + ') OVER (' + over + ')';
|
||||||
|
@ -63,7 +63,7 @@ describe('PostgresQuery', function() {
|
|||||||
{ type: 'alias', params: ['a'] },
|
{ type: 'alias', params: ['a'] },
|
||||||
{ type: 'special', params: ['increase'] },
|
{ type: 'special', params: ['increase'] },
|
||||||
];
|
];
|
||||||
expect(query.buildValueColumn(column)).toBe('v - lag(v) OVER () AS "a"');
|
expect(query.buildValueColumn(column)).toBe('v - lag(v) OVER (ORDER BY time) AS "a"');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When generating WHERE clause', function() {
|
describe('When generating WHERE clause', function() {
|
||||||
|
Reference in New Issue
Block a user