Closed jcollum closed 7 years ago
jshs2 is hive server2 client library, for querying. That is not suitable server management.
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.
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.
In your Example code, where is cursor defined?
const execResult = yield cursor.execute(config.Query.query);
Plz, see my answer,
connection = new Connection(configuration);
cursor = yield connection.connect();
That is cursor.
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
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.
Very Agree ! Maybe you can make a littler example,this doc is difficult for those who are not familiar with Promise
@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
Seems like it's used for server management, not querying. The docs are a little unclear on it though.