Retrieving example for jshs2

2019-08-21 15:55发布

I have a working code to fire query on hive using node module "jdbc", as an alternative i was trying "jshs2" , i am able to connect to hive and fire query but still stuck to retrieve the resultset, can anyone who have used the "jshs2", module can put up an example.

Thanks for any help.

标签: node.js hive
1条回答
手持菜刀,她持情操
2楼-- · 2019-08-21 16:51

I just started a project where I have to connect to hive from node too. I was able to run a query on database and iterate through the resultset using the following demo code:

const {
  Configuration,
  HiveConnection,
  IDLContainer,
} = require('jshs2');

const options = {
  auth: 'NOSASL',
  host: 'myServer',
  port: myPort,
};

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

I'm using node v8.x, so I can use ES6 features like destructuring and async/await. If your node version is older you must work with promise chains.

查看更多
登录 后发表回答