如何使用node js连接配置单元服务器

wf82jlnq  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(346)

我正在尝试使用jshs2连接配置单元,但无法建立连接。这是正确的方式来连接Hive使用这个npm。我的源代码如下:

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.');
});
0md85ypi

0md85ypi1#

正如您在评论中提到的,您使用sasl auth,但是jshs2的作者提到lib不支持sasl身份验证(link)
您可以使用javajdbc或hive驱动程序在nodejs中使用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();
});

相关问题