Skip to content

Instantly share code, notes, and snippets.

@yssharma
Last active August 29, 2015 14:25
Show Gist options
  • Save yssharma/8b72557ad23f080e7c1f to your computer and use it in GitHub Desktop.
Save yssharma/8b72557ad23f080e7c1f to your computer and use it in GitHub Desktop.
Sample test code for DRILL JDBC
-------------
Dependency
-------------
<dependency>
<groupId>org.apache.drill.exec</groupId>
<artifactId>drill-jdbc</artifactId>
<version>1.1.0</version>
</dependency>
----------
Testcase
----------
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
import org.apache.drill.exec.ExecConstants;
import org.apache.drill.jdbc.Driver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class TestDrillJdbcDriver {
/* Drill JDBC Uri for local zookeeper */
public static final String DRILL_JDBC_LOCAL_URI = "jdbc:drill:zk=local";
/* Sample query used by Drill */
public static final String DRILL_SAMPLE_QUERY = "SELECT * FROM cp.`employee.json` LIMIT 20";
@Test
public void testDrillJdbcDriver() throws Exception {
Connection con = null;
try {
con = new Driver().connect(DRILL_JDBC_LOCAL_URI, getDefaultProperties());
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(DRILL_SAMPLE_QUERY);
int count = 0;
while (rs.next()) {
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(3));
count++;
}
Assert.assertEquals(count, 20, "Twenty rows were expected.");
} catch (Exception ex) {
System.out.println(ex);
} finally {
if (con != null) {
con.close();
}
}
}
public static Properties getDefaultProperties() {
final Properties properties = new Properties();
properties.setProperty(ExecConstants.HTTP_ENABLE, "false");
return properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment