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
48fc5edd
Commit
48fc5edd
authored
May 30, 2018
by
Kim Christensen
Committed by
Marcus Efraimsson
May 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support InfluxDB count distinct aggregation (#11658)
influxdb: support count distinct aggregation
parent
f32e3a29
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
175 additions
and
0 deletions
+175
-0
pkg/tsdb/influxdb/query_part_test.go
+8
-0
public/app/plugins/datasource/influxdb/query_part.ts
+23
-0
public/app/plugins/datasource/influxdb/specs/query_part.jest.ts
+144
-0
No files found.
pkg/tsdb/influxdb/query_part_test.go
View file @
48fc5edd
...
...
@@ -76,5 +76,13 @@ func TestInfluxdbQueryPart(t *testing.T) {
res
:=
part
.
Render
(
query
,
queryContext
,
"mean(value)"
)
So
(
res
,
ShouldEqual
,
`mean(value) AS "test"`
)
})
Convey
(
"render count distinct"
,
func
()
{
part
,
err
:=
NewQueryPart
(
"count"
,
[]
string
{})
So
(
err
,
ShouldBeNil
)
res
:=
part
.
Render
(
query
,
queryContext
,
"distinct(value)"
)
So
(
res
,
ShouldEqual
,
`count(distinct(value))`
)
})
})
}
public/app/plugins/datasource/influxdb/query_part.ts
View file @
48fc5edd
...
...
@@ -44,6 +44,28 @@ function replaceAggregationAddStrategy(selectParts, partModel) {
for
(
var
i
=
0
;
i
<
selectParts
.
length
;
i
++
)
{
var
part
=
selectParts
[
i
];
if
(
part
.
def
.
category
===
categories
.
Aggregations
)
{
if
(
part
.
def
.
type
===
partModel
.
def
.
type
)
{
return
;
}
// count distinct is allowed
if
(
part
.
def
.
type
===
'count'
&&
partModel
.
def
.
type
===
'distinct'
)
{
break
;
}
// remove next aggregation if distinct was replaced
if
(
part
.
def
.
type
===
'distinct'
)
{
var
morePartsAvailable
=
selectParts
.
length
>=
i
+
2
;
if
(
partModel
.
def
.
type
!==
'count'
&&
morePartsAvailable
)
{
var
nextPart
=
selectParts
[
i
+
1
];
if
(
nextPart
.
def
.
category
===
categories
.
Aggregations
)
{
selectParts
.
splice
(
i
+
1
,
1
);
}
}
else
if
(
partModel
.
def
.
type
===
'count'
)
{
if
(
!
morePartsAvailable
||
selectParts
[
i
+
1
].
def
.
type
!==
'count'
)
{
selectParts
.
splice
(
i
+
1
,
0
,
partModel
);
}
return
;
}
}
selectParts
[
i
]
=
partModel
;
return
;
}
...
...
@@ -434,4 +456,5 @@ export default {
getCategories
:
function
()
{
return
categories
;
},
replaceAggregationAdd
:
replaceAggregationAddStrategy
,
};
public/app/plugins/datasource/influxdb/specs/query_part.jest.ts
View file @
48fc5edd
...
...
@@ -40,5 +40,149 @@ describe('InfluxQueryPart', () => {
expect
(
part
.
text
).
toBe
(
'alias(test)'
);
expect
(
part
.
render
(
'mean(value)'
)).
toBe
(
'mean(value) AS "test"'
);
});
it
(
'should nest distinct when count is selected'
,
()
=>
{
var
selectParts
=
[
queryPart
.
create
({
type
:
'field'
,
category
:
queryPart
.
getCategories
().
Fields
,
}),
queryPart
.
create
({
type
:
'count'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
];
var
partModel
=
queryPart
.
create
({
type
:
'distinct'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
});
queryPart
.
replaceAggregationAdd
(
selectParts
,
partModel
);
expect
(
selectParts
[
1
].
text
).
toBe
(
'distinct()'
);
expect
(
selectParts
[
2
].
text
).
toBe
(
'count()'
);
});
it
(
'should convert to count distinct when distinct is selected and count added'
,
()
=>
{
var
selectParts
=
[
queryPart
.
create
({
type
:
'field'
,
category
:
queryPart
.
getCategories
().
Fields
,
}),
queryPart
.
create
({
type
:
'distinct'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
];
var
partModel
=
queryPart
.
create
({
type
:
'count'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
});
queryPart
.
replaceAggregationAdd
(
selectParts
,
partModel
);
expect
(
selectParts
[
1
].
text
).
toBe
(
'distinct()'
);
expect
(
selectParts
[
2
].
text
).
toBe
(
'count()'
);
});
it
(
'should replace count distinct if an aggregation is selected'
,
()
=>
{
var
selectParts
=
[
queryPart
.
create
({
type
:
'field'
,
category
:
queryPart
.
getCategories
().
Fields
,
}),
queryPart
.
create
({
type
:
'distinct'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
queryPart
.
create
({
type
:
'count'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
];
var
partModel
=
queryPart
.
create
({
type
:
'mean'
,
category
:
queryPart
.
getCategories
().
Selectors
,
});
queryPart
.
replaceAggregationAdd
(
selectParts
,
partModel
);
expect
(
selectParts
[
1
].
text
).
toBe
(
'mean()'
);
expect
(
selectParts
).
toHaveLength
(
2
);
});
it
(
'should not allowed nested counts when count distinct is selected'
,
()
=>
{
var
selectParts
=
[
queryPart
.
create
({
type
:
'field'
,
category
:
queryPart
.
getCategories
().
Fields
,
}),
queryPart
.
create
({
type
:
'distinct'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
queryPart
.
create
({
type
:
'count'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
];
var
partModel
=
queryPart
.
create
({
type
:
'count'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
});
queryPart
.
replaceAggregationAdd
(
selectParts
,
partModel
);
expect
(
selectParts
[
1
].
text
).
toBe
(
'distinct()'
);
expect
(
selectParts
[
2
].
text
).
toBe
(
'count()'
);
expect
(
selectParts
).
toHaveLength
(
3
);
});
it
(
'should not remove count distinct when distinct is added'
,
()
=>
{
var
selectParts
=
[
queryPart
.
create
({
type
:
'field'
,
category
:
queryPart
.
getCategories
().
Fields
,
}),
queryPart
.
create
({
type
:
'distinct'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
queryPart
.
create
({
type
:
'count'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
];
var
partModel
=
queryPart
.
create
({
type
:
'distinct'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
});
queryPart
.
replaceAggregationAdd
(
selectParts
,
partModel
);
expect
(
selectParts
[
1
].
text
).
toBe
(
'distinct()'
);
expect
(
selectParts
[
2
].
text
).
toBe
(
'count()'
);
expect
(
selectParts
).
toHaveLength
(
3
);
});
it
(
'should remove distinct when sum aggregation is selected'
,
()
=>
{
var
selectParts
=
[
queryPart
.
create
({
type
:
'field'
,
category
:
queryPart
.
getCategories
().
Fields
,
}),
queryPart
.
create
({
type
:
'distinct'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
}),
];
var
partModel
=
queryPart
.
create
({
type
:
'sum'
,
category
:
queryPart
.
getCategories
().
Aggregations
,
});
queryPart
.
replaceAggregationAdd
(
selectParts
,
partModel
);
expect
(
selectParts
[
1
].
text
).
toBe
(
'sum()'
);
});
});
});
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