Hello, something :)
Regarding jdbc style: I understand this approach has some limitations, but here 
is an example.
You will need to make sure the hive service is running: 
https://cwiki.apache.org/Hive/hiveserver.html
Here is a sample code that I've used for testing. It is not the best java in 
the world but it gets the job done.
You will need to make sure the hive and hadoop jars are on the classpath. Note 
you will have to edit the connectionString.


import java.sql.*;

public class RunSQL {
   private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
   private static String connectionString = 
"jdbc:hive://myserver.hp.com:10000/default";

    public static void main(String[] args) throws SQLException 
,org.apache.hadoop.hive.ql.metadata.HiveException {

        String SQLToRun=(args[0]);

        ResultSet res = null;

        try {
            Class.forName(driverName);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(1);
          }
        Connection con = DriverManager.getConnection(connectionString);
        System.out.println("Connected.");

        Statement stmt = con.createStatement();

        System.out.println("Running: " + SQLToRun);
        res = stmt.executeQuery(SQLToRun);
        ResultSetMetaData meta=res.getMetaData();
        int numberOfColumns=meta.getColumnCount();

        System.out.println("Result:");
        while (res.next()) {
                for (int i=1;i<=numberOfColumns;i++){
                    System.out.print(String.valueOf("\t" + res.getString(i)));
                }
                System.out.println();
        }

    }
}

From: Something Something [mailto:mailinglist...@gmail.com]
Sent: Monday, September 17, 2012 12:39 AM
To: hive-u...@hadoop.apache.org
Subject: Questions about Hive

Note:  I am a newbie to Hive.

Can someone please answer the following questions?

1)  Does Hive provide APIs (like HBase does) that can be used to retrieve data 
from the tables in Hive from a Java program?  I heard somewhere that the data 
can be accessed with JDBC (style) APIs.  True?

2)  I don't see how I can add indexes on the tables, so does that mean a query 
such as the following will trigger a MR job that will search files on HDFS 
sequentially?





hive> SELECT a.foo FROM invites a WHERE a.ds='2008-08-15';

3)  Has anyone compared performance of Hive against other NOSQL databases such 
as HBase, MongoDB.  I understand it's not exactly apples to apples comparison, 
but still...

Thanks.

Reply via email to