zoukankan      html  css  js  c++  java
  • 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/
  • 相关阅读:
    [转]理解java的三大特性之多态
    [转]java:IO流学习小结
    Base64 加密之中文乱码
    piwik优化之定时任务生成统计数据
    php统计中英文混合的文章字数
    Linux常用命令之定时任务
    skype在线状态代码详解
    php+google/baidu翻译接口
    php限制文件下载速度的代码
    PHP破解wifi密码(wifi万能钥匙的接口)
  • 原文地址:https://www.cnblogs.com/xuansheng/p/4675036.html
Copyright © 2011-2022 走看看