mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 01:52:53 +08:00
Fix query builder queries for interval start
This changes the rate and increase queries to not calculate a value when there is no previous value. This also adds an order by metric column to prevent inconsistent series ordering in the legend.
This commit is contained in:
@ -72,7 +72,9 @@ describe('PostgresQuery', () => {
|
||||
{ type: 'window', params: ['increase'] },
|
||||
];
|
||||
expect(query.buildValueColumn(column)).toBe(
|
||||
'(CASE WHEN v >= lag(v) OVER (ORDER BY time) THEN v - lag(v) OVER (ORDER BY time) ELSE v END) AS "a"'
|
||||
'(CASE WHEN v >= lag(v) OVER (ORDER BY time) ' +
|
||||
'THEN v - lag(v) OVER (ORDER BY time) ' +
|
||||
'WHEN lag(v) OVER (ORDER BY time) IS NULL THEN NULL ELSE v END) AS "a"'
|
||||
);
|
||||
});
|
||||
|
||||
@ -96,7 +98,9 @@ describe('PostgresQuery', () => {
|
||||
{ type: 'window', params: ['increase'] },
|
||||
];
|
||||
expect(query.buildValueColumn(column)).toBe(
|
||||
'(CASE WHEN v >= lag(v) OVER (PARTITION BY host ORDER BY time) THEN v - lag(v) OVER (PARTITION BY host ORDER BY time) ELSE v END) AS "a"'
|
||||
'(CASE WHEN v >= lag(v) OVER (PARTITION BY host ORDER BY time) ' +
|
||||
'THEN v - lag(v) OVER (PARTITION BY host ORDER BY time) ' +
|
||||
'WHEN lag(v) OVER (PARTITION BY host ORDER BY time) IS NULL THEN NULL ELSE v END) AS "a"'
|
||||
);
|
||||
column = [
|
||||
{ type: 'column', params: ['v'] },
|
||||
@ -106,7 +110,8 @@ describe('PostgresQuery', () => {
|
||||
];
|
||||
expect(query.buildValueColumn(column)).toBe(
|
||||
'(CASE WHEN max(v) >= lag(max(v)) OVER (PARTITION BY host ORDER BY time) ' +
|
||||
'THEN max(v) - lag(max(v)) OVER (PARTITION BY host ORDER BY time) ELSE max(v) END) AS "a"'
|
||||
'THEN max(v) - lag(max(v)) OVER (PARTITION BY host ORDER BY time) ' +
|
||||
'WHEN lag(max(v)) OVER (PARTITION BY host ORDER BY time) IS NULL THEN NULL ELSE max(v) END) AS "a"'
|
||||
);
|
||||
});
|
||||
|
||||
@ -149,7 +154,7 @@ describe('PostgresQuery', () => {
|
||||
expect(query.buildQuery()).toBe(result);
|
||||
|
||||
query.target.metricColumn = 'm';
|
||||
result = 'SELECT\n t AS "time",\n m AS metric,\n value\nFROM table\nORDER BY 1';
|
||||
result = 'SELECT\n t AS "time",\n m AS metric,\n value\nFROM table\nORDER BY 1,2';
|
||||
expect(query.buildQuery()).toBe(result);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user