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 JonathanSmith
Date Thu, 10 Sep 2009 15:57:02 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 JonathanSmith:
http://wiki.apache.org/hadoop/Hive/HiveClient

------------------------------------------------------------------------------
  
  public class HiveJdbcClient {
    private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
-   
+ 
-   /** 
+   /**
     * @param args
-    * @throws SQLException 
+    * @throws SQLException
-    */  
+    */
    public static void main(String[] args) throws SQLException {
        try {
        Class.forName(driverName);
@@ -31, +31 @@

        // TODO Auto-generated catch block
        e.printStackTrace();
        System.exit(1);
-     }   
+     }
      Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default",
"", "");
      Statement stmt = con.createStatement();
      String tableName = "testHiveDriverTable";
@@ -43, +43 @@

      res = stmt.executeQuery(sql);
      if (res.next()) {
        System.out.println(res.getString(1));
-     }   
+     }
      // describe table
      sql = "describe " + tableName;
      System.out.println("Running: " + sql);
      res = stmt.executeQuery(sql);
      while (res.next()) {
        System.out.println(res.getString(1) + "\t" + res.getString(2));
-     }   
+     }
-         
+ 
      // load data into table
      // NOTE: filepath has to be local to the hive server
      // NOTE: /tmp/a.txt is a ctrl-A separated file with two fields per line
@@ -59, +59 @@

      sql = "load data local inpath '" + filepath + "' into table " + tableName;
      System.out.println("Running: " + sql);
      res = stmt.executeQuery(sql);
-         
+ 
      // select * query
      sql = "select * from " + tableName;
      System.out.println("Running: " + sql);
      res = stmt.executeQuery(sql);
      while (res.next()) {
        System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2));
-     }   
+     }
-         
+ 
      // regular hive query
      sql = "select count(1) from " + tableName;
      System.out.println("Running: " + sql);
      res = stmt.executeQuery(sql);
      while (res.next()) {
        System.out.println(res.getString(1));
-     }   
+     }
    }
  }
  }}}
@@ -130, +130 @@

  
  = Python =
  Operates only on a standalone server. Set (and export) PYTHONPATH to build/dist/lib/py.
- The python modules imported in the code below are generated by building hive.
+ [[BR]]The python modules imported in the code below are generated by building hive.
- Please note that the generated python module names have changed in hive trunk.
+ [[BR]]Please note that the generated python module names have changed in hive trunk.
  {{{
  #!/usr/bin/env python
  
@@ -167, +167 @@

  }}}
  
  = PHP =
- Operates only on a standalone server. 
+ Operates only on a standalone server.
  {{{
  <?php
  // set THRIFT_ROOT to php directory of the hive distribution
@@ -189, +189 @@

  }}}
  
  = Thrift Java Client =
- Operates both in embedded mode and on standalone server. 
+ Operates both in embedded mode and on standalone server.
  
  = ODBC =
  Operates only on a standalone server. See [wiki:Self:Hive/HiveODBC HiveODBC].

Mime
View raw message