Apache Drill - connection to Drill in Embedded Mode [java]
Asked Answered
G

4

7

I want to connect to Drill by Java app, and so far I was trying to use JDBC to do it and I'm using example from https://github.com/vicenteg/DrillJDBCExample, but... when I change DB_URL static variable to "jdbc:drill:zk=local" and start app i get exception:

java.sql.SQLNonTransientConnectionException: Running Drill in embedded mode using Drill's jdbc-all JDBC driver Jar file alone is not supported.

and so far I didn't found any workaround. Any idea how to connect to Drill in embedded mode? I don't want to set up distributed mode so far.

There is truly not much about it on the web.

Any help would be appreciated!

Glorious answered 27/7, 2015 at 13:38 Comment(4)
Did you try using this JDBC URL? jdbc:drill:drillbit=<drillbit-hostname>:31010Bifocals
im using embedded mode, so I dont start drillbit as far as i knowGlorious
When you use embedded mode, you are starting a drillbit, it just does so without requiring a zookeeper instance.Bifocals
@vicenteg this error is shown on changing JDBC URL: No suitable driver found for dbc:drill:drillbit=localhost:31010Patentor
P
11

If you are connecting to a local embedded instance(without Zookeeper), you should use drillbit host directly like:

jdbc:drill:drillbit=<drillbit-host>:[port]

eg: jdbc:drill:drillbit=localhost

Putdown answered 21/9, 2015 at 21:4 Comment(1)
This is working well for me on Squirrel & SQLWorkbench as wellMichal
L
7

TLDR: jdbc:drill:drillbit=localhost:31010

First try using SQuirreL SQL client.

I am doing this with a vm running linux and apache, if this is all on one host you can replace with localhost.

first start drill-embedded on your vm or host eg:

/opt/apache-drill-1.1.0/bin/drill-embedded

this will start the embedded shell. check the port is open - it looks to be a different default than zookeeper etc:

sroot@localhost:/opt/apache-drill-1.1.0/bin [1089] netstat -anp | grep 31010

tcp 0 0 ::ffff:0.0.0.0:31010 :::* LISTEN 12934/java

you should be able to telnet localhost 31010 to this port.

you have to setup the jar driver as described here : https://drill.apache.org/docs/using-jdbc-with-squirrel-on-windows/

make sure the jar with the driver is executable.

but modify the string with the below - its different without zookeeper, eg in squirrel should look like this (thanks to others answers above too

jdbc:drill:drillbit=localhost:31010

you can replace localhost with the ip above - then test the connection.

the jar i'm using is the drill-jdbc-all-1.1.0.jar and the classname is org.apache.drill.jdbc.Driver

example squirrel driver configuration

Linearity answered 30/10, 2015 at 18:26 Comment(0)
M
1

I dont think you r using the correct jar. It seems you are using jdbc-all-jar. There are two jars. You need to add the other jar to make it work. Have added the maven pom. this should get you going

<dependency>
      <groupId>org.apache.drill.exec</groupId>
      <artifactId>drill-jdbc</artifactId>
      <version>1.1.0</version>
    </dependency>
Mllly answered 3/8, 2015 at 9:12 Comment(1)
java.lang.ClassNotFoundException: org.apache.drill.exec for now. But its something new!Glorious
P
0

you need to add the following dependency in your java project (I assume maven based)

<dependency>
    <groupId>org.apache.drill.exec</groupId>
    <artifactId>drill-jdbc</artifactId>
    <version>1.4.0</version>
</dependency>

Sample code (Assuming you want to run drill in embedded mode):

Class.forName("org.apache.drill.jdbc.Driver");
Connection connection =DriverManager.getConnection("jdbc:drill:zk=localhost");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery("SELECT * from cp.`employee`");
while(rs.next()){
System.out.println(rs.getString(1));
}

If you already started drill (assumning drill is running on local machine). Then you should change Connection:

Connection connection =DriverManager.getConnection("jdbc:drill:drillbit=localhost");

Check sample project: https://github.com/devender-yadav/DrillJDBC

NOTE: I have tested this for Drill 1.2, 1.3 and 1.4

Patentor answered 28/11, 2015 at 7:43 Comment(1)
For both the options, do i need to explicitly start the drill ? or in the first option it will start automatically in embedded mode?Zubkoff

© 2022 - 2024 — McMap. All rights reserved.