私はメソッドを調べてきましたが、Hive のジョブの (eventListener のように!) 完了率を推定する方法を見つけることができないようです。助けてください!編集-クライアントから「マッピングが完了しました... 50%完了しました」を取得できると思いました(コマンドOVERWRITE EXTERNAL TABLEを送信した場合)。OpsCenter と Brisk (Datastax による) はまさにこれを行います。
import java.util.List;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.service.HiveServerException;
import org.apache.hadoop.hive.service.ThriftHive;
import org.apache.hadoop.hive.service.ThriftHive.Client;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.transport.TSocket;
public class Hive {
static Client client;
static TSocket transport;
public static void main(String args[]) throws HiveServerException,
TException, MetaException {
transport = new TSocket("hiveserver",
10000);
transport.setTimeout(999999999);
TBinaryProtocol protocol = new TBinaryProtocol(transport);
client = new ThriftHive.Client(protocol);
transport.open();
System.out.println("Starting map job...");
Thread mapReduceThread = new Thread(new HiveQuery(
"SELECT COUNT(*) FROM myHiveTable"));
mapReduceThread.start();
System.out.println("Waiting on map...");
}
private static class HiveQuery implements Runnable {
private String hql;
public HiveQuery(String hql) {
this.setHql(hql);
}
public void run() {
long start = System.currentTimeMillis();
// Blocking
try {
client.execute(this.getHql());
} catch (HiveServerException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
List<String> responseList = null;
try {
responseList = client.fetchAll();
} catch (HiveServerException e) {
e.printStackTrace();
} catch (TException e) {
e.printStackTrace();
}
long elapsedTimeMillis = System.currentTimeMillis() - start;
float elapsedTime = elapsedTimeMillis / 1000F;
System.out.println("Job took: " + elapsedTime + " seconds");
for (String response : responseList) {
System.out.println("Response: " + response);
}
transport.close();
System.out.println("Closed transport");
System.exit(0);
}
public void setHql(String hql) {
this.hql = hql;
}
public String getHql() {
return hql;
}
}
}