Hive Server 2 thrift客户端错误:未设置必填字段'operationHandle'

时间:2013-09-09 19:07:34

标签: hadoop mapreduce hive thrift cloudera

我正在尝试在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)

2 个答案:

答案 0 :(得分:0)

您确定将operationsHandle字段设置为有效值吗? Thrift eror表示它的含义:API期望设置某个字段(在您的情况下为operationHandle),该字段尚未赋值。而堆栈跟踪证实了这一点:

  

Struct:TFetchResultsReq( operationHandle:null ,orientation:FETCH_FIRST,   maxRows进行:1)

答案 1 :(得分:0)

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