本文介绍如何使用Druid数据源进行数据分析或者交互式开发。

建表语法

create table tbName
using druid
options(propertyKey=propertyValue[, propertyKey=propertyValue]*);

Table Schema

创建Druid数据表时,无需显式地定义表的字段信息,示例如下。
create table druid_test_table
using druid
options(
curator.connect="${ZooKeeper-host}:${ZooKeeper-port}}",
index.service="druid/overlord",
data.source="test_source",
discovery.path="/druid/discovery",
firehose="druid:firehose:%s",
rollup.aggregators="{\"metricsSpec\":[{\"type\":\"count\",\"name\":\"count\"},
                                      {\"type\":\"doubleSum\",\"fieldName\":\"value\",\"name\":\"sum\"},
                                      {\"type\":\"doubleMin\",\"fieldName\":\"value\",\"name\":\"min\"},
                                      {\"type\":\"doubleMax\",\"fieldName\":\"value\",\"name\":\"max\"}]}",
rollup.dimensions="timestamp,metric,userId",
rollup.query.granularities="minute",
tuning.segment.granularity="FIVE_MINUTE",
tuning.window.period="PT5M",
timestampSpec.column="timestamp",
timestampSpec.format="posix");

配置参数说明

参数 描述 是否必选
curator.connect ZooKeeper的Host,例如emr-header-1:2181
curator.max.retries ZooKeeper连接失败后的重试次数,默认值为5。
curator.retry.base.sleep ZooKeeper连接失败后重试的间隔初始值,默认值为100,单位毫秒。
curator.retry.max.sleep ZooKeeper连接失败后重试的间隔最大值,默认值为3000,单位毫秒。
index.service 例如druid或overlord。
data.source 写入Druid的data source。
discovery.path 默认值为druid或discovery。
firehose 例如druid:firehose:%s
rollup.aggregators tranquility聚合器,JSON格式,示例如下。
{\"metricsSpec\":[{\"type\":\"count\",\"name\":\"count\"},
                  {\"type\":\"doubleSum\",\"fieldName\":\"value\",\"name\":\"sum\"},
                  {\"type\":\"doubleMin\",\"fieldName\":\"value\",\"name\":\"min\"},
                  {\"type\":\"doubleMax\",\"fieldName\":\"value\",\"name\":\"max\"}]}
其中,metricsSpec为固定值。
rollup.dimensions 写入Druid的维度。
rollup.query.granularities 聚合粒度,例如minute。
tuning.window.period 时间窗大小,默认值为PT10M。
tuning.segment.granularity segment粒度,默认值为DAY。
tuning.partitions 分区数量,默认值为1。
tuning.replications 副本数,默认值为1。
timestampSpec.column 写入Druid时的timestamp列名,默认值为timestamp。
timestampSpec.format 写入Druid时的timestamp列名的格式,默认值为iso。