}
// query execute
try {
QueryStatus status;
int initRetries = 0;
int progressRetries = 0;
while (true) {
// TODO - configurable
status = client.getQueryStatus(queryId);
if(status.getState() == QueryState.QUERY_MASTER_INIT || status.getState() == QueryState.QUERY_MASTER_LAUNCHED) {
Thread.sleep(Math.min(20 * initRetries, 1000));
initRetries++;
continue;
}
if (status.getState() == QueryState.QUERY_RUNNING || status.getState() == QueryState.QUERY_SUCCEEDED) {
sout.println("Progress: " + (int)(status.getProgress() * 100.0f)
+ "%, response time: " + ((float)(status.getFinishTime() - status.getSubmitTime()) / 1000.0) + " sec");
sout.flush();
}
if (status.getState() != QueryState.QUERY_RUNNING &&
status.getState() != QueryState.QUERY_NOT_ASSIGNED &&
status.getState() != QueryState.QUERY_KILL_WAIT) {
break;
} else {
Thread.sleep(Math.min(200 * progressRetries, 1000));
progressRetries += 2;
}
}
if (status.getState() == QueryState.QUERY_ERROR) {
sout.println("Internal error!");
if(status.getErrorMessage() != null && !status.getErrorMessage().isEmpty()) {
sout.println(status.getErrorMessage());
}
} else if (status.getState() == QueryState.QUERY_FAILED) {
sout.println("Query failed!");
} else if (status.getState() == QueryState.QUERY_KILLED) {
sout.println(queryId + " is killed.");
} else {
if (status.getState() == QueryState.QUERY_SUCCEEDED) {
sout.println("final state: " + status.getState()
+ ", response time: " + (((float)(status.getFinishTime() - status.getSubmitTime()) / 1000.0)
+ " sec"));
if (status.hasResult()) {
ClientProtos.GetQueryResultResponse response = client.getResultResponse(queryId);
ResultSet res = TajoClient.createResultSet(client, queryId, response);
TableDesc desc = new TableDesc(response.getTableDesc());
long totalRowNum = desc.getStats().getNumRows();
long totalBytes = desc.getStats().getNumBytes();