hive-cdh5.7以后版本,程序使用hive接口进行查询,如何获取查询日志?
五哥 2017-07-14 05:10:28 hive CHD 5.7版本前使用:
public String getQueryLog(TOperationHandle tOperationHandle) throws Exception {
//TCLIService.Client client;
if(tOperationHandle!=null){
TGetLogReq tGetLogReq = new TGetLogReq(tOperationHandle);
TGetLogResp logResp = client.GetLog(tGetLogReq);
log = logResp.getLog();
}
return log;
}
使用hive-service-0.12.0-cdh5.01.jar中的类
但是CDH5.7后,hive-service中的TCLIService.Client 中不在提供GetLog方法了,不知道有什么办法可以获取吗 ?
我查看了hive-exec-1.1.0-cdh5.12.0-core.jar中,org.apache.hive.service.cli.thrift;-ThriftCLIService
/**
*
* @param client
* 连接thriftserver的客户端
* @param operationHandle
* 当前操作对应句柄
* @param Orientation
* 获取结果的起始位置 FetchOrientation.First 从结果第一行开始取2
* @param fetchType
* 获取结果的类型 FetchType.LOG 获取此操作对应日志
* @param maxRows
* 此次获取的最大行数
* @return
*/
public static TRowSet fetchResult(TCLIService.Client client, TOperationHandle operationHandle,
FetchOrientation Orientation, FetchType fetchType, long maxRows) {
TFetchResultsReq fetchReq = new TFetchResultsReq();
fetchReq.setFetchType(fetchType.toTFetchType());
fetchReq.setMaxRows(maxRows);
fetchReq.setOperationHandle(operationHandle);
fetchReq.setOrientation(Orientation.toTFetchOrientation());
TRowSet rowSetLog = null;
try {
rowSetLog = client.FetchResults(fetchReq).getResults();
} catch (TException e) {
log.info("Exception:" + e.getStackTrace());
e.printStackTrace();
}
return rowSetLog;
}
好像可以,不知道有没有哪位大神,有弄过过的,分享一下,谢谢