使用Javascript从Hive访问Cosmos数据

时间:2014-10-14 16:49:27

标签: javascript fiware

我正在试图通过使用javascript来创建Web界面来访问存储在Cosmos中的数据。我知道有一个java代码可用于与Hive进行查询。该代码如下所示:

    private Connection getConnection(
      String ip, String port, String user, String password) {
   try {
      // dynamically load the Hive JDBC driver
      Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver");
   } catch (ClassNotFoundException e) {
      System.out.println(e.getMessage());
      return null;
   } // try catch

   try {
      // return a connection based on the Hive JDBC driver, default DB
      return DriverManager.getConnection("jdbc:hive://" + ip + ":" +
         port + "/default?user=" + user + "&password=" + password);
   } catch (SQLException e) {
      System.out.println(e.getMessage());
      return null;
   } // try catch
} // getConnection


    private void doQuery() {
   try {
      // from here on, everything is SQL!
      Statement stmt = con.createStatement();
      ResultSet res = stmt.executeQuery("select column1,column2," +
         "otherColumns from mytable where column1='whatever' and " +
         "columns2 like '%whatever%'");

      // iterate on the result
      while (res.next()) {
         String column1 = res.getString(1);
         Integer column2 = res.getInteger(2);
         // whatever you want to do with this row, here
      } // while

      // close everything
      res.close(); stmt.close(); con.close();
   } catch (SQLException ex) {
      System.exit(0);
   } // try catch
} // doQuery

我需要知道如何在javascript中实现该代码,我知道这是可能的,但我不知道如何。

谢谢!

1 个答案:

答案 0 :(得分:0)

从Hive 0.13开始,JavaScript客户端可以使用Thrift library在Http之上发送Thrift RPC消息。问题是FIWARE LAB中当前版本的Hive是0.9,因此必须更新。我们目前working on it,因为这也是Wirecloud-based Hive client的要求。请继续关注!