我想以異步方式在服務器上執行Hive查詢。 Hive查詢可能需要很長時間才能完成,因此我不希望阻止該呼叫。我目前使用Thirft進行阻塞調用(在client.execute()上的阻塞),但我還沒有看到如何進行非阻塞調用的示例。這裏是阻止代碼:如何在Java中對Hive進行異步調用?
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不是很瞭解,但不能將它包裝在可運行的程序中並創建一個新線程? – brindy 2010-02-02 02:10:44
是的,我很清楚自己可以完成這項工作,但是有些事情讓我覺得它已經嵌入到Thrift中,比如TNonblockingSocket。我找不到如何使用它的任何示例,或者即使Hive支持它。 – 2010-02-02 17:38:58