Apache Drill初探
- 介紹
Apache Drill是一個開源的,對於Hadoop和NoSQL低延遲的SQL查詢引擎。
Apache Drill 實現了 Google's Dremel.那么什么是Google's Dremel?網絡中一段描述:Dremel 是Google 的"交互式"數據分析系統。可以組建成規模上千的集群,處理PB級別的數據。MapReduce處理一個數據,需要分鍾級的時間。作為MapReduce的發起人,Google開發了Dremel將處理時間縮短到秒級,作為MapReduce的有力補充。Dremel作為Google BigQuery的report引擎,獲得了很大的成功。
一些特性:
-
實時分析及快速應用開發
2.兼容已有的 SQL 環境和 Apache Hive
3.半結構化/嵌套數據結構
- 安裝
- https://drill.apache.org/download/下載最新版Drill 0.7.0
-
單機模式運行,在drill 安裝目錄執行命令:
bin/sqlline -u jdbc:drill:zk=local -n admin -p admin
進入drill shell命令行交互模式:
輸入!tables查看系統默認的一些表
查詢實例表:SELECT * FROM cp.`employee.json` LIMIT 20;
安裝成功!輸入!quit命令退出。
分布式安裝運行:
將drill-override-example.conf的內容復制到drill-override.conf
修改其中Zookeeper配置
bin目錄執行drillbit.sh即可
三、架構原理
1. Drill查詢架構
查詢的流程常包括以下步驟:
- drill客戶端發起查詢,客戶端可以是一個JDBC、ODBC、命令行界面或REST API。集群中任何drill單元可以接受來自客戶端的查詢,沒有主從概念。
- drill單元對查詢進行分析、優化,並針對快速高效執行生成一個最優的分布式執行計划。
- 收到請求的drill單元成為該查詢的drill單元驅動節點。這個節點從ZooKeeper獲取整個集群可用的一個drill單元列表。驅動節點確定合適的節點來執行各種查詢計划片段到達最大化數據局部性。
- 各個節點查詢片段執行計划按照它們的drill單元計划表執行。
- 各個節點完成它們的執行后返回結果數據給驅動節點。
- 驅動節點以流的形式將結果返回給客戶端。
2.Drillbit核心模型
3. Drill 編譯器
四、應用
1.Drill接口
①Drill shell (SQLLine)見安裝部分
②Drill Web UI(安裝目錄命令行啟動bin/sqlline -u jdbc:drill:zk=local -n admin -p admin)
進入查詢窗口
數據源設置
③ODBC & JDBC,可以在第三方應用配置相關的驅動直接連接
也可以使用編程模式, JDBC編程接口
加載驅動org.apache.drill.jdbc.Driver;使用Connection URL: jdbc:drill:zk=xuansheng-pc
更多代碼:
https://github.com/asinwang/drill-demo/blob/master/src/main/java/org/apache/drill/jdbc/JdbcDemo.java
④C++ API(沒有看見相關資料,貌似還在開發中)
⑤REST接口
import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Request;
import org.apache.http.entity.ContentType;
import com.alibaba.fastjson.JSON;
public class RestDemo {
private static final String HOST_NAME = "http://xuansheng-pc:8047/query.json";
private static String buildRequestBody(String queryType, String query) {
RequestBody reques = new RequestBody(queryType, query);
String json = JSON.toJSON(reques).toString();
return json;
}
public static void main(String[] args) throws Exception {
String queryType = "SQL";
String query = "SELECT * FROM cp.`employee.json` LIMIT 20";
String buildRequestBody = buildRequestBody(queryType, query);
System.out.println("buildRequestBody:" + buildRequestBody);
Content returnContent = Request.Post(HOST_NAME).bodyString(buildRequestBody, ContentType.APPLICATION_JSON)
.execute().returnContent();
System.out.println(returnContent);
}
}
class RequestBody {
private String queryType;
private String query;
public RequestBody() {
}
public RequestBody(String queryType, String query) {
super();
this.queryType = queryType;
this.query = query;
}
public String getQueryType() {
return queryType;
}
public void setQueryType(String queryType) {
this.queryType = queryType;
}
public String getQuery() {
return query;
}
public void setQuery(String query) {
this.query = query;
}
}
-
連接Hbase、HDFS等
查詢時使用對應的type作為命名空間即可
工程代碼見:https://github.com/asinwang/drill-demo.git
相關資源