0.17版本,Druid支持多种数据导入方式:
- UI界面,根据步骤和提示,一步步执行即可
- UI界面,提交json格式的task文件
- 本地curl命令提交json格式的task文件
- Druid家目录下,执行自带的post-index-task
个人感觉第一种和第3种用着比较方便。接下来对每种数据导入方式的操作步骤详细介绍。
Druid支持流数据摄取和批量摄取两种方式。
- 流数据摄取:支持Kafka、Kinesis和Tranquility。
- 批量摄取:支持index(串行)、index_parallel(并行,0.13版本新增)和index_hadoop(M/R任务)。推荐使用后两种。有现成的Hadoop集群时,推荐使用index_hadoop方式。
1、UI界面
在浏览器输入http://broker:8888,进入Druid的UI界面
点击左上方的Load data按钮,选择数据源类型即可。可以选择Kafka、local、hdfs等。然后根据步骤提示操作即可。
需要注意的是,在这一步骤,可以设置数据导入的并行度,提高数据摄取速度。
2、UI界面,提交json格式的task文件
和第一种类似,但是需要自己编辑task文件。指定时间列、维度列和指标列的信息,指定聚合粒度等。
在ingestion界面,点击提交即可。
3、本地curl命令提交json格式的task文件
编辑task任务,在命令行提交。示例如下,根据自己数据编辑对应内容。
{
"type": "index_parallel",
"spec": {
"dataSchema": {
"dataSource": "wikipedia",
"timestampSpec": {
"column": "timestamp",
"format": "auto"
},
"dimensionsSpec": {
"dimensions": [
{ "type": "string", "page" },
{ "type": "string", "language" },
{ "type": "long", "name": "userId" }
]
},
"metricsSpec": [
{ "type": "count", "name": "count" },
{ "type": "doubleSum", "name": "bytes_added_sum", "fieldName": "bytes_added" },
{ "type": "doubleSum", "name": "bytes_deleted_sum", "fieldName": "bytes_deleted" }
],
"granularitySpec": {
"segmentGranularity": "day",
"queryGranularity": "none",
"intervals": [
"2013-08-31/2013-09-01"
]
}
},
"ioConfig": {
"type": "index_parallel",
"inputSource": {
"type": "local",
"baseDir": "examples/indexing/",
"filter": "wikipedia_data.json"
},
"inputFormat": {
"type": "json",
"flattenSpec": {
"useFieldDiscovery": true,
"fields": [
{ "type": "path", "name": "userId", "expr": "$.user.id" }
]
}
}
},
"tuningConfig": {
"type": "index_parallel"
}
}
}
在命令行提交。
curl -X 'POST' -H 'Content-Type:application/json' -d @filepath/task.json http://localhost:8081/druid/indexer/v1/task
4、bin目录下,自带的post-index-task
指定task任务的文件位置,提交任务即可。
bin/post-index-task --file filepath/task.json --url http://localhost:8081