Impala thrift API接口使用事例

来源:互联网 发布:windows键是哪个键 编辑:程序博客网 时间:2024/06/10 14:43

直接看代码

        public void impalaQuery() throws Exception {TSocket transport = new TSocket("10.17.36.93", 21000);transport.open();TProtocol protocol = new TBinaryProtocol(transport);// connect to clientImpalaService.Client client = new ImpalaService.Client(protocol);client.PingImpalaService();// send the queryQuery query = new Query(); query.setQuery("SELECT * FROM wux_test_10000 limit 1000");// fetch the resultsclient.send_query(query);   queryHandle = client.recv_query();String log = client.get_log(queryHandle.getLog_context());System.out.println(log);//查询结果Results results = client.fetch(queryHandle, false, 5);List<String> data = results.data;for (int i = 0; i < data.size(); i++) {System.out.println(data.get(i));}}public void impalaGetLog() throws Exception {System.out.println("获取日志");TSocket transport = new TSocket(host, port);transport.open();TProtocol protocol = new TBinaryProtocol(transport);// connect to clientImpalaService.Client client = new ImpalaService.Client(protocol);client.PingImpalaService();String log = client.get_log(queryHandle.getLog_context());System.out.println(log);}public void impalaGetStatu() throws Exception {System.out.println("获取状态:");TSocket transport = new TSocket(host, port);transport.open();TProtocol protocol = new TBinaryProtocol(transport);// connect to clientImpalaService.Client client = new ImpalaService.Client(protocol);client.PingImpalaService();QueryState qs = client.get_state(queryHandle);System.out.println(qs);}public void canel() throws Exception {TSocket transport = new TSocket(host, port);transport.open();TProtocol protocol = new TBinaryProtocol(transport);// connect to clientImpalaService.Client client = new ImpalaService.Client(protocol);client.PingImpalaService();TStatus ts = client.Cancel(queryHandle);System.out.println(ts);}

以上代码是impala自己的thrift接口,但是这套接口有个问题,就是不支持异步查询,而另外一套是基于hiveserver2的,可以支持异步查询,只要修改以下代码就行


TCLIService.Client client = new ImpalaHiveServer2Service.Client(protocol);

这样就可以用hiveserver2的api来操作impala了



0 0