0

I am new to Apache Drill and got it setup fine to run locally in embedded mode and via Web interface. However, am facing the following issue when trying to access via Java client using JDBC.

Following drill docs and a few posts here, my setup is like:

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

code:

public static void main(String[] args) {
  Class.forName("org.apache.drill.jdbc.Driver");
  **Connection connection = DriverManager.getConnection("jdbc:drill:zk=local");**
  Statement st = connection.createStatement();
  ResultSet rs = st.executeQuery("SELECT * from cp.`employee` LIMIT 10");
  while (rs.next()) {
    System.out.println(rs.getString(1));
  }
...

There are no compile issues however, on running the above, I get the following OutOfMemoryException on the highlighted section of above code:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/drill/exec/exception/OutOfMemoryException
 at org.apache.drill.jdbc.impl.DrillJdbc41Factory.newDrillConnection(DrillJdbc41Factory.java:64)
 at org.apache.drill.jdbc.impl.DrillFactory.newConnection(DrillFactory.java:69)
 at net.hydromatic.avatica.UnregisteredDriver.connect(UnregisteredDriver.java:126)
 at org.apache.drill.jdbc.Driver.connect(Driver.java:72)
 at java.sql.DriverManager.getConnection(DriverManager.java:664)
 at java.sql.DriverManager.getConnection(DriverManager.java:270)
 at com.mapr.drill.DrillJDBCExample.runMode1(DrillJDBCExample.java:49)
 at com.mapr.drill.DrillJDBCExample.main(DrillJDBCExample.java:21)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.ClassNotFoundException: org.apache.drill.exec.exception.OutOfMemoryException
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 ... 13 more

I did this with drill running locally. Also tried with changing jdbc url to "jdbc:drill:drillbit=localhost";

Please help.

Ross
  • 1,313
  • 4
  • 16
  • 24
san
  • 3
  • 1
  • 5
  • you are working on windows machine or Linux? – Dev Jul 11 '16 at 14:41
  • Seems like a build issue to me. Please make sure `mvn clean install -DskipTests` is sucessful. As drill is running is locally so try with `"jdbc:drill:drillbit=localhost"` (_you mentioned too_) – Dev Jul 11 '16 at 14:57
  • mvn commands run fine. There are no tests to skip. Also tried the localhost drillbit with drill started locally. Also tried changed localhost to ip address. – san Jul 11 '16 at 15:41

2 Answers2

0

I am assuming you are trying to query employee.json file in your classpath and cp storage plugin in enabled.

Then your query should be

SELECT * from cp.`employee.json` LIMIT 10

EDIT:

Try one thing simply add drill-jdbc-all-1.7.0.jar located at <drill-directory>/jars/jdbc-driver in your project and try your JDBC code. This jar is bundled with all the dependent jars.

Dev
  • 13,492
  • 19
  • 81
  • 174
  • Thanks dev. I have tried with this query with same exception. – san Jul 11 '16 at 14:33
  • Please correct me if wrong but the jdbc URL provided in code should cause drill to pick up the employee.json file in query isnt it? What does it have to do with file being in classpath? – san Jul 11 '16 at 15:58
  • @user3638201 Creating JDBC connection with drill has nothing to do with classpath and all. As drill is running, so go to http://localhost:8047/storage and you will see storage plugins. You can query on those which are under **Enabled Storage Plugins**. Check details of plugin : https://drill.apache.org/docs/storage-plugin-registration/. As per the query you are using cp plugin name which is actually used to query all the files in Classpath – Dev Jul 12 '16 at 05:21
  • Yep, the cp storage is enabled as I have been running command line and browser queries against that storage plugin. Also, earlier I meant that if the file is already in drills classpath then there are no other classpath settings to set in terms of java client. Querying the storage plugin should take care of accessing employee.json file from the 3rd party foodmart jar I suppose. – san Jul 12 '16 at 14:41
  • yes, **foodmart jar** is having `employee.json` file. – Dev Jul 12 '16 at 14:52
  • @user3638201 As you are able to query via Drill client and UI, try one thing simply add `drill-jdbc-all-1.7.0.jar` located at `/jars/jdbc-driver` in your project and try your JDBC code. This jar is bundled with all the dependent jars. – Dev Jul 12 '16 at 14:55
  • So I started again from scratch and this time included jdbc-all jar in dependencies. Now, I could get my client to work but only when drill was running locally and with using drillbit=localhost in jdbc url. I get exceptions if I shut drill down and use the zk=local in jdbc url. Anyway, I guess we need to use the jdbc-all jar too which is different from all what I found so far. dev, would you like to post your suggestion as a comment for me to accept as an answer. Thanks! – san Jul 18 '16 at 03:07
0

Use drill-jdbc-all instead of drill-jdbc. Below is an example

<dependency>
        <groupId>org.apache.drill.exec</groupId>
        <artifactId>drill-jdbc-all</artifactId>
        <version>1.15.0</version>
        <exclusions>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>log4j-over-slf4j</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
Ben
  • 179
  • 1
  • 3