Apache Drill初探


                                    Apache Drill初探

  1. 介紹

Apache Drill是一個開源的,對於HadoopNoSQL低延遲的SQL查詢引擎。

Apache Drill 實現了 Google's Dremel.那么什么是Google's Dremel?網絡中一段描述:Dremel Google "交互式"數據分析系統。可以組建成規模上千的集群,處理PB級別的數據。MapReduce處理一個數據,需要分鍾級的時間。作為MapReduce的發起人,Google開發了Dremel將處理時間縮短到秒級,作為MapReduce的有力補充。Dremel作為Google BigQueryreport引擎,獲得了很大的成功。

一些特性:

  1. 實時分析及快速應用開發

     2.兼容已有的 SQL 環境和 Apache Hive

3.半結構化/嵌套數據結構

  1. 安裝
  2. https://drill.apache.org/download/下載最新版Drill 0.7.0
  3. 單機模式運行,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查詢架構

查詢的流程常包括以下步驟:

  1. drill客戶端發起查詢,客戶端可以是一個JDBCODBC、命令行界面或REST API。集群中任何drill單元可以接受來自客戶端的查詢,沒有主從概念。
  2. drill單元對查詢進行分析、優化,並針對快速高效執行生成一個最優的分布式執行計划。
  3. 收到請求的drill單元成為該查詢的drill單元驅動節點。這個節點從ZooKeeper獲取整個集群可用的一個drill單元列表。驅動節點確定合適的節點來執行各種查詢計划片段到達最大化數據局部性。
  4. 各個節點查詢片段執行計划按照它們的drill單元計划表執行。
  5. 各個節點完成它們的執行后返回結果數據給驅動節點。
  6. 驅動節點以流的形式將結果返回給客戶端。

2.Drillbit核心模型

 

3. Drill 編譯器

四、應用

1.Drill接口

Drill shell (SQLLine)見安裝部分

Drill Web UI(安裝目錄命令行啟動bin/sqlline -u jdbc:drill:zk=local -n admin -p admin)

http://127.0.0.1:8047/

進入查詢窗口

數據源設置

③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;

    }

}

  1. 連接HbaseHDFS

查詢時使用對應的type作為命名空間即可

 

工程代碼見:https://github.com/asinwang/drill-demo.git

相關資源

  1. http://drill.apache.org/
  2. https://static.googleusercontent.com/media/research.google.com/zh-CN//pubs/archive/36632.pdf
  3. http://www.yankay.com/google-dremel-rationale/
  4. https://docs.google.com/document/d/1RF0v05l0lWy1OwSXxHuboqJNLRkS-YzshrEVmUSby5I/edit
  5. http://www.geekfan.net/13787/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM