Example #1
0
 @Override
 public int compareTo(QueryId queryId) {
   int compVal = getApplicationId().compareTo(queryId.getApplicationId());
   if (compVal != 0) {
     return compVal;
   } else {
     return getAttemptId() - queryId.getAttemptId();
   }
 }
Example #2
0
 @Override
 public boolean equals(Object obj) {
   if (this == obj) return true;
   if (obj == null) return false;
   if (getClass() != obj.getClass()) return false;
   QueryId other = (QueryId) obj;
   if (!this.getApplicationId().equals(other.getApplicationId())) return false;
   if (this.getAttemptId() != other.getAttemptId()) return false;
   return true;
 }
Example #3
0
  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());
  }
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(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);
  }
Example #5
0
  public boolean killQuery(QueryId queryId) throws ServiceException, IOException {

    QueryStatus status = getQueryStatus(queryId);

    try {
      /* send a kill to the TM */
      service.killQuery(null, queryId.getProto());
      long currentTimeMillis = System.currentTimeMillis();
      long timeKillIssued = currentTimeMillis;
      while ((currentTimeMillis < timeKillIssued + 10000L)
          && (status.getState() != QueryState.QUERY_KILLED)) {
        try {
          Thread.sleep(1000L);
        } catch (InterruptedException ie) {
          /** interrupted, just break */
          break;
        }
        currentTimeMillis = System.currentTimeMillis();
        status = getQueryStatus(queryId);
      }
    } catch (ServiceException io) {
      LOG.debug("Error when checking for application status", io);
      return false;
    }

    return true;
  }
Example #6
0
  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;
    }
  }
Example #7
0
  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());
  }
Example #8
0
  public QueryStatus getQueryStatus(QueryId queryId) throws ServiceException {
    GetQueryStatusRequest.Builder builder = GetQueryStatusRequest.newBuilder();
    builder.setQueryId(queryId.getProto());

    GetQueryStatusResponse res = service.getQueryStatus(null, builder.build());

    return new QueryStatus(res);
  }