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

try cursor.execute(query), but execute is not a function? #15

Closed mu009009 closed 6 years ago

mu009009 commented 7 years ago

Hi I'm trying to use this module to connect to a Hiveserver2 DB, and I have tried this code below.

    const options = {
        // Connection configuration
        auth: 'NOSASL',
      host: 'myhost',            // HiveServer2 hostname
      port: '10000',                     // HiveServer2 port
      username: 'root',                      // HiveServer2 user
      password: '12345',          // HiveServer2 password
      hiveType: HS2Util.HIVE_TYPE.HIVE,  // HiveServer2 type, (Hive or CDH Hive)
      hiveVer: '2.1.0',                  // HiveServer2 Version
      thriftVer: '0.9.3',                // Thrift version at IDL Compile time
    };

    let connection;
    let cursor;
    let serviceType;

    const configuration = new Configuration(options);
  const idl = new IDLContainer();

    idl.initialize(configuration).then(() => {
    // your code, ...
        connection = new HiveConnection(configuration, idl);
        cursor = connection.connect();
        serviceType = idl.serviceType;
        console.log(connection);
        console.log(cursor);
        console.log(serviceType);
        cursor.execute('SHOW DATABASES').then((err,result) => {
            console.log('check if run this part');
            console.log(err);               
            console.log(result);
        })
    });

but I received the error that execute is not a function. I think I got some misunderstand with the read me example, and I write those code based on the read me and the test in this module.... hope to get some help thank you

MarineRu commented 7 years ago

I'm writing the same code and I have the same problem. How to fix it ?

mauryaavinash95 commented 6 years ago

I am getting the same error. Is there a workaround for this? Is there something I am doing wrong?

--------------------CODE----------------------

const jshs2 = require('jshs2');
const HS2Util = jshs2.HS2Util;
const IDLContainer = jshs2.IDLContainer;
const HiveConnection = jshs2.HiveConnection;
const Configuration = jshs2.Configuration;

console.log("In server.js");
const options1 = {
        // Connection configuration 
        auth: 'NOSASL',
        host: '127.0.0.1',           // HiveServer2 hostname 
        port: '10000',                     // HiveServer2 port 
        timeout: 10000,                    // Connection timeout 
        username: 'admin',           // HiveServer2 user 
        password: 'admin',                      // HiveServer2 password 
        hiveType: HS2Util.HIVE_TYPE.HIVE,  // HiveServer2 type, (Hive or CDH Hive) 
        hiveVer: '1.1.0',                  // HiveServer2 Version 
        thriftVer: '0.9.2',                // Thrift version at IDL Compile time 
        maxRows: 5120,
        nullStr: 'NULL',
        i64ToString: true,
};
const configure = new Configuration(options1);
const idl = new IDLContainer();
idl.initialize(configure).then(() => {
    connection = new HiveConnection(configure, idl);
        cursor = connection.connect();
    serviceType = idl.ServiceType;
    console.log("Cursor getting initialised", cursor);
    cursor.execute("select * from test.test_table;").then((resolve)=>{
        console.log("Resolved");
    }, (reject)=>{
        console.log("Rejected");
    });
        console.log("In the end");
});

----------------------------OUTPUT--------------------------------- In server.js Cursor getting initialised Promise { <pending> } (node:31149) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: cursor.execute is not a function (node:31149) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

vineetma commented 6 years ago

There are visible two issues in above code: connection.connect()--> it is a promise, which needs to be written differently. connection.connect.then( (cursor) => { /*your cursor related code goes here.. */ });

Similarly, in your cursor code, you would get results. i.e. cursor.execute("sql query..").then( (results) => { /* data handling code goes here..*/ })

It need not have resolve and reject, inside then callback.

mauryaavinash95 commented 6 years ago

Thanks a lot @vineetma . Checked my Thrift hive logs and this code is hitting request, but somehow it is failing as

17/11/25 16:51:31 ERROR TThreadPoolServer: Error occurred during processing of message.
java.lang.RuntimeException: org.apache.thrift.transport.TTransportException: Invalid status -128
    at org.apache.thrift.transport.TSaslServerTransport$Factory.getTransport(TSaslServerTransport.java:219)
    at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:269)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.thrift.transport.TTransportException: Invalid status -128
    at org.apache.thrift.transport.TSaslTransport.sendAndThrowMessage(TSaslTransport.java:232)
    at org.apache.thrift.transport.TSaslTransport.receiveSaslMessage(TSaslTransport.java:184)
    at org.apache.thrift.transport.TSaslServerTransport.handleSaslStartMessage(TSaslServerTransport.java:125)
    at org.apache.thrift.transport.TSaslTransport.open(TSaslTransport.java:271)
    at org.apache.thrift.transport.TSaslServerTransport.open(TSaslServerTransport.java:41)
    at org.apache.thrift.transport.TSaslServerTransport$Factory.getTransport(TSaslServerTransport.java:216)
    ... 4 more

For now, I am using this post to get it done: https://dzone.com/articles/connect-apache-spark-sql-to-nodejs-on-linux-via-jd