Search in sources :

Example 6 with TKeyValue

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;
}
Also used : TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) TKey(org.apache.accumulo.core.dataImpl.thrift.TKey) TKey(org.apache.accumulo.core.dataImpl.thrift.TKey)

Aggregations

TKeyValue (org.apache.accumulo.core.dataImpl.thrift.TKeyValue)6 ArrayList (java.util.ArrayList)4 Key (org.apache.accumulo.core.data.Key)4 IOException (java.io.IOException)3 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)3 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)3 Column (org.apache.accumulo.core.data.Column)3 Range (org.apache.accumulo.core.data.Range)3 TKey (org.apache.accumulo.core.dataImpl.thrift.TKey)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Collectors (java.util.stream.Collectors)2 AccumuloException (org.apache.accumulo.core.client.AccumuloException)2 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)2 KeyValue (org.apache.accumulo.core.data.KeyValue)2 PartialKey (org.apache.accumulo.core.data.PartialKey)2 Value (org.apache.accumulo.core.data.Value)2