/**
   * Method to execute a Delete mutation operation on Hypertable. A delete is implemented by
   * Hypertable as a put that inserts tombstone values.
   *
   * @param tableName
   * @param delete
   * @throws ClientException
   * @throws TException
   */
  public void delete(String tableName, Delete delete) throws ClientException, TException {
    long mutator = client.mutator_open(ns, tableName, 0, 0);

    for (int i = 0; i < delete._getCells().size(); i++) {
      Cell c = delete._getCells().get(i);
      if (c.getKey().isSetRevision()) {
        int revs = (int) c.getKey().getRevision();
        System.out.println(revs);
        String cfam = c.getKey().getColumn_family();
        String cqual = c.getKey().getColumn_qualifier();
        c.getKey().setRevisionIsSet(false);
        List<Result> res =
            this.scan(
                tableName, new Scan(delete.getRowkey()).addColumn(cfam, cqual).setRevisions(revs));
        if (!res.isEmpty()) {
          System.out.println(res.get(0).getValueRevisions(cfam, cqual));
          for (Long ts : res.get(0).getTimestampRevisions(cfam, cqual))
            delete.deleteColumn(cfam, cqual, ts);
        }
        delete._getCells().remove(i--);
      }
    }

    try {
      if (delete._getCells().size() > 1) client.mutator_set_cells(mutator, delete._getCells());
      else if (delete._getCells().size() == 1)
        client.mutator_set_cell(mutator, delete._getCells().get(0));
    } finally {
      client.mutator_close(mutator);
    }
  }
  /**
   * Method to execute a Scan operation on Hypertable.
   *
   * @param tablename
   * @param scan
   * @return
   * @throws ClientException
   * @throws TException
   */
  public List<Result> scan(String tablename, Scan scan) throws ClientException, TException {
    long scanner = client.scanner_open(ns, tablename, scan._getScanSpec());
    HashMap<String, List<Cell>> buckets = new HashMap<String, List<Cell>>();
    try {
      List<Cell> cells = client.scanner_get_cells(scanner);

      while (cells.size() > 0) {
        for (Cell cell : cells) {
          String row = cell.getKey().getRow();
          if (buckets.get(row) == null) buckets.put(row, new LinkedList<Cell>());
          buckets.get(row).add(cell);
        }
        cells = client.scanner_get_cells(scanner);
      }
    } finally {
      client.scanner_close(scanner);
    }
    List<Result> reslist = new LinkedList<Result>();
    for (String row : buckets.keySet()) {
      reslist.add(new Result(row, buckets.get(row)));
    }
    return reslist;
  }