Hive - Thrift - readMessageBegin中丢失的版本,旧客户端?

时间:2016-02-17 09:56:11

标签: javascript node.js hadoop hive thrift

您好我正在尝试使用thrift构建一个nodejs客户端来查询我的hive数据库,但是我遇到了一个奇怪的问题......我已经用thrift生成了我的nodejs客户端API({{ 1}} TCLIService是定义Hive服务的thrift文件)现在我尝试连接到Hive,但我的OpenSession正在等待......也许我没有做正确的电话,但我找不到任何东西最近在网上(每个节俭/节点/蜂房项目是4或5年)。你能看一看并告诉我,我做错了吗?谢谢

TCLIService.thrift:

thrift -r --gen js:node TCLIService.thrift

Nodejs代码:     var sessionHandle ='';

// OpenSession()
//
// Open a session (connection) on the server against
// which operations may be executed.
struct TOpenSessionReq {
    // The version of the HiveServer2 protocol that the client is using.
    1: required TProtocolVersion client_protocol = TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8

    // Username and password for authentication.
    // Depending on the authentication scheme being used,
    // this information may instead be provided by a lower
    // protocol layer, in which case these fields may be
    // left unset.
    2: optional string username
    3: optional string password

    // Configuration overlay which is applied when the session is
    // first created.
    4: optional map<string, string> configuration
}

service TCLIService {
    TOpenSessionResp OpenSession(1:TOpenSessionReq req);
}

我的输出如下:

function openSession(config) {
    openSessReq = new ttypes.TOpenSessionReq();
    openSessReq.client_protocol = ttypes.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V8;
    openSessReq.username = config.hiveUser;
    openSessReq.password = config.hivePassword;
    console.log("openSessReq = " + JSON.stringify(openSessReq));
    console.log("Before OpenSession : sessionHandle = " + sessionHandle);
    sessionHandle = client.OpenSession(openSessReq, function (err, result){
        console.log('handler fired ... ');
        if (err) {
            console.error("error : " + err);
        } else {
            console.log("result : " + result);
        }
    });
    console.log("After OpenSession : sessionHandle = " + sessionHandle);
}

connection.on('error', function(err) {
    /*Error detected, print the error*/
    console.error(err);
    /*Close the program with error code*/
    process.exit(1)
});

console.log('Error handler registered ...')

connection.on('connect', function(){
    console.log('Connected ...');
    /*Init session*/
    console.log(client);
    openSession(config);
}

脚本无限期运行...如果我更改端口或关闭HiveServer我面临错误,因此连接正常,但我无法找出openSession为什么不行!谢谢你的帮助

编辑: 我已经检查了我的日志,并且NOSASL标识是问题...我已修复(我认为)此问题,现在收到以下错误:

客户:

CreateConnection DONE ...
Error handler registered ...
Connect handler registered ...
Connected ...
{ output:
   TBufferedTransport {
     defaultReadBufferSize: 1024,
     writeBufferSize: 512,
     inBuf: <Buffer e8 19 2b 03 00 00 00 00 b0 1a 2b 03 00 00 00 00 e8 18 2b 03 00 00 00 00 f0 18 2b 03 00 00 00 00 b0 19 2b 03 00 00 00 00 78 1a 2b 03 00 00 00 00 70 1d ... >,
     readCursor: 0,
     writeCursor: 0,
     outBuffers: [],
     outCount: 0,
     onFlush: [Function],
     client: [Circular] },
  pClass: [Function: TBinaryProtocol],
  _seqid: 0,
  _reqs: {} }
openSessReq = {"client_protocol":7,"username":"root","password":"root","configuration":null}
Before OpenSession : sessionHandle =
After OpenSession : sessionHandle = undefined
^C

服务器:

{ [Error: write EPIPE]
 code: 'EPIPE',
 errno: 'EPIPE',
 syscall: 'write',
 address: undefined }

我已经读过必须通过使用错误的协议层来提出问题...我使用TBinaryProtocol是一个问题吗?

2 个答案:

答案 0 :(得分:0)

我通过执行以下操作解决了我的问题:

使用beewax检查我的HiveServer2的协议版本并查询我的HiveServer2(使用Hue)并检查HiveServer2日志(我发现Hive为0.15.0的HIVE_CLI_SERVICE_PROTOCOL_V7)

通过修改hive-site.xml

在我的HiveServer2上启用NOSASL身份验证

答案 1 :(得分:0)

尝试检查环境的三个部分,默认情况下,这三个部分都位于同一个配置文件(hive-site.xml)中:

  1. transportMode 检查hive.server2.transport.mode,您必须在服务和客户端使用相同的模式。

  2. ssl启用 检查hive.server2.use.SSL,您可以尝试关闭以确保与此配置无关。

  3. AUTH 检查hive.server2.authentication,因为有多种类型(NONE,NOSASL,KERBEROS,LDAP,CUSTOM)的auth模式,请确保使用正确的模式。

  4. PS。您可以尝试通过控制台连接到您的hs2,看看服务器是否有任何问题。