本文介绍了使用Hive从Javascript访问Cosmos数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm triying to access data stored in Cosmos by using javascript to create a web interface. I know there's a java code available to make query's with Hive. That code is shown below:

    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中实现该代码,我知道有可能,但我不知道如何.

I need to know how to implement that code in javascript, I know it's possible but I don't know how.

谢谢!

推荐答案

从Hive 0.13开始,JavaScript客户端可以使用 Thrift库,以便在Http顶部发送Thrift RPC消息.问题是FIWARE LAB中Hive的当前版本是0.9,因此必须更新.我们目前正在对其进行研究,因为这是.敬请期待!

Starting from Hive 0.13, a JavaScript client may use the Thrift library in order to send Thrift RPC messages on top of Http. The problem is the current version of Hive in FIWARE LAB is 0.9, and thus it must be updated. We are currently working on it, because this is a requiremente for a Wirecloud-based Hive client as well. Stay tuned!

这篇关于使用Hive从Javascript访问Cosmos数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:36