use of org.apache.hadoop.hbase.thrift2.generated.TDelete in project hbase by apache.
the class TestThriftHBaseServiceHandler method testDeleteFamilyVersion.
@Test
public void testDeleteFamilyVersion() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = Bytes.toBytes("testDeleteFamilyVersion");
ByteBuffer table = wrap(tableAname);
long timestamp1 = EnvironmentEdgeManager.currentTime() - 10;
long timestamp2 = EnvironmentEdgeManager.currentTime();
List<TColumnValue> columnValues = new ArrayList<>();
TColumnValue columnValueA = new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname));
columnValueA.setTimestamp(timestamp1);
columnValues.add(columnValueA);
TPut put = new TPut(wrap(rowName), columnValues);
put.setColumnValues(columnValues);
handler.put(table, put);
columnValueA.setTimestamp(timestamp2);
handler.put(table, put);
TGet get = new TGet(wrap(rowName));
get.setMaxVersions(2);
TResult result = handler.get(table, get);
assertEquals(2, result.getColumnValuesSize());
TDelete delete = new TDelete(wrap(rowName));
List<TColumn> deleteColumns = new ArrayList<>();
TColumn deleteColumn = new TColumn(wrap(familyAname));
deleteColumn.setTimestamp(timestamp1);
deleteColumns.add(deleteColumn);
delete.setColumns(deleteColumns);
delete.setDeleteType(TDeleteType.DELETE_FAMILY_VERSION);
handler.deleteSingle(table, delete);
get = new TGet(wrap(rowName));
result = handler.get(table, get);
assertArrayEquals(rowName, result.getRow());
assertEquals(1, result.getColumnValuesSize());
assertEquals(timestamp2, result.getColumnValues().get(0).getTimestamp());
}
use of org.apache.hadoop.hbase.thrift2.generated.TDelete in project hbase by apache.
the class TestThriftHBaseServiceHandler method testDeleteMultiple.
@Test
public void testDeleteMultiple() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName1 = Bytes.toBytes("testDeleteMultiple1");
byte[] rowName2 = Bytes.toBytes("testDeleteMultiple2");
List<TColumnValue> columnValues = new ArrayList<>(2);
columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
columnValues.add(new TColumnValue(wrap(familyBname), wrap(qualifierBname), wrap(valueBname)));
List<TPut> puts = new ArrayList<>(2);
puts.add(new TPut(wrap(rowName1), columnValues));
puts.add(new TPut(wrap(rowName2), columnValues));
handler.putMultiple(table, puts);
List<TDelete> deletes = new ArrayList<>(2);
deletes.add(new TDelete(wrap(rowName1)));
deletes.add(new TDelete(wrap(rowName2)));
List<TDelete> deleteResults = handler.deleteMultiple(table, deletes);
// 0 means they were all successfully applies
assertEquals(0, deleteResults.size());
assertFalse(handler.exists(table, new TGet(wrap(rowName1))));
assertFalse(handler.exists(table, new TGet(wrap(rowName2))));
}
use of org.apache.hadoop.hbase.thrift2.generated.TDelete in project hbase by apache.
the class TestThriftHBaseServiceHandlerWithReadOnly method testDeleteMultipleWithReadOnly.
@Test
public void testDeleteMultipleWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
ByteBuffer table = wrap(tableAname);
byte[] rowName1 = Bytes.toBytes("testDeleteMultiple1");
byte[] rowName2 = Bytes.toBytes("testDeleteMultiple2");
List<TDelete> deletes = new ArrayList<>(2);
deletes.add(new TDelete(wrap(rowName1)));
deletes.add(new TDelete(wrap(rowName2)));
boolean exceptionCaught = false;
try {
handler.deleteMultiple(table, deletes);
} catch (TIOError e) {
exceptionCaught = true;
assertTrue(e.getCause() instanceof DoNotRetryIOException);
assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
} finally {
assertTrue(exceptionCaught);
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TDelete in project hbase by apache.
the class TestThriftHBaseServiceHandlerWithReadOnly method testDeleteWithReadOnly.
@Test
public void testDeleteWithReadOnly() throws Exception {
ThriftHBaseServiceHandler handler = createHandler();
byte[] rowName = Bytes.toBytes("testDelete");
ByteBuffer table = wrap(tableAname);
TDelete delete = new TDelete(wrap(rowName));
boolean exceptionCaught = false;
try {
handler.deleteSingle(table, delete);
} catch (TIOError e) {
exceptionCaught = true;
assertTrue(e.getCause() instanceof DoNotRetryIOException);
assertEquals("Thrift Server is in Read-only mode.", e.getMessage());
} finally {
assertTrue(exceptionCaught);
}
}
use of org.apache.hadoop.hbase.thrift2.generated.TDelete 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;
}
Aggregations