Search in sources :

Example 1 with TAppend

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);
    }
}
Also used : ArrayList(java.util.ArrayList) BatchMutation(org.apache.hadoop.hbase.thrift.generated.BatchMutation) Mutation(org.apache.hadoop.hbase.thrift.generated.Mutation) TAppend(org.apache.hadoop.hbase.thrift.generated.TAppend) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult) ByteBuffer(java.nio.ByteBuffer)

Example 2 with TAppend

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);
    }
}
Also used : TException(org.apache.thrift.TException) Table(org.apache.hadoop.hbase.client.Table) TAppend(org.apache.hadoop.hbase.thrift.generated.TAppend) Append(org.apache.hadoop.hbase.client.Append) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result) TRowResult(org.apache.hadoop.hbase.thrift.generated.TRowResult)

Example 3 with TAppend

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;
}
Also used : TAppend(org.apache.hadoop.hbase.thrift.generated.TAppend) Append(org.apache.hadoop.hbase.client.Append) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TAppend (org.apache.hadoop.hbase.thrift.generated.TAppend)3 ByteBuffer (java.nio.ByteBuffer)2 Append (org.apache.hadoop.hbase.client.Append)2 TRowResult (org.apache.hadoop.hbase.thrift.generated.TRowResult)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 Result (org.apache.hadoop.hbase.client.Result)1 Table (org.apache.hadoop.hbase.client.Table)1 BatchMutation (org.apache.hadoop.hbase.thrift.generated.BatchMutation)1 Mutation (org.apache.hadoop.hbase.thrift.generated.Mutation)1 TException (org.apache.thrift.TException)1