Example #1
0
  public GetQueryResultResponse getResultResponse(QueryId queryId) throws ServiceException {
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
      return null;
    }

    NettyClientBase client = null;
    try {
      InetSocketAddress queryMasterAddr = queryMasterMap.get(queryId);
      if (queryMasterAddr == null) {
        LOG.warn("No Connection to QueryMaster for " + queryId);
        return null;
      }
      client = connPool.getConnection(queryMasterAddr, QueryMasterClientProtocol.class, false);
      QueryMasterClientProtocolService.BlockingInterface queryMasterService = client.getStub();
      GetQueryResultRequest.Builder builder = GetQueryResultRequest.newBuilder();
      builder.setQueryId(queryId.getProto());
      GetQueryResultResponse response = queryMasterService.getQueryResult(null, builder.build());

      return response;
    } catch (Exception e) {
      throw new ServiceException(e.getMessage(), e);
    } finally {
      connPool.releaseConnection(client);
    }
  }
Example #2
0
  public ResultSet getQueryResultAndWait(QueryId queryId) throws ServiceException, IOException {
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
      return createNullResultSet(queryId);
    }
    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 createNullResultSet(queryId);
      }

    } else {
      LOG.warn("Query (" + status.getQueryId() + ") failed: " + status.getState());

      // TODO throw SQLException(?)
      return createNullResultSet(queryId);
    }
  }
Example #3
0
 public ResultSet getQueryResult(QueryId queryId) throws ServiceException, IOException {
   if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
     return createNullResultSet(queryId);
   }
   GetQueryResultResponse response = getResultResponse(queryId);
   TableDesc tableDesc = CatalogUtil.newTableDesc(response.getTableDesc());
   conf.setVar(ConfVars.USERNAME, response.getTajoUserName());
   return new TajoResultSet(this, queryId, conf, tableDesc);
 }
Example #4
0
  /**
   * 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(final String sql) throws ServiceException, IOException {
    GetQueryStatusResponse response =
        new ServerCallable<GetQueryStatusResponse>(
            connPool, tajoMasterAddr, TajoMasterClientProtocol.class, false, true) {
          public GetQueryStatusResponse call(NettyClientBase client) throws ServiceException {
            final QueryRequest.Builder builder = QueryRequest.newBuilder();
            builder.setQuery(sql);
            TajoMasterClientProtocolService.BlockingInterface tajoMasterService = client.getStub();
            return tajoMasterService.submitQuery(null, builder.build());
          }
        }.withRetries();

    QueryId queryId = new QueryId(response.getQueryId());
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
      return this.createNullResultSet(queryId);
    } else {
      return this.getQueryResultAndWait(queryId);
    }
  }