资讯专栏INFORMATION COLUMN

大数据分析druid实现双维度的topn查询

luzhuqun / 2235人阅读

摘要:前言支持三种数据查询类型。,,是无维度,支持单维度,支持双维度。现在有一个需求基于服务名和调用链的两个维度,从获取最大分位数的前五名数据。但是没有排序查看官方文档的查询格式。官网上明确标识可以通过实现查询。其中可以限制返回数量。

前言

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...


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

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/76643.html

相关文章

  • 数据分析druid数据实时统计分析数据存储)

    摘要:俗名德鲁伊是一个为在大数据集之上做实时统计分析而设计的开源数据存储。下文都以德鲁伊代表为什么创建德鲁伊在最近几年,互联网技术的快速增长已经产生了大量由机器产生的数据。通过请求访问数据库 什么是druid 与某连接池同名,但完全是两个东西。Druid(俗名德鲁伊)是一个为在大数据集之上做实时统计分析而设计的开源数据存储。这个系统集合了一个面向列存储的层,一个分布式、shared-noth...

    felix0913 评论0 收藏0

发表评论

0条评论

luzhuqun

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<