Search in sources :

Example 1 with TDeleteType

use of org.apache.hadoop.hbase.thrift2.generated.TDeleteType in project hbase by apache.

the class ThriftUtilities method deleteFromHBase.

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;
}
Also used : TColumn(org.apache.hadoop.hbase.thrift2.generated.TColumn) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) TDeleteType(org.apache.hadoop.hbase.thrift2.generated.TDeleteType) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Cell (org.apache.hadoop.hbase.Cell)1 TColumn (org.apache.hadoop.hbase.thrift2.generated.TColumn)1 TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)1 TDeleteType (org.apache.hadoop.hbase.thrift2.generated.TDeleteType)1