Search in sources :

Example 6 with TColumnIncrement

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

the class TestThriftHBaseServiceHandler method testAttribute.

@Test
public void testAttribute() throws Exception {
    byte[] rowName = Bytes.toBytes("testAttribute");
    byte[] attributeKey = Bytes.toBytes("attribute1");
    byte[] attributeValue = Bytes.toBytes("value1");
    Map<ByteBuffer, ByteBuffer> attributes = new HashMap<>();
    attributes.put(wrap(attributeKey), wrap(attributeValue));
    TGet tGet = new TGet(wrap(rowName));
    tGet.setAttributes(attributes);
    Get get = getFromThrift(tGet);
    assertArrayEquals(get.getAttribute("attribute1"), attributeValue);
    List<TColumnValue> columnValues = new ArrayList<>(1);
    columnValues.add(new TColumnValue(wrap(familyAname), wrap(qualifierAname), wrap(valueAname)));
    TPut tPut = new TPut(wrap(rowName), columnValues);
    tPut.setAttributes(attributes);
    Put put = putFromThrift(tPut);
    assertArrayEquals(put.getAttribute("attribute1"), attributeValue);
    TScan tScan = new TScan();
    tScan.setAttributes(attributes);
    Scan scan = scanFromThrift(tScan);
    assertArrayEquals(scan.getAttribute("attribute1"), attributeValue);
    List<TColumnIncrement> incrementColumns = new ArrayList<>(1);
    incrementColumns.add(new TColumnIncrement(wrap(familyAname), wrap(qualifierAname)));
    TIncrement tIncrement = new TIncrement(wrap(rowName), incrementColumns);
    tIncrement.setAttributes(attributes);
    Increment increment = incrementFromThrift(tIncrement);
    assertArrayEquals(increment.getAttribute("attribute1"), attributeValue);
    TDelete tDelete = new TDelete(wrap(rowName));
    tDelete.setAttributes(attributes);
    Delete delete = deleteFromThrift(tDelete);
    assertArrayEquals(delete.getAttribute("attribute1"), attributeValue);
}
Also used : Delete(org.apache.hadoop.hbase.client.Delete) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) HashMap(java.util.HashMap) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) ArrayList(java.util.ArrayList) TDelete(org.apache.hadoop.hbase.thrift2.generated.TDelete) TIncrement(org.apache.hadoop.hbase.thrift2.generated.TIncrement) TColumnValue(org.apache.hadoop.hbase.thrift2.generated.TColumnValue) ByteBuffer(java.nio.ByteBuffer) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Put(org.apache.hadoop.hbase.client.Put) Get(org.apache.hadoop.hbase.client.Get) TGet(org.apache.hadoop.hbase.thrift2.generated.TGet) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) TColumnIncrement(org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement) TIncrement(org.apache.hadoop.hbase.thrift2.generated.TIncrement) Increment(org.apache.hadoop.hbase.client.Increment) TColumnIncrement(org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement) TScan(org.apache.hadoop.hbase.thrift2.generated.TScan) Scan(org.apache.hadoop.hbase.client.Scan) TPut(org.apache.hadoop.hbase.thrift2.generated.TPut) Test(org.junit.Test)

Example 7 with TColumnIncrement

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

the class ThriftUtilities method incrementFromHBase.

public static TIncrement incrementFromHBase(Increment in) throws IOException {
    TIncrement out = new TIncrement();
    out.setRow(in.getRow());
    if (in.getDurability() != Durability.USE_DEFAULT) {
        out.setDurability(durabilityFromHBase(in.getDurability()));
    }
    for (Map.Entry<byte[], List<Cell>> entry : in.getFamilyCellMap().entrySet()) {
        byte[] family = entry.getKey();
        for (Cell cell : entry.getValue()) {
            TColumnIncrement columnValue = new TColumnIncrement();
            columnValue.setFamily(family).setQualifier(CellUtil.cloneQualifier(cell));
            columnValue.setAmount(Bytes.toLong(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
            out.addToColumns(columnValue);
        }
    }
    for (Map.Entry<String, byte[]> attribute : in.getAttributesMap().entrySet()) {
        out.putToAttributes(ByteBuffer.wrap(Bytes.toBytes(attribute.getKey())), ByteBuffer.wrap(attribute.getValue()));
    }
    try {
        CellVisibility cellVisibility = in.getCellVisibility();
        if (cellVisibility != null) {
            TCellVisibility tCellVisibility = new TCellVisibility();
            tCellVisibility.setExpression(cellVisibility.getExpression());
            out.setCellVisibility(tCellVisibility);
        }
    } catch (DeserializationException e) {
        throw new RuntimeException(e);
    }
    out.setReturnResults(in.isReturnResults());
    return out;
}
Also used : TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) CellVisibility(org.apache.hadoop.hbase.security.visibility.CellVisibility) TIncrement(org.apache.hadoop.hbase.thrift2.generated.TIncrement) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) TColumnIncrement(org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement) TCellVisibility(org.apache.hadoop.hbase.thrift2.generated.TCellVisibility) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

ArrayList (java.util.ArrayList)7 TColumnIncrement (org.apache.hadoop.hbase.thrift2.generated.TColumnIncrement)7 TIncrement (org.apache.hadoop.hbase.thrift2.generated.TIncrement)7 Test (org.junit.Test)6 ByteBuffer (java.nio.ByteBuffer)5 TColumnValue (org.apache.hadoop.hbase.thrift2.generated.TColumnValue)5 TPut (org.apache.hadoop.hbase.thrift2.generated.TPut)5 TGet (org.apache.hadoop.hbase.thrift2.generated.TGet)4 TCellVisibility (org.apache.hadoop.hbase.thrift2.generated.TCellVisibility)3 TResult (org.apache.hadoop.hbase.thrift2.generated.TResult)3 Delete (org.apache.hadoop.hbase.client.Delete)2 Increment (org.apache.hadoop.hbase.client.Increment)2 Put (org.apache.hadoop.hbase.client.Put)2 TAuthorization (org.apache.hadoop.hbase.thrift2.generated.TAuthorization)2 TDelete (org.apache.hadoop.hbase.thrift2.generated.TDelete)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Cell (org.apache.hadoop.hbase.Cell)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1