npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hs2-thrift

v1.0.11

Published

Hive Server 2 client using Apache Thrift RPC able to query Impala for Javascript.

Downloads

25

Readme

Hive Server 2 Thrift

Hive Server 2 client using Apache Thrift RPC able to query Impala written in Javascript.

NOTE: There is currently very limited functionality, it will only query the DB and return a result. More functionality will be added later if required for my project.

HiveServer2 Thrift protocol used fined in latest TCLIService.thrift: https://github.com/apache/hive/blob/master/service-rpc/if/TCLIService.thrift

Getting Started

Prerequisites

  • Nodejs => 10.16.3
  • npm
  • git
  • You know your HiveServer2 Protol Version (package uses V5 as default)

Option 1: Install the npm package and refer to example for usage

npm install hs2-thrift 

Option 2: Clone git repo and install the npm packages detailed in package.json

git clone https://github.com/amroczeK/hs2-thrift.git hs2-thrift
cd hs2-thrift
npm install 

Example 1:

// const client = require("hs2-thrift");  // Use this if example.js is outside hs2-thrift package e.g. used 'npm install hs2-thrift'
const client = require("../index.js");

const config = {
    host: 'example.com.au',   // Change to correspond with your config
    port: 1234,               // Change to correspond with your config
    username: '',             // Change to correspond with your config
    password: '',             // Change to correspond with your config
    protocol_ver: 5,		  // Version 1 - 11. Change to suit your HS2 Protocol Version, defaults to V5
    retain_session: null	  // Set true if you want to retain connection and session
  }

var sqlQuery = "select * from default.temp";  // Change this query to suit your db/table

client.connectAndQuery(config, sqlQuery).then((result) => {
	console.log("Result: " + sqlQuery + " => \n" + JSON.stringify(result));
	// if retain_session == true, connection & session will remain active, process will not close
	if (config.retain_session == null) {
		process.exit(0);
	}
}).catch((error) => {
	console.log(JSON.stringify(error))
	process.exit(1)
})

Example 2:

// const client = require("hs2-thrift");  // Use this if example.js is outside hs2-thrift package e.g. used 'npm install hs2-thrift'
const client = require("../index.js");

const config = {
  host: 'example.com.au',   // Change to correspond with your config
  port: 1234,               // Change to correspond with your config
  username: '',             // Change to correspond with your config
  password: '',             // Change to correspond with your config
  protocol_ver: 5,			// Version 1 - 11. Change to suit your HS2 Protocol Version, defaults to V5
  retain_session: null		// Set true if you want to retain connection and session
}

var sqlQuery = "select * from default.temp";  // Change this query to suit your db/table

async function queryImpala(){
	try {
		const session = await client.connect(config);
		console.log("Session created.")
		const result = await client.query(session, sqlQuery);
		console.log("Result: " + sqlQuery + " => \n" + JSON.stringify(result));
		if (config.retain_session == null) {
			await client.disconnect(session);
			console.log("Disconnected from server and closed session successfully.");
			process.exit(0);
		}
	} catch(error) {
        console.log("Error: " + JSON.stringify(error));
		await client.disconnect(session);
        process.exit(1);
	}
}
queryImpala();

Example output / result

PS C:\dev\javascript_projects\hs2-thrift-example> node .\main.js
Sending query: select * from default.temp
Result: select * from default.temp =>
[[{"col1":1},{"col2":2}],[{"col1":5},{"col2":6}],[{"col1":3},{"col2":4}]]
Attempting to disconnect from server and close session.
Disconnected from server and closed session successfully.

Running the example

node example.js

Troubleshooting errors

Hive connection error : TProtocolException: Required field operationHandle is unset!
// Make sure that the SQL query you are sending is valid and connecting to the correct DB.
// Also make sure the query is valid.

Acknowledgements

Reviewing SistemaStrategy's (https://github.com/SistemaStrategy/HiveThrift) implementation of Apache Hive Thrift was a great help in developing this package.