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);
});
});
});
});
2条答案
按热度按时间szqfcxe21#
由于node-node-thrift-hive和node-hive这两个模块都被放弃了,还没有提交4到5年,我有同样的问题,我正在使用node 0.12和以下是我的解决方案。
第一步:你必须安装hiveserver2,我的配置单元版本是1.2,hadoop版本是2.7
https://cwiki.apache.org/confluence/display/hive/setting+up+hiveserver2
如果您不想遵循步骤1,那么请将节点js升级到4.5>并使用jshs2npm
在我的例子中,我不想升级我的节点版本,所以我尝试通过jdbc驱动程序jdbc npm进行连接
步骤2:使用下面的代码连接配置单元并获取数据
gstyhher2#
如果不可能使用java,并且必须使用sasl身份验证连接到hive服务器,那么可以使用npm lib
hive-driver
下面是一个用法示例: