前言

druid支持三种数据查询类型。timeseries,topn,groupby
timeseries是无维度,topn支持单维度,groupby支持双维度。现在有一个需求:基于服务名和调用链的两个维度,从druid获取最大分位数的前五名数据。topn是单维度的。groupby是双维度的。但是没有排序

查看官方文档

groupby的查询格式。官网上明确标识可以通过groupby实现topn查询。

{
  "queryType": "groupBy",
  "dataSource": "sample_datasource",
  "granularity": "day",
  "dimensions": ["country", "device"],
  "limitSpec": { "type": "default", "limit": 5000, "columns": ["country", "data_transfer"] },
  "filter": {
    "type": "and",
    "fields": [
      { "type": "selector", "dimension": "carrier", "value": "AT&T" },
      { "type": "or", 
        "fields": [
          { "type": "selector", "dimension": "make", "value": "Apple" },
          { "type": "selector", "dimension": "make", "value": "Samsung" }
        ]
      }
    ]
  },
  "aggregations": [
    { "type": "longSum", "name": "total_usage", "fieldName": "user_count" },
    { "type": "doubleSum", "name": "data_transfer", "fieldName": "data_transfer" }
  ],
  "postAggregations": [
    { "type": "arithmetic",
      "name": "avg_usage",
      "fn": "/",
      "fields": [
        { "type": "fieldAccess", "fieldName": "data_transfer" },
        { "type": "fieldAccess", "fieldName": "total_usage" }
      ]
    }
  ],
  "intervals": [ "2012-01-01T00:00:00.000/2012-01-03T00:00:00.000" ],
  "having": {
    "type": "greaterThan",
    "aggregation": "total_usage",
    "value": 100
  }
}

其中limitspec可以限制返回数量。但是没有说可以排序。真的无语
点击查看limitspec的详情http://druid.io/docs/0.12.1/q...

clipboard.png
官方文档还是写的很详细的,多看官方文档有益身心。


木木甫
494 声望23 粉丝

已工作的应届生。希望能和大家多多交流技术问题,