0
votes

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.

2
you are working on windows machine or Linux? - Dev
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
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

2 Answers

0
votes

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.

0
votes

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>