imjuni / jshs2

jsHS2 is a node.js client driver for hive server 2
http://imjuni.github.io/jshs2/
MIT License
34 stars 12 forks source link

question: is this library used for querying or for management? #8

Closed jcollum closed 7 years ago

jcollum commented 8 years ago

Seems like it's used for server management, not querying. The docs are a little unclear on it though.

imjuni commented 8 years ago

jshs2 is hive server2 client library, for querying. That is not suitable server management.

jcollum commented 8 years ago

I might be missing it in the docs. Is there a sample of using this to do something like SELECT * from tableName? I can't find it in the docs or the tests.

imjuni commented 8 years ago

in my testcase PromiseTest.js (similar in README.md),

var options = {};

options.auth = config[config.use].auth;
options.host = config[config.use].host;
options.port = config[config.use].port;
options.timeout = config[config.use].timeout;
options.username = config[config.use].username;
options.hiveType = config[config.use].hiveType;
options.hiveVer = config[config.use].hiveVer;
options.cdhVer = config[config.use].cdhVer;
options.thriftVer = config[config.use].thriftVer;

options.maxRows = config[config.use].maxRows;
options.nullStr = config[config.use].nullStr;
options.i64ToString = config[config.use].i64ToString;

testConf.config = config;
testConf.jshs2 = options;

set your environment,

configuration = new Configuration(testConf.jshs2);

yield configuration.initialize();

initialize jshs2 object,

connection = new Connection(configuration);
cursor = yield connection.connect();

create connection,

serviceType = cursor.getConfigure().getServiceType();
execResult = yield cursor.execute(testConf.config.Query.query);
for (i = 0, len = 1000; i < len; i++) {
status = yield cursor.getOperationStatus();
log = yield cursor.getLog();

debug('wait, status -> ', hs2util.getState(serviceType, status));
debug('wait, log -> ', log);

if (hs2util.isFinish(cursor, status)) {
  debug('Status -> ', status, ' -> stop waiting');

  break;
}

yield hs2util.pSleep(10000);
}

execute and check operation status.

if (execResult.hasResultSet) {
  schema = yield cursor.getSchema();

  debug('schema -> ', schema);

  fetchResult = yield cursor.fetchBlock();

  debug('first row ->', JSON.stringify(fetchResult.rows[0]));
  debug('rows ->', fetchResult.rows.length);
  debug('rows ->', fetchResult.hasMoreRows);
}

fetch data

return {
  hasResultSet: execResult.hasResultSet,
  rows: (execResult.hasResultSet) ? fetchResult.rows : []
};

return data for callee

Everything in my testcase PromiseTest.js. If you use old node.js version, use callback version.

jcollum commented 7 years ago

In your Example code, where is cursor defined?

const execResult = yield cursor.execute(config.Query.query);

imjuni commented 7 years ago

Plz, see my answer,

connection = new Connection(configuration);
cursor = yield connection.connect();

That is cursor.

jcollum commented 7 years ago

The example is confusing because the cursor is never initialized, where is the let/var/const? I can figure that out of course.

It's also odd that a connect function would return a cursor -- I think of a cursor as a set of results you can iterate through (paging etc), not a connection.

The library would be more readable if it was more like:

connection = new Connection(configuration);
cursor = yield connection.query(query);

// iterate first set of results in cursor 
// or use a while hasResults loop 
jcollum commented 7 years ago

In your Example in the README on this line:

const execResult = yield cursor.execute(config.Query.query);

This will always fail because cursor is null. The example seems to be missing something.

wuwanyu commented 7 years ago

Very Agree ! Maybe you can make a littler example,this doc is difficult for those who are not familiar with Promise

jcollum commented 7 years ago

@wuwanyu we've decided that webhcat will work better for our needs, we just need to set up a server to listen for web callbacks