hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Hadoop Wiki] Trivial Update of "Hive/HiveClient" by RaghothamMurthy
Date Fri, 27 Mar 2009 15:25:24 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Hadoop Wiki" for change notification.

The following page has been changed by RaghothamMurthy:

New page:
This page describes the different clients supported by Hive. The command line client currently
only supports an embedded server. The JDBC and thrift-java clients support both embedded and
standalone servers. Clients in other languages only support standalone servers. For details
about the standalone server see [wiki:Self:Hive/HiveServer HiveServer].

= Command line =
Operates in embedded mode only, i.e., it needs to have access to the hive libraries. For more
details see [wiki:Self:Hive/GettingStarted GettingStarted].

= JDBC =
For embedded mode, uri is just "jdbc:hive://". For standalone server, uri is "jdbc:hive://host:port/dbname"
where host and port are determined by where the hive server is run. For example, "jdbc:hive://localhost:10000/default".
Currently, the only dbname supported is "default".


import java.sql.*;

class HiveJdbcClient {
public static void main(String[] args) {
  String uri = "jdbc:hive://"; // for embedded mode
  String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
  // load the hive jdbc driver
  // currently do not support username and password
  Connection con = DriverManager.getConnection(uri, ""/*user*/, ""/*passwd*/); 
  Statement stmt = con.createStatement();

  // DDL Statement
  stmt.executeQuery("CREATE TABLE r(a STRING, b INT, c DOUBLE)");
  stmt.executeQuery("CREATE TABLE s(a STRING, b INT, c DOUBLE)");

  // Metadata 
  ResultSet res = stmt.executeQuery("SHOW TABLES");
  // fetch results
  while (res.next()) {
   // Column indexes start from 1
   System.out.println("Table name: " + res.getString(1));

  // Metadata 
  ResultSet res = stmt.executeQuery("DESCRIBE r");
  while (res.next()) {
   System.out.println("Column Name: " + res.getString(1));
   System.out.println("Column Type: " + res.getString(2));
   System.out.println("Comment: " + res.getString(3));

  // DML Statement
  stmt.executeQuery("LOAD TABLE LOCAL INPATH '/path/to/file' INTO TABLE r");

  // Select
  res = stmt.executeQuery("SELECT * FROM r");
  while (res.next()) {

  // Insert
  res = stmt.executeQuery("INSERT OVERWRITE TABLE s SELECT * FROM r WHERE b > 10");


= Python =
Set PYTHONPATH to build/dist/lib/py
#!/usr/bin/env python

import sys

from hive import ThriftHive
from hive.ttypes import HiveServerException
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

    transport = TSocket.TSocket('localhost', 10000)
    transport = TTransport.TBufferedTransport(transport)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    client = ThriftHive.Client(protocol)

    client.execute("CREATE TABLE r(a STRING, b INT, c DOUBLE)")
    client.execute("LOAD TABLE LOCAL INPATH '/path' INTO TABLE r")
    client.execute("SELECT * FROM r")
    while (row = client.fetchOne()):
      print row
    client.execute("SELECT * FROM r")
    print client.fetchAll()


except Thrift.TException, tx:
    print '%s' % (tx.message)


= Thrift Java Client =

= ODBC =
In the works.

= Thrift C++ Client
In the works.

View raw message