从put中获取postput中的列值

时间:2016-12-02 02:33:24

标签: hbase

我在hbase中实现了一个potput函数,我需要在那个

中获取特殊列的值
class AccessControlCoprocessor extends BaseRegionObserver {


@Override
public void postPut(ObserverContext<RegionCoprocessorEnvironment> e,
                    Put put,
                    WALEdit edit,
                    Durability durability)
        throws IOException
{

/*
the original put was added in this way
    val p = new Put(Bytes.toBytes(data.hashCode().toString()))


        p.add(Bytes.toBytes("cf1"),
          Bytes.toBytes("count"), Bytes.toBytes("1"))
I nee to get "1" from the above
*/

}
}

如何从上面得到“1”,我想用行键和列标识符来做..

1 个答案:

答案 0 :(得分:0)

当你知道列族时,你可以直接从传递给协处理器的Put对象中获取值:

final List<Cell> cells = put.get(Bytes.toBytes("cf1"), Bytes.toBytes("count"));

// we assume that there is only one cell in this Put transaction
Cell cell = cells.get(0)
byte[] value = CellUtil.cloneValue(cell);
String valueAsString = new String(value);

CellUtils可从org.apache.hadoop.hbase.CellUtil

获取