【发布时间】:2011-01-11 23:50:28
【问题描述】:
我想以异步方式在服务器上执行 Hive 查询。 Hive 查询可能需要很长时间才能完成,所以我不想阻止调用。我目前正在使用 Thirft 进行阻塞调用(client.execute() 上的阻塞),但我还没有看到如何进行非阻塞调用的示例。这是阻塞代码:
TSocket transport = new TSocket("hive.example.com", 10000);
transport.setTimeout(999999999);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
Client client = new ThriftHive.Client(protocol);
transport.open();
client.execute(hql); // Omitted HQL
List<String> rows;
while ((rows = client.fetchN(1000)) != null) {
for (String row : rows) {
// Do stuff with row
}
}
transport.close();
上面的代码缺少 try/catch 块以保持简短。
有人知道如何进行异步调用吗? Hive/Thrift 可以支持吗?有没有更好的办法?
谢谢!
【问题讨论】:
-
我现在对 Thrift 还不是很了解,但是你不能把它包装在一个 runnable 中并创建一个新的 Thread 吗?
-
是的,很明显我可以自己完成这项工作,但有些东西让我觉得它已经内置在 Thrift 中,比如 TNonblockingSocket。我找不到任何关于如何使用它的例子,或者即使 Hive 支持它。
标签: java asynchronous rpc thrift hive