将 node.js 应用程序连接到 hive 时出错 [英] Error in connecting node.js application to hive

查看:14
本文介绍了将 node.js 应用程序连接到 hive 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 node-hive 和 thrift 将我的 node js 应用程序连接到 hive,但它们都不起作用.是否有其他节点模块可以连接到 hive?

I have used node-hive and thrift for connecting my node js application to hive, but none of them works. Are there any other node modules for getting connected to hive ?

推荐答案

As node node-thrift-hivenode-hive 两个模块都被放弃了,还没有提交 4 到 5 年旧的,我有同样的问题,我使用的是 Node 0.12 及以下是我的解决方案.

As node node-thrift-hive and node-hive both module are abandoned, not commit still 4 to 5 year old, I have same issue and I am using Node 0.12 and below is my solutions.

步骤 -1:你必须设置 Hiveserver2 ,我的配置单元版本是 1.2 和 hadoop 版本 2.7

Step -1: You have to setup Hiveserver2 , my hive version is 1.2 and hadoop version 2.7

https://cwiki.apache.org/confluence/display/Hive/Setting+Up+HiveServer2

如果您不想遵循第 1 步,请将您的节点 js 升级到 4.5 > 并使用 jshs2npm

If you don't want to follow Step-1 then upgrade your node js to 4.5 > and use jshs2 npm

就我而言,我不想升级我的节点版本,所以我尝试通过 JDBC 驱动程序连接 JDBC npm

In my case I don't want to upgrade my node version so I try to connect via JDBC drivers JDBC npm

第 2 步:使用下面的代码连接 hive 并获取数据

Step-2: Use Below code to connect hive and fetch the data

var JDBC = require('jdbc');
var jinst = require('jdbc/lib/jinst');

// isJvmCreated will be true after the first java call.  When this happens, the
// options and classpath cannot be adjusted.
if (!jinst.isJvmCreated()) {
  // Add all java options required by your project here.  You get one chance to
  // setup the options before the first java call.
  jinst.addOption("-Xrs");
  // Add all jar files required by your project here.  You get one chance to
  // setup the classpath before the first java call.
  jinst.setupClasspath(['./drivers/hsqldb.jar',
                        './drivers/derby.jar',
                        './drivers/derbyclient.jar',
                        './drivers/derbytools.jar',
                        './lib/drivers/hive-jdbc-1.2.1.jar',
                        './lib/drivers/hive-exec-1.2.1.jar',
                        './lib/drivers/hive-common-1.2.1.jar',
                        './lib/drivers/hive-metastore-1.2.1.jar',
                        './lib/drivers/hive-service-1.2.1.jar',
                        './lib/drivers/httpclient-4.3.jar',
                        './lib/drivers/httpcore-4.3.jar',
                        './lib/drivers/libthrift-0.9.1.jar',
                        './lib/drivers/libfb303-0.9.0.jar',
                        './lib/drivers/hadoop-common-2.7.1.jar',
                        './lib/drivers/slf4j-api-1.7.21.jar',
                        './lib/drivers/org-apache-commons-logging.jar'
                        ]);
}

var config = {
  url: 'jdbc:hive2://127.0.0.1:10000',
  user : 'demo',
  password: '',
  minpoolsize: 2,
  maxpoolsize: 3
};

var testpool = null;
var testconn = null;
var hsqldb = new JDBC(config);

hsqldb.initialize(function(err) {
  if (err) {
    console.log(err);
  }
});

hsqldb.reserve(function(err, connObj) {
     console.log("Using connection: " + connObj.uuid);
     var conn = connObj.conn;
     conn.createStatement(function(err, statement) {
        statement.executeQuery("select * from test1 limit 1",function(err,resultSet){
            //console.log(resultSet);
            resultSet.toObjArray(function(err, results) {
                console.log(results);
            });

        });
     });    
}); 

这篇关于将 node.js 应用程序连接到 hive 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆