3
Druid Query in JSON
source link: https://fann.im/blog/2019/04/11/druid-query-in-json/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Druid Query in JSON
Apr 11, 2019
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?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK