use of org.apache.accumulo.core.dataImpl.thrift.TKeyValue in project accumulo by apache.
the class Key method compress.
/**
* Compresses a list of key/value pairs before sending them via thrift.
*
* @param param
* list of key/value pairs
* @return list of Thrift key/value pairs
*/
public static List<TKeyValue> compress(List<? extends KeyValue> param) {
List<TKeyValue> tkvl = Arrays.asList(new TKeyValue[param.size()]);
if (!param.isEmpty())
tkvl.set(0, new TKeyValue(param.get(0).getKey().toThrift(), ByteBuffer.wrap(param.get(0).getValue().get())));
for (int i = param.size() - 1; i > 0; i--) {
Key prevKey = param.get(i - 1).getKey();
KeyValue kv = param.get(i);
Key key = kv.getKey();
TKey newKey = null;
if (isEqual(prevKey.row, key.row)) {
newKey = key.toThrift();
newKey.row = null;
}
if (isEqual(prevKey.colFamily, key.colFamily)) {
if (newKey == null)
newKey = key.toThrift();
newKey.colFamily = null;
}
if (isEqual(prevKey.colQualifier, key.colQualifier)) {
if (newKey == null)
newKey = key.toThrift();
newKey.colQualifier = null;
}
if (isEqual(prevKey.colVisibility, key.colVisibility)) {
if (newKey == null)
newKey = key.toThrift();
newKey.colVisibility = null;
}
if (newKey == null)
newKey = key.toThrift();
tkvl.set(i, new TKeyValue(newKey, ByteBuffer.wrap(kv.getValue().get())));
}
return tkvl;
}
Aggregations