博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Programmatic PlyQL via HTTP, ODBC, and JDBC
阅读量:2439 次
发布时间:2019-05-10

本文共 2710 字,大约阅读时间需要 9 分钟。

Some time ago at Imply, we launched PlyQL, a command line utility that provides an SQL-like interface to Druid via Plywood. We heard a lot of positive feedback as many people prefer to use SQL over Druid’s native JSON-over-HTTP interface. The most common question we hear about PlyQL is how one can interface to it programmatically either from user created apps or from existing SQL based BI tools. We are pleased to announce we just released PlyQL 0.7 with two brand new programmatic interface options: SQL-over-HTTP and MySQL Gateway.

SQL-over-HTTP

When you run:

plyql -h your.druid.broker:8082 --json-server 8083

PlyQL will start listening on port 8083 where you can POST some SQL like so:

curl -X POST 'http://localhost:8083/plyql' \  -H 'content-type: application/json' \  -d '{
"sql": "SELECT COUNT(*) FROM wikipedia WHERE \"2015-09-12T01\" <= __time AND __time < \"2015-09-12T02\""}'

Check out the for more info about possible parameters.

MySQL Gateway

In this experimental feature we use the excellent library to provide a MySQL server interface.

When you run:

plyql -h your.druid.broker:8082 --experimental-mysql-gateway 3307

PlyQL will start in a MySQL-like server mode and will be queryable from a MySQL client, ODBC, or JDBC driver.

SELECT user, COUNT(*) AS Count FROM wikipedia WHERE channel = "en" GROUP BY user ORDER BY Count DESC LIMIT 3

PlyQL will attempt to respond faithfully to SET, SHOW, DESCRIBE and any other meaningful query so that it appears to the client as a real MySQL server with read-only permissions.

SHOW FULL COLUMNS IN wikipedia LIKE "%e%"

While not all of MySQL is supported, the goal is to provide a way for new and existing tools that already communicate via ODBC or JDBC interfaces to talk to Druid using PlyQL.

Here is an example of how you could use the existing MySQL JDBC driver to query the above PlyQL gateway.

import java.sql.SQLException;import java.sql.DriverManager;import java.sql.Connection;import java.sql.Statement;import java.sql.ResultSet;class DruidQuery{  public static void main(String[] args) throws SQLException  {    Connection con = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3307/plyql1");    Statement stmt = con.createStatement();    ResultSet rs = stmt.executeQuery(      "SELECT page, count(*) AS cnt FROM wikipedia GROUP BY page ORDER BY cnt DESC LIMIT 15"    );    while (rs.next()) {      String page = rs.getString("page");      long count = rs.getLong("cnt");      System.out.println(String.format("page[%s] count[%d]", page, count));    }  }}

We are looking for your help to make this tool better. Whenever a query cannot be handled it will throw an error like so:

SHOW FULL COLUMNS IN wikipedia LIKE "%e%"

If this happens, please file an issue, if one does not already exist, and tell us what client software generated the relevant query.

For more information please look through the PlyQL Readme or run plyql –help

你可能感兴趣的文章
mongos分片集群下db数量过多导致服务不可用
查看>>
mysql唯一索引的一个小常识--Duplicate entry 'XXX' for key 'XXX'
查看>>
故障处理--mongos count不准
查看>>
大量短连接导致haproxy服务器端口耗尽
查看>>
mongo3.0.9库命名的一个S级bug
查看>>
跨版本导入数据导致mysqld崩溃
查看>>
xtrabackup对于flush tables with read lock操作的设置
查看>>
Gone away故障原因排查
查看>>
Server has authorization schema version 3,but found a schema version 1 user
查看>>
WebSphere的池设置——线程池、连接池
查看>>
caffe-ssd调试问题总结
查看>>
用户态调测工具(二):perror和man
查看>>
机器学习&深度学习入门历程
查看>>
LTP(Linux Test Project)学习(一)——LTP介绍
查看>>
LTP(Linux Test Project)学习(二)——LTP下载编译执行
查看>>
LTP(Linux Test Project)学习(三)——LTP目录介绍
查看>>
DirtyCow CVE-2016-5195分析
查看>>
caffe编译报错解决记录
查看>>
LTP(Linux Test Project)学习(七)——LTP提交补丁
查看>>
Linux 4.0亮点特性
查看>>