Skip to content

Instantly share code, notes, and snippets.

@zhuqling
Last active October 23, 2018 01:34
Show Gist options
  • Save zhuqling/f49a18a079e2f7db705f2a8e8b8d02e0 to your computer and use it in GitHub Desktop.
Save zhuqling/f49a18a079e2f7db705f2a8e8b8d02e0 to your computer and use it in GitHub Desktop.
Druid.io 总结

Druid.io 总结

注意点

  • 基于文件batch ingestion支持压缩文件.gz格式
  • intervals 时间区间 x/y 前闭后开 x <= n < y
  • granularity设为week时,按周一~周日汇总,符合中国标准
  • 跳过中间无数据的时间点,两头没有数据的不会自动添加时间点
  "context" : {
    "skipEmptyBuckets": "true"
  }

总数

{
  "queryType": "timeseries",
  "dataSource": "wikiticker",
  "granularity": "all", // all 所有合计,只返回一个时间点,但返回所有时间的总计
  "aggregations" : [
    {
      "type" : "longSum", // longSum=>整形合计,doubleSum=>浮点数合计
      "name" : "edits", // 返回名称
      "fieldName" : "added" // 原数据点
    },
    {
      "type" : "longSum",
      "name" : "rows",
      "fieldName" : "count"
    }
  ],
  "intervals": ["2015-09-12/2015-09-15"],
}

比率

{
  "queryType": "timeseries",
  "dataSource": "wikiticker",
  "granularity": "all",
  "filter": {
    "type": "and",
    "fields": [
      {
        "type": "selector",
        "dimension": "isRobot",
        "value": "false"
      },
      {
        "type": "in",
        "dimension": "channel",
        "values": ["#ca.wikipedia", "#en.wikipedia"]
      }
    ]
  },
  "aggregations" : [
    {
      "type" : "longSum",
      "name" : "new",
      "fieldName" : "added"
    },
    {
      "type" : "longSum",
      "name" : "total",
      "fieldName" : "count"
    }
  ],
  "postAggregations": [
    { "type": "arithmetic",
      "name": "rate", // rate = new / total, 当total=0时,返回0
      "fn": "/",
      "fields": [
        { "type": "fieldAccess", "fieldName": "total" },
        { "type": "fieldAccess", "fieldName": "new" }
      ]
    }
  ],
  "intervals": ["2015-09-12/2015-09-13"]
}

趋势

{
  "queryType": "timeseries",
  "dataSource": "wikiticker",
  "granularity": "day",
  "filter": {
    "type": "and",
    "fields": [
      {
        "type": "selector",
        "dimension": "isRobot",
        "value": "false"
      },
      {
        "type": "in",
        "dimension": "channel",
        "values": ["#ca.wikipedia", "#en.wikipedia"]
      }
    ]
  },
  "aggregations" : [
    {
      "type" : "longSum",
      "name" : "new",
      "fieldName" : "added"
    },
    {
      "type" : "longSum",
      "name" : "total",
      "fieldName" : "count"
    }
  ],
  "postAggregations": [
    { "type": "arithmetic",
      "name": "rate",
      "fn": "/",
      "fields": [
        { "type": "fieldAccess", "fieldName": "total" },
        { "type": "fieldAccess", "fieldName": "new" }
      ]
    }
  ],
  "intervals": ["2015-09-12/2015-09-15"]
}

分组

{
  "queryType" : "topN",
  "dataSource" : "wikiticker",
  "intervals" : ["2015-09-12/2015-09-15"],
  "granularity" : "day", // 天比较:day+intervals两天(1周当环比时),,周比较:week+intervals两周,月比较:month+两月;非汇总指标,只能按day调节interval,排除不需要的中间天
  "dimension" : "page", // 分组项
  "metric" : "total", // 排序字段,按此字段由大到小排序返回,需包含在aggregations或postAggregations内
  "threshold" : 100, // 返回数限制,最大1000,否则使用groupBy查询
  "aggregations" : [
    {
      "type" : "longSum",
      "name" : "new",
      "fieldName" : "added"
    },
    {
      "type" : "longSum",
      "name" : "total",
      "fieldName" : "count"
    }
  ],
  "postAggregations": [
    { "type": "arithmetic",
      "name": "rate",
      "fn": "/",
      "fields": [
        { "type": "fieldAccess", "fieldName": "total" },
        { "type": "fieldAccess", "fieldName": "new" }
      ]
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment