Druid Query in JSON
Druid 可以在 Superset SQL 查询,除此之外可以通过 HTTP+JSON 查询:
curl -X POST '<host:<port>/druid/v2/?pretty' -H 'Content-Type:application/json' -H 'Accept:application/json' -d @query.json
{
"queryType": "timeseries",
"dataSource": "cpm_log",
"granularity": "hour",
"aggregations": [
{
"type": "longSum",
"name": "requests",
"fieldName": "req_count_raw"
},
{
"type": "longSum",
"name": "impressions",
"fieldName": "win_count"
},
{
"type": "floatSum",
"name": "revenues",
"fieldName": "win_price"
}
],
"postAggregations": [
{
"type":"arithmetic",
"name": "ecpm",
"fn": "/",
"fields": [
{
"type": "fieldAccess",
"name": "postAgg_rev",
"fieldName": "revenues"
},
{
"type": "fieldAccess",
"name": "postAgg_imps",
"fieldName": "impressions"
}
]
}
],
"filter": {
"type": "and",
"fields": [
{
"type": "selector",
"dimension": "device_os",
"value": "android"
},
{
"type": "in",
"dimension": "req_ad_type",
"values": ["banner"]
}
]
},
"context": {
"grandTotal": true
},
"intervals": [
"2019-04-09T00:00:00+08:00/2019-04-09T23:00:00+08:00"
]
}
- queryType 有
timeseries
,topN
,groupBy
,search
,timeBoundary
等 - 尽量少用 groupBy 查询,效率不高
- topN 查询是通过
metric
来排序 context
可以指定queryId
,这样可以通过DELETE /druid/v2/{queryId}
取消查询- 去重:
{"type": "cardinality", "name": "distinct_pid", "fields": ["ad_pid"]}
Was this page helpful?