Example #1
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 #2
0
 public TableDesc attachTable(String name, String path) throws ServiceException {
   AttachTableRequest.Builder builder = AttachTableRequest.newBuilder();
   builder.setName(name);
   builder.setPath(path);
   TableResponse res = service.attachTable(null, builder.build());
   return TCatUtil.newTableDesc(res.getTableDesc());
 }
Example #3
0
  public boolean updateQuery(String tql) throws ServiceException {
    QueryRequest.Builder builder = QueryRequest.newBuilder();
    builder.setQuery(tql);

    ResultCode resultCode = service.updateQuery(null, builder.build()).getResultCode();
    return resultCode == ResultCode.OK;
  }
Example #4
0
 public TableDesc createTable(String name, Path path, TableMeta meta) throws ServiceException {
   CreateTableRequest.Builder builder = CreateTableRequest.newBuilder();
   builder.setName(name);
   builder.setPath(path.toString());
   builder.setMeta(meta.getProto());
   TableResponse res = service.createTable(null, builder.build());
   return TCatUtil.newTableDesc(res.getTableDesc());
 }
Example #5
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);
  }
Example #6
0
 public TableDesc getTableDesc(String tableName) throws ServiceException {
   GetTableDescRequest.Builder build = GetTableDescRequest.newBuilder();
   build.setTableName(tableName);
   TableResponse res = service.getTableDesc(null, build.build());
   if (res == null) {
     return null;
   } else {
     return TCatUtil.newTableDesc(res.getTableDesc());
   }
 }
Example #7
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 #8
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 #9
0
  /**
   * It submits a query statement and get a response immediately. The response only contains a query
   * id, and submission status. In order to get the result, you should use {@link
   * #getQueryResult(tajo.QueryId)} or {@link #getQueryResultAndWait(tajo.QueryId)}.
   */
  public SubmitQueryRespose executeQuery(String tql) throws ServiceException {
    QueryRequest.Builder builder = QueryRequest.newBuilder();
    builder.setQuery(tql);

    return service.submitQuery(null, builder.build());
  }
Example #10
0
 /**
  * Get a list of table names. All table and column names are represented as lower-case letters.
  */
 public List<String> getTableList() throws ServiceException {
   GetTableListRequest.Builder builder = GetTableListRequest.newBuilder();
   GetTableListResponse res = service.getTableList(null, builder.build());
   return res.getTablesList();
 }
Example #11
0
 public boolean dropTable(String name) throws ServiceException {
   StringProto.Builder builder = StringProto.newBuilder();
   builder.setValue(name);
   return service.dropTable(null, builder.build()).getValue();
 }