Java Code Examples for org.apache.hadoop.hbase.client.Delete#getTimeStamp()

The following examples show how to use org.apache.hadoop.hbase.client.Delete#getTimeStamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftUtilities.java    From hbase with Apache License 2.0 4 votes vote down vote up
public static TDelete deleteFromHBase(Delete in) {
  TDelete out = new TDelete(ByteBuffer.wrap(in.getRow()));

  List<TColumn> columns = new ArrayList<>(in.getFamilyCellMap().entrySet().size());
  long rowTimestamp = in.getTimestamp();
  if (rowTimestamp != HConstants.LATEST_TIMESTAMP) {
    out.setTimestamp(rowTimestamp);
  }

  for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
    out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())),
        ByteBuffer.wrap(attribute.getValue()));
  }
  if (in.getDurability() != Durability.USE_DEFAULT)  {
    out.setDurability(durabilityFromHBase(in.getDurability()));
  }
  // Delete the whole row
  if (in.getFamilyCellMap().size() == 0) {
    return out;
  }
  TDeleteType type = null;
  for (Map.Entry<byte[], List<Cell>> familyEntry:
      in.getFamilyCellMap().entrySet()) {
    byte[] family = familyEntry.getKey();
    TColumn column = new TColumn(ByteBuffer.wrap(familyEntry.getKey()));
    for (Cell cell: familyEntry.getValue()) {
      TDeleteType cellDeleteType = deleteTypeFromHBase(cell.getType());
      if (type == null) {
        type = cellDeleteType;
      } else if (type != cellDeleteType){
        throw new RuntimeException("Only the same delete type is supported, but two delete type "
            + "is founded, one is " + type + " the other one is " + cellDeleteType);
      }
      byte[] qualifier = CellUtil.cloneQualifier(cell);
      long timestamp = cell.getTimestamp();
      column.setFamily(family);
      if (qualifier != null) {
        column.setQualifier(qualifier);
      }
      if (timestamp != HConstants.LATEST_TIMESTAMP) {
        column.setTimestamp(timestamp);
      }
    }
    columns.add(column);
  }
  out.setColumns(columns);
  out.setDeleteType(type);

  return out;
}