Cloudera Impala simple command line test

I am a big believer in simple command line examples. Connecting the dots is so much easier when you do this.

There will be much more on this, but this should get you started.

CLASSPATH is shown below. The absolute locations will differ according to where you place your jar files.

[root@util01 test]# env | grep CLASS | awk '{split($1,t,":");while (++i <= length(t)) {print t[i]}}'
CLASSPATH=.
/usr/share/tomcat5/common/lib/hive_contrib.jar
/usr/share/tomcat5/common/lib/hive-jdbc-0.10.0-cdh4.2.0.jar
/usr/share/tomcat5/common/lib/hive-metastore-0.10.0-cdh4.2.0.jar
/usr/share/tomcat5/common/lib/hive-service-0.10.0-cdh4.2.0.jar
/usr/share/tomcat5/common/lib/libthrift-0.9.0.jar
/usr/share/tomcat5/common/lib/slf4j-api-1.6.4.jar
/usr/share/tomcat5/common/lib/commons-logging-1.0.4.jar
[root@util01 test]#

Java code below...

import java.sql.*;

public class hive {
  public static void main (String args[]) {
    try {
      Class.forName("org.apache.hive.jdbc.HiveDriver");
      Connection con = DriverManager.getConnection("jdbc:hive2://192.168.3.50:21050/;auth=noSasl");
      Statement stmt = con.createStatement();
      ResultSet res = stmt.executeQuery("select * from x");
      while (res.next()) {
        System.out.println(res.getInt(1) + "
"); } stmt.close(); con.close(); } catch (Exception e) { e.printStackTrace(); System.out.println(e.getMessage()); } } }

...and output of the run...

[root@util01 test]# java hive
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
1
2
3
4
5
6
97
98
99
100

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.