1

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

2 回答 2

0

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

结构:TFetchResultsReq(操作句柄:空,方向:FETCH_FIRST,maxRows:1)

于 2013-09-09T20:02:15.507 回答
0

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

于 2016-04-02T16:00:05.963 回答