Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
3fe3f374
Unverified
Commit
3fe3f374
authored
Sep 10, 2018
by
Marcus Efraimsson
Committed by
GitHub
Sep 10, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13200 from svenklemm/postgres-query-builder-fixes
Fix query builder queries for interval start
parents
227bf85e
116fb505
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
6 deletions
+16
-6
public/app/plugins/datasource/postgres/postgres_query.ts
+7
-2
public/app/plugins/datasource/postgres/specs/postgres_query.test.ts
+9
-4
No files found.
public/app/plugins/datasource/postgres/postgres_query.ts
View file @
3fe3f374
...
...
@@ -187,7 +187,8 @@ export default class PostgresQuery {
case
'increase'
:
curr
=
query
;
prev
=
'lag('
+
curr
+
') OVER ('
+
over
+
')'
;
query
=
'(CASE WHEN '
+
curr
+
' >= '
+
prev
+
' THEN '
+
curr
+
' - '
+
prev
+
' ELSE '
+
curr
+
' END)'
;
query
=
'(CASE WHEN '
+
curr
+
' >= '
+
prev
+
' THEN '
+
curr
+
' - '
+
prev
;
query
+=
' WHEN '
+
prev
+
' IS NULL THEN NULL ELSE '
+
curr
+
' END)'
;
break
;
case
'rate'
:
let
timeColumn
=
this
.
target
.
timeColumn
;
...
...
@@ -197,7 +198,8 @@ export default class PostgresQuery {
curr
=
query
;
prev
=
'lag('
+
curr
+
') OVER ('
+
over
+
')'
;
query
=
'(CASE WHEN '
+
curr
+
' >= '
+
prev
+
' THEN '
+
curr
+
' - '
+
prev
+
' ELSE '
+
curr
+
' END)'
;
query
=
'(CASE WHEN '
+
curr
+
' >= '
+
prev
+
' THEN '
+
curr
+
' - '
+
prev
;
query
+=
' WHEN '
+
prev
+
' IS NULL THEN NULL ELSE '
+
curr
+
' END)'
;
query
+=
'/extract(epoch from '
+
timeColumn
+
' - lag('
+
timeColumn
+
') OVER ('
+
over
+
'))'
;
break
;
default
:
...
...
@@ -279,6 +281,9 @@ export default class PostgresQuery {
query
+=
this
.
buildGroupClause
();
query
+=
'
\
nORDER BY 1'
;
if
(
this
.
hasMetricColumn
())
{
query
+=
',2'
;
}
return
query
;
}
...
...
public/app/plugins/datasource/postgres/specs/postgres_query.test.ts
View file @
3fe3f374
...
...
@@ -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
);
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment