"upper": "US" ,
"ordering": "numeric",
"upperStrict": true,
"ordering": "lexicographic"
},
"resultFormat": "list",
"columns": [
"page",
"countryName",
"cityName",
"countryIsoCode"
],
"intervals": [
"2016-06-27/2016-06-28"
],
"limit": 5
}
Aggregations
Count aggregator
1
2
3
4
5
6
7
8
select
page,
count(*) as num
from wikipedia3
where "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-28 00:00:00'
group by page
order by num desc
limit 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"queryType": "topN",
"dataSource": "wikipedia3",
"dimension": "page",
"threshold": 5,
"metric": "num",
"granularity": "all",
"aggregations": [
{
"type": "count",
"name": "num"
}
],
"intervals": [
"2016-06-27/2016-06-28"
]
}
Sum aggregators
longSum、doubleSum、floatSum
1
2
3
4
5
6
7
8
select
page,
sum(delta) as num
from wikipedia3
where "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-28 00:00:00'
group by page
order by page asc
limit 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"queryType": "topN",
"dataSource": "wikipedia3",
"dimension": "page",
"threshold": 5,
"metric": "num",
"granularity": "all",
"aggregations": [
{
"type": "longSum",
"name": "num",
"fieldName" : "delta"
}
],
"intervals": [
"2016-06-27/2016-06-28"
]
}
Min / Max aggregators
图片描述(最多50字)
doubleMin、doubleMax、floatMin、floatMax、longMin、longMax
1
2
3
4
5
6
7
8
select
page,
max(delta) as num
from wikipedia3
where "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-28 00:00:00'
group by page
order by page asc
limit 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
{
"queryType": "topN",
"dataSource": "wikipedia3",
"dimension": "page",
"threshold": 5,
"metric": "num",
"granularity": "all",
"aggregations": [
{
"type": "longMax",
"name": "num",
"fieldName" : "delta"
}
],
"intervals": [
"2016-06-27/2016-06-28"
]
}
First / Last aggregator
不能在数据摄入的时候使用,只能用于查询
Last:最大时间戳对应的数据,0 if no row exist;First最小时间戳对应的数据,0 if no row exist
JavaScript aggregator
Post Aggregations
对Aggregations的结果进行二次加工并输出,最终的结果既包含Aggregations的结果也包含Post Aggregations的结果
2. Timeseries
统计一段时间内的汇总数据
1
2
3
4
SELECT count(*) as num,
sum(added)
FROM wikipedia
WHERE "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-27 23:59:59'
1
2
3
4
5
6
7
8
9
10
{
"queryType": "timeseries",
"dataSource": "wikipedia3",
"granularity": "all",
"aggregations": [
{ "type": "count", "name": "count" },
{ "type": "longSum", "name": "added", "fieldName": "added" }
],
"intervals": [ "2016-06-27/2016-06-28" ]
}
3. TopN
返回前N条数据,并可以按照metric排序,可以支持维度,但只有一个,不能多个
1
2
3
4
5
6
7
8
SELECT
page,
sum(added) as num
FROM wikipedia
WHERE "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-27 23:59:59'
group by page
order by num desc
limit 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"queryType": "topN",
"dataSource": "wikipedia3",
"dimension": "page",
"threshold": 5,
"metric": "added",
"granularity": "all",
"aggregations": [
{
"type": "doubleSum",
"name": "added",
"fieldName": "added"
}
],
"intervals": [ "2016-06-27/2016-06-28" ]
}
4. GroupBy
能对指定的多个维度分组,也支持对指定的维度排序,也支持limit,但是性能比TopN和Timeseries要差很多
1
2
3
4
5
6
7
8
9
10
SELECT
page,
countryName,
sum(added) as num,
sum(delta) as num2
FROM wikipedia
WHERE "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-27 23:59:59'
group by page,countryName
order by num desc
limit 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
{
"queryType": "groupBy",
"dataSource": "wikipedia3",
"granularity": "all",
"dimensions": [
"page",
"countryName"
],
"limitSpec": {
"type": "default",
"limit": 5,
"columns": [
{
"dimension": "added",
"direction": "descending",
"dimensionOrder": {
"type": "numeric"
}
}
]
},
"aggregations": [
{
"type": "longSum",
"name": "added",
"fieldName": "added"
},
{
"type": "longSum",
"name": "delta",
"fieldName": "delta"
}
],
"intervals": [
"2016-06-27/2016-06-28"
]
}
5. Search
图片描述(最多50字)
类似于like操作,可以查询多个维度列,不支持聚合
1
2
3
4
5
6
7
SELECT
page,
countryName
FROM wikipedia
WHERE "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-27 23:59:59'
and page like '%C' or countryName like '%C'
limit 5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"queryType": "search",
"dataSource": "wikipedia3",
"granularity": "all",
"dimensions": [
"page",
"countryName"
],
"query": {
"type": "insensitive_contains",
"value": "C"
},
"sort" : {
"type": "lexicographic"
},
"limit": 5,
"intervals": [
"2016-06-27/2016-06-28"
]
}
6. Select
查数据,不支持聚合,但支持分页,排序,相比来说还是不错了
1
2
3
4
5
SELECT
*
FROM wikipedia
WHERE "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-27 23:59:59'
limit 0,5
1
2
3
4
5
6
7
8
9
10
11
{
"queryType": "select",
"dataSource": "wikipedia3",
"granularity": "all",
"dimensions":[],
"metrics":[],
"pagingSpec":{"pagingIdentifiers": {}, "threshold":5},
"intervals": [
"2016-06-27/2016-06-28"
]
}
7. Scan
类似于Select,但不支持分页,但是如果没有分页需求,推荐使用这个,性能比Select好,所以不要选错了。
1
2
3
4
5
SELECT
page,countryName
FROM wikipedia
WHERE "__time" BETWEEN TIMESTAMP '2016-06-27 00:00:00' AND TIMESTAMP '2016-06-27 23:59:59'
limit 5
1
2
3
4
5
6
7
8
9
10
11
{
"queryType": "scan",
"dataSource": "wikipedia3",
"resultFormat": "list",
"columns":["page","countryName"],
"intervals": [
"2016-06-27/2016-06-28"
],
"batchSize":20480,
"limit":5
}
觉得文章不错的同学可以关注我,有学习福利也会提供给大家。