【问题标题】:Hive Server 2 thrift Client error: Required field 'operationHandle' is unsetHive Server 2 thrift Client 错误:必填字段 'operationHandle' 未设置
【发布时间】:2013-09-09 19:07:34
【问题描述】:

我正在尝试在 CDH 4.3 上的 hive server2 上运行以下 hive thrift 代码并出现以下错误。这是我的代码:我可以成功地运行 hive jdbc 连接到同一台服务器,它只是不工作的节俭。

public static void main(String[] args) throws Exception
{
   TSocket transport = new TSocket("my.org.hiveserver2.com",10000);
   transport.setTimeout(999999999);
   TBinaryProtocol protocol = new TBinaryProtocol(transport);
   TCLIService.Client client = new TCLIService.Client(protocol);

   transport.open();

   TOpenSessionReq openReq = new TOpenSessionReq();
   TOpenSessionResp openResp = client.OpenSession(openReq);
   TSessionHandle sessHandle = openResp.getSessionHandle();
   TExecuteStatementReq execReq = new TExecuteStatementReq(sessHandle, "SELECT * FROM testhivedrivertable");
   TExecuteStatementResp execResp = client.ExecuteStatement(execReq);
   TOperationHandle stmtHandle = execResp.getOperationHandle();
   TFetchResultsReq fetchReq = new TFetchResultsReq(stmtHandle, TFetchOrientation.FETCH_FIRST, 1);
   TFetchResultsResp resultsResp = client.FetchResults(fetchReq);

   TRowSet resultsSet = resultsResp.getResults();
   List<TRow> resultRows = resultsSet.getRows();
   for(TRow resultRow : resultRows){
       resultRow.toString();
   }

   TCloseOperationReq closeReq = new TCloseOperationReq();
   closeReq.setOperationHandle(stmtHandle);
   client.CloseOperation(closeReq);
   TCloseSessionReq closeConnectionReq = new TCloseSessionReq(sessHandle);
   client.CloseSession(closeConnectionReq);

   transport.close();

}

这是错误日志:

Exception in thread "main" org.apache.thrift.protocol.TProtocolException: Required field 'operationHandle' is unset! Struct:TFetchResultsReq(operationHandle:null, orientation:FETCH_FIRST, maxRows:1)
        at org.apache.hive.service.cli.thrift.TFetchResultsReq.validate(TFetchResultsReq.java:465)
        at org.apache.hive.service.cli.thrift.TCLIService$FetchResults_args.validate(TCLIService.java:12607)
        at org.apache.hive.service.cli.thrift.TCLIService$FetchResults_args$FetchResults_argsStandardScheme.write(TCLIService.java:12664)
        at org.apache.hive.service.cli.thrift.TCLIService$FetchResults_args$FetchResults_argsStandardScheme.write(TCLIService.java:12633)
        at org.apache.hive.service.cli.thrift.TCLIService$FetchResults_args.write(TCLIService.java:12584)
        at org.apache.thrift.TServiceClient.sendBase(TServiceClient.java:63)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.send_FetchResults(TCLIService.java:487)
        at org.apache.hive.service.cli.thrift.TCLIService$Client.FetchResults(TCLIService.java:479)
        at HiveJDBCServer1.main(HiveJDBCServer1.java:26)

【问题讨论】:

标签: hadoop mapreduce hive thrift cloudera


【解决方案1】:

您确定将 operationsHandle 字段设置为有效值吗? Thrift 错误表明它所说的内容:API 期望设置某个字段(在您的情况下为 operationHandle),该字段尚未分配值。你的堆栈跟踪证实了这一点:

Struct:TFetchResultsReq(operationHandle:null,orientation:FETCH_FIRST, 最大行数:1)

【讨论】:

  • @liunkor :我正在使用 hiveserver2,我知道 hive server1 可以工作,因为我有其他应用程序可以在 hiveserver 1 上正常工作。
  • 没有设置OperationHandle是对的。这就是为什么TOperationHandle stmtHandle = execResp.getOperationHandle();没有设置操作句柄的原因。
  • 有没有人用 HIVERSERVER2 成功构建过 thrift 客户端。
【解决方案2】:

如果有人发现这个,就像我一样,通过谷歌搜索错误消息:我在 hiverserver2 的 PHP Thrift 库中遇到了类似的问题。至少在我的情况下,execResp.getOperationHandle() 返回 NULL,因为在生成 execResp 的执行请求中存在错误。由于某种原因,这并没有引发异常,在尝试获取操作句柄之前,我必须详细检查 execResp,并专门检查状态。

【讨论】:

    猜你喜欢
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 2016-07-04
    • 2012-08-07
    相关资源
    最近更新 更多