public ResultSet getQueryResultAndWait(QueryId queryId) throws ServiceException, IOException { if (queryId.equals(TajoIdUtils.NullQueryId)) { return null; } QueryStatus status = getQueryStatus(queryId); while (status != null && isQueryRunnning(status.getState())) { try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } status = getQueryStatus(queryId); } if (status.getState() == QueryState.QUERY_SUCCEEDED) { if (status.hasResult()) { return getQueryResult(queryId); } else { return null; } } else { LOG.error(status.getErrorMessage()); return null; } }
public ResultSet getQueryResult(QueryId queryId) throws ServiceException, IOException { if (queryId.equals(TajoIdUtils.NullQueryId)) { return null; } TableDesc tableDesc = getResultDesc(queryId); return new ResultSetImpl(conf, tableDesc.getPath()); }
public TableDesc getResultDesc(QueryId queryId) throws ServiceException { if (queryId.equals(TajoIdUtils.NullQueryId)) { return null; } GetQueryResultRequest.Builder builder = GetQueryResultRequest.newBuilder(); builder.setQueryId(queryId.getProto()); GetQueryResultResponse response = service.getQueryResult(null, builder.build()); return TCatUtil.newTableDesc(response.getTableDesc()); }
/** * It submits a query statement and get a response. The main difference from {@link * #executeQuery(String)} is a blocking method. So, this method is wait for the finish of the * submitted query. * * @return If failed, return null. */ public ResultSet executeQueryAndGetResult(String tql) throws ServiceException, IOException { QueryRequest.Builder builder = QueryRequest.newBuilder(); builder.setQuery(tql); SubmitQueryRespose response = service.submitQuery(null, builder.build()); QueryId queryId = new QueryId(response.getQueryId()); if (queryId.equals(TajoIdUtils.NullQueryId)) { return null; } return getQueryResultAndWait(queryId); }