Tej Kiran
Tej Kiran

Reputation: 2238

Java Client Jar for Apache Drill

I have a machine on which I am storing some data in the form of json or csv. and on same machine Apache Drill is also running. I can access the Apache Drill using web console on different machine. and also can execute the sql query on the file that store on the machine where Apache Drill is running. Now I want to create a program that can execute sql query as I am doing on web browser in web console of Apache Drill.

Can anyone know about the jar like webhdfs-java-client-0.0.2.jar used for Hadoop hdfs?

I am looking for such a java client jar for Apache Drill.

Upvotes: 0

Views: 153

Answers (1)

Dev
Dev

Reputation: 13753

You can achieve this using drill-jdbc driver. Check Drill's documentation.

If you are using maven, add this dependency:

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

Sample code (assuming drill running on xx.xx.xx.xx):

Class.forName("org.apache.drill.jdbc.Driver");

Connection connection =DriverManager.getConnection("jdbc:drill:drillbit=xx.xx.xx.xx");
Statement st = connection.createStatement();
ResultSet rs = st.executeQuery(<your SQL query>);
while(rs.next()){
System.out.println(rs.getString(1));
}

If you want zookeeper to start drill automatically, use:

Connection connection =DriverManager.getConnection("jdbc:drill:zk=xx.xx.xx.xx");

Note: Here xx.xx.xx.xx can be IP address or host name.

Edit: Check my github project for more details.

Upvotes: 1

Related Questions