java Java Hive Thrift Client拉取Hive日志代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java Java Hive Thrift Client拉取Hive日志代码相关的知识,希望对你有一定的参考价值。

public static void main(String[] args) throws TException, SaslException {
		TTransport transport = HiveAuthFactory.getSocketTransport("xx.xx.xx.xx", 10000,99999);
		transport = PlainSaslHelper.getPlainTransport("xxx", "xxx", transport);
		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();

		String sql = "select count(*) from table ";
		TExecuteStatementReq req = new TExecuteStatementReq(sessHandle, sql);
		req.setRunAsync(true);
		TExecuteStatementResp executeStatementResp = client.ExecuteStatement(req);

		while (true) {
			TGetOperationStatusReq getOperationStatusReq = new TGetOperationStatusReq(executeStatementResp.getOperationHandle());
			TGetOperationStatusResp getOperationStatusResp = client.GetOperationStatus(getOperationStatusReq);

			TStatus status = getOperationStatusResp.getStatus();
			System.out.println(getOperationStatusResp.getOperationState());
//			if ((status.getStatusCode() == TStatusCode.SUCCESS_STATUS || status.getStatusCode() == TStatusCode.SUCCESS_WITH_INFO_STATUS) && getOperationStatusResp.getOperationState() == TOperationState.FINISHED_STATE) {
//				break;
//			}
			TFetchResultsReq tFetchResultsReq = new TFetchResultsReq(executeStatementResp.getOperationHandle(), TFetchOrientation.FETCH_NEXT, 100);
			tFetchResultsReq.setFetchType((short)1);//0是获取数据,1是数据日志
			TFetchResultsResp tFetchResultsResp = client.FetchResults(tFetchResultsReq);
			RowSet rowSet = RowSetFactory.create(tFetchResultsResp.getResults(),openResp.getServerProtocolVersion());
			for (Object[] objects : rowSet) {
				System.out.println(objects[0]);
			}
			try {
				TimeUnit.SECONDS.sleep(10);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}

//		TFetchResultsReq tFetchResultsReq = new TFetchResultsReq(executeStatementResp.getOperationHandle(), TFetchOrientation.FETCH_FIRST, 100);
//		tFetchResultsReq.setFetchType((short)1);//0是获取数据,1是数据日志
//		TFetchResultsResp tFetchResultsResp = client.FetchResults(tFetchResultsReq);
//		RowSet rowSet = RowSetFactory.create(tFetchResultsResp.getResults(),openResp.getServerProtocolVersion());
//		for (Object[] objects : rowSet) {
//			System.out.println(objects[0]);
//		}




	}

以上是关于java Java Hive Thrift Client拉取Hive日志代码的主要内容,如果未能解决你的问题,请参考以下文章

hive安装失败,提示找不到类 org/apache/thrift/TException

hive jdbc连接不成功。。报错org.apache.thrift.transport.TTransportException: Invalid status -128

Hive JDBC 错误:java.lang.NoSuchFieldError:HIVE_CLI_SERVICE_PROTOCOL_V7

JAVA 中的 Hive JDBC 连接

1Java通过JDBC操作Hive

❤️Hive的基本知识❤️