node.js - 如何使用Node JS连接Hive服务器

标签 node.js hadoop hive

我正在尝试使用jshs2连接Hive,但无法建立连接。是
正确的方法来使用此npm连接 hive 。我的源代码如下:

const jshs2 = require('jshs2');
const options = {};
options.auth = 'NOSASL';
options.host = 'host name';
options.port = '10000';
options.username = 'user name';
options.password = 'password';
options.hiveType = 2;
const hiveConfig = new Configuration(options);
const idl = new IDLContainer();
async function main() {
        await idl.initialize(hiveConfig);
        const connection = await new HiveConnection(hiveConfig, idl);
        const cursor = await connection.connect();
        const res = await cursor.execute('SELECT * FROM orders LIMIT 10');
        if (res.hasResultSet) {
            const fetchResult = await cursor.fetchBlock();
            fetchResult.rows.forEach((row) => {
                console.log(row);
            });
        }
        cursor.close();
        connection.close();
}
main().then(() => {
        console.log('Finished.');
});

最佳答案

正如您在评论中提到的那样,您使用SASL身份验证,但是jshs2的作者提到该库不支持SASL身份验证(link)

您可以使用java jdbchive-driver在node.js中使用SASL连接Hive

const hive = require('hive-driver');
const { TCLIService, TCLIService_types } = hive.thrift;
const client = new hive.HiveClient(
    TCLIService,
    TCLIService_types
);
const utils = new hive.HiveUtils(
    TCLIService_types
);
 
client.connect(
    {
        host: 'host name',
        port: 10000
    },
    new hive.connections.TcpConnection(),
    new hive.auth.PlainTcpAuthentication({
	    username: 'user name',
	    password: 'password'
    })
).then(async client => {
    const session = await client.openSession({
        client_protocol: TCLIService_types.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V10
    });
    const operation = await session.executeStatement(
        'SELECT * FROM orders LIMIT 10'
    );
    await utils.waitUntilReady(operation, false, () => {});
    await utils.fetchAll(operation);

    console.log(
        utils.getResult(selectDataOperation).getValue()
    );

    await operation.close();
    await session.close();
});

关于node.js - 如何使用Node JS连接Hive服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51708296/

相关文章:

javascript - 如何将变量作为参数传递给 cypher 查询 (neo4j)

node.js - cloudfoundry : how to use filesystem

hadoop - 可以在hadoop YARN中运行的应用程序

apache-spark - Apache Spark 不使用来自 Hive 分区外部表的分区信息

node.js - npm 从私有(private)注册表安装,回退到 git 存储库 URL

javascript - 如果 json 对象具有字符串、 bool 值和数字类型的组合,如何迭代它

hadoop - 查询配置单元表时发生Presto错误

hadoop - 获取空指针异常

hadoop - 使用Hive插入hbase表(Hadoop)

hadoop - Hive:在Hive SQL中转置的方法