入門
本教程介紹如何將您的數(shù)據(jù)文件加載到Druid啸澡。
在本教程中,我們假設(shè)您已經(jīng)按照快速入門中所述下載了Druid,并將其在本機上運行庐船。并且您不需要事先加載任何數(shù)據(jù)。
上述步驟完成后嘲更,你就可以通過編寫自定義的提取規(guī)范來加載自己的數(shù)據(jù)集了筐钟。
編寫提取規(guī)范
您可以使用Druid批量加載進程將文件數(shù)據(jù)加載到Druid。在quickstart/wikiticker-index.json有一個批量提取規(guī)范的示例赋朦,根據(jù)需求可以自行修改篓冲。
最重要的問題是:
{
"type" : "index_hadoop",
"spec" : {
"ioConfig" : {
"type" : "hadoop",
"inputSpec" : {
"type" : "static",
//2.數(shù)據(jù)集路徑,多個文件使用逗號分隔
"paths" : "quickstart/wikiticker-2015-09-12-sampled.json"
}
},
"dataSchema" : {
//1.應(yīng)該調(diào)用什么數(shù)據(jù)集
"dataSource" : "wikiticker",
"granularitySpec" : {
"type" : "uniform",
"segmentGranularity" : "day",
"queryGranularity" : "none",
//6.加載的時間的范圍或者間隔
"intervals" : ["2015-09-12/2015-09-13"]
},
"parser" : {
"type" : "hadoopyString",
"parseSpec" : {
"format" : "json",
"dimensionsSpec" : {
//4.有哪些字段作為維度
"dimensions" : [
"channel",
"cityName",
"comment",
"countryIsoCode",
"countryName",
"isAnonymous",
"isMinor",
"isNew",
"isRobot",
"isUnpatrolled",
"metroCode",
"namespace",
"page",
"regionIsoCode",
"regionName",
"user"
]
},
"timestampSpec" : {
"format" : "auto",
//3.哪個字段應(yīng)該視為時間戳
"column" : "time"
}
}
},
//5.哪些字段作為指標
"metricsSpec" : [
{
"name" : "count",
"type" : "count"
},
{
"name" : "added",
"type" : "longSum",
"fieldName" : "added"
},
{
"name" : "deleted",
"type" : "longSum",
"fieldName" : "deleted"
},
{
"name" : "delta",
"type" : "longSum",
"fieldName" : "delta"
},
{
"name" : "user_unique",
"type" : "hyperUnique",
"fieldName" : "user"
}
]
},
"tuningConfig" : {
"type" : "hadoop",
"partitionsSpec" : {
"type" : "hashed",
"targetPartitionSize" : 5000000
},
"jobProperties" : {}
}
}
}
如果您的數(shù)據(jù)里面沒有記錄時間宠哄,您可以用當前時間標記每一行數(shù)據(jù)壹将,或者也可以用一個固定時間戳去標記所有行,例如"2000-01-01T00:00:00.000Z"毛嫉。
讓我們以網(wǎng)頁瀏覽數(shù)據(jù)集為例诽俯, Druid支持TSV,CSV和JSON承粤,開箱即用暴区。 請注意闯团,Druid不支持嵌套的JSON對象,因此如果您使用JSON仙粱,則應(yīng)提供包含平面對象的文件房交。
{"time": "2015-09-01T00:00:00Z", "url": "/foo/bar", "user": "alice", "latencyMs": 32}
{"time": "2015-09-01T01:00:00Z", "url": "/", "user": "bob", "latencyMs": 11}
{"time": "2015-09-01T01:30:00Z", "url": "/foo/bar", "user": "bob", "latencyMs": 45}
確保文件末尾沒有換行符。 如果將此文件保存到名為“pageviews.json”的文件伐割,則對于此數(shù)據(jù)集:
- 數(shù)據(jù)集叫做 "pageviews"
- 數(shù)據(jù)位于"pageviews.json"中
- 時間戳是 "time"字段
- "url" 和 "user"字段適合作為數(shù)據(jù)維度
- 網(wǎng)頁的訪問量(count統(tǒng)計)和總耗時(sum(latencyMs))是很好的指標涌萤,當我們加載數(shù)據(jù)的時候收集這些統(tǒng)計值,可以讓我們能夠很容易在查詢時計算平均值口猜。
- 數(shù)據(jù)涵蓋的時間范圍是 2015-09-01 (包含) 到2015-09-02 (不包含)远寸。
你可以將現(xiàn)有的索引文件quickstart/wikiticker-index.json深滚,copy到新文件。
cp quickstart/wikiticker-index.json my-index-task.json
然后通過更改這些部分修改它:
"dataSource": "pageviews"
"inputSpec": {
"type": "static",
"paths": "pageviews.json"
}
"timestampSpec": {
"format": "auto",
"column": "time"
}
"dimensionsSpec": {
"dimensions": ["url", "user"]
}
"metricsSpec": [
{"name": "views", "type": "count"},
{"name": "latencyMs", "type": "doubleSum", "fieldName": "latencyMs"}
]
"granularitySpec": {
"type": "uniform",
"segmentGranularity": "day",
"queryGranularity": "none",
"intervals": ["2015-09-01/2015-09-02"]
}
運行任務(wù)
要運行此任務(wù),請確保索引任務(wù)能夠讀取pageviews.json:
如果你是本機運行(沒有配置到hadoop的連接计技,這也是Druid默認值)返奉,那么將pageviews.json放到Druid的根目錄下动分。
如果Druid配置了hadoop集群連接假消,那么將pageviews.json上傳到HDFS。并且調(diào)整上面提取規(guī)范的配置路徑耐床。
向Druid Overlord上提交你的索引任務(wù)密幔,就可以開始進行索引了,在標準Druid安裝中撩轰,URL為http://OVERLORD_IP:8090/druid/indexer/v1/task 胯甩。
curl -X 'POST' -H 'Content-Type:application/json' -d @my-index-task.json OVERLORD_IP:8090/druid/indexer/v1/task
如果你的所有東西都是在本機運行,你可以使用localhost
curl -X 'POST' -H 'Content-Type:application/json' -d @my-index-task.json localhost:8090/druid/indexer/v1/task
如果此任務(wù)發(fā)生任何錯誤(例如狀態(tài)為FAILED)堪嫂,可以通過overlord控制臺上的"Task log"進行故障排查(http://www.localhost/console.html)偎箫。
數(shù)據(jù)查詢
您的數(shù)據(jù)應(yīng)該在一到兩分鐘就能完全可用,在Coordinator控制臺http://localhost:8081/#/ 可以監(jiān)控進度皆串。
一旦數(shù)據(jù)完全可用淹办,就可以通過任意支持的查詢方法查詢數(shù)據(jù)了。
深入閱讀
想更深入了解批量加載數(shù)據(jù)恶复,請閱讀批量數(shù)據(jù)提取章節(jié)
原文鏈接:http://druid.io/docs/0.9.2/tutorials/tutorial-batch.html