use of org.apache.hadoop.hbase.thrift.generated.TAppend in project hbase by apache.
the class TestThriftServer method doTestAppend.
/**
* Appends the value to a cell and checks that the cell value is updated properly.
*/
public static void doTestAppend() throws Exception {
ThriftHBaseServiceHandler handler = new ThriftHBaseServiceHandler(UTIL.getConfiguration(), UserProvider.instantiate(UTIL.getConfiguration()));
handler.createTable(tableAname, getColumnDescriptors());
try {
List<Mutation> mutations = new ArrayList<>(1);
mutations.add(new Mutation(false, columnAname, valueAname, true));
handler.mutateRow(tableAname, rowAname, mutations, null);
List<ByteBuffer> columnList = new ArrayList<>(1);
columnList.add(columnAname);
List<ByteBuffer> valueList = new ArrayList<>(1);
valueList.add(valueBname);
TAppend append = new TAppend(tableAname, rowAname, columnList, valueList);
handler.append(append);
TRowResult rowResult = handler.getRow(tableAname, rowAname, null).get(0);
assertEquals(rowAname, rowResult.row);
assertArrayEquals(Bytes.add(valueAname.array(), valueBname.array()), rowResult.columns.get(columnAname).value.array());
} finally {
handler.disableTable(tableAname);
handler.deleteTable(tableAname);
}
}
use of org.apache.hadoop.hbase.thrift.generated.TAppend in project hbase by apache.
the class ThriftHBaseServiceHandler method append.
@Override
public List<TCell> append(TAppend tappend) throws IOError, TException {
if (tappend.getRow().length == 0 || tappend.getTable().length == 0) {
throw new TException("Must supply a table and a row key; can't append");
}
Table table = null;
try {
table = getTable(tappend.getTable());
Append append = ThriftUtilities.appendFromThrift(tappend);
Result result = table.append(append);
return ThriftUtilities.cellFromHBase(result.rawCells());
} catch (IOException e) {
LOG.warn(e.getMessage(), e);
throw getIOError(e);
} finally {
closeTable(table);
}
}
use of org.apache.hadoop.hbase.thrift.generated.TAppend in project hbase by apache.
the class ThriftUtilities method appendFromThrift.
/**
* From a {@link TAppend} create an {@link Append}.
* @param tappend the Thrift version of an append.
* @return an increment that the {@link TAppend} represented.
*/
public static Append appendFromThrift(TAppend tappend) {
Append append = new Append(tappend.getRow());
List<ByteBuffer> columns = tappend.getColumns();
List<ByteBuffer> values = tappend.getValues();
if (columns.size() != values.size()) {
throw new IllegalArgumentException("Sizes of columns and values in tappend object are not matching");
}
int length = columns.size();
for (int i = 0; i < length; i++) {
byte[][] famAndQf = CellUtil.parseColumn(getBytes(columns.get(i)));
append.addColumn(famAndQf[0], famAndQf[1], getBytes(values.get(i)));
}
return append;
}
Aggregations