Apache Drill之 SQLParser Apache Calcite

Apache Drill

为了理解Calcite,下面的PPT可以学习下

http://www.slideshare.net/julianhyde/apache-calcite-overview?related=2

http://www.slideshare.net/julianhyde/calcite-stratany2014

http://www.slideshare.net/julianhyde/drill-sql-optiq

https://datapsyche.wordpress.com/2014/08/06/optiq-query-push-down-concepts/


Drill的逻辑结构如下图所示。其中SQL Parser部分采用的是Apache Calcite。简单的来说这里在Drill里面Calcite实现的功能是提供了JDBC interface,接收用户的查询请求,然后将SQL Query语句转换成为SQL语法树,也就是逻辑计划。


比如查询语句:SELECT device, cust_id, order_id FROM clicks.json t, hive.orders o WHERE t.cust_id=o.cust_id

在SQL Parser之后Drill中会得到如下的逻辑计划


那么Apache Calcite究竟是何方神圣,其实就是之前的Optiq

Calcite

架构如下图所示。(Calcite最初被命名为Optiq,由Julian Hyde所编写,但如今已经成为Apache孵化器项目之一。

http://calcite.incubator.apache.org/


对Calcite进行一个简单的入门学习

http://www.tuicool.com/articles/u2qqIr  SQL over anything with an Optiq Adapter



this post shows how to create an Optiq Adapter. There are examples out there with optiq-csv and couple of other projects but I found them a little hard to comprehend. Moreover, query push down feature isn’t well documented and I would do a followup post on that soon.

What is Optiq?

Optiq ( https://github.com/julianhyde/optiq ) is a query planning engine that can help you execute and plan SQL over your data sources. For example, there is a project optiq-web using which you can point to wiki pages with tables and query those html tables through SQL. Similar projects are there to run SQL on CSV, JSON files, MongoDB etc. Lets say you built a custom data store and you want to provide SQL access to it, then Optiq is a good choice. You just need to write an Optiq adapter to your data source.

A Sample Use Case

Anyways, the intention of this post is a step by step guide to write a custom adapter. Let’s see how I wrote an adapter to run SQL on top of JavaBean objects. Lets say you have a List of Users (JavaBean Objects) and would like to run queries like: “select max(age) from users” etc. Optiq has an inbuilt ReflectiveSchema that can be used here, but lets do our own implementation to see how it’s done, also ReflectiveSchema does not have query push down which I am planning to add.

Creating the Adapter

Tutorial source code link:  https://github.com/cyberabis/optiq-javabean

Step 1: Create a Schema Class

The Schema class is the equivalent of a Database and can contain multiple tables.

Extend AbstractSchema and override getTableMap method. This method should return table names and Tables. How to create table class is next.

package io.thedal.optiq.javabean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值