Skip to content

Commit

Permalink
Concluded its best to keep Function<Map.Entry<K,T>,Entry<byte[]
Browse files Browse the repository at this point in the history
  • Loading branch information
rsingh433 committed Feb 1, 2024
1 parent a933461 commit 65b3c74
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
Expand Down Expand Up @@ -88,7 +87,7 @@ public void seek(Range range, Collection<ByteSequence> columnFamilies, boolean i
byte[] ba = source.getTopKey().getColumnQualifierData().toArray();
byte[] valueData = source.getTopValue().get();

byte[] encodedData = encodeEntry(ba, valueData);
byte[] encodedData = encodeKeyValue(ba, valueData);

dos.writeInt(encodedData.length);
dos.write(encodedData, 0, encodedData.length);
Expand Down Expand Up @@ -210,24 +209,24 @@ public static <T> Condition createCondition(Collection<T> set, Function<T,byte[]
}

public static <K,T> Condition createCondition(Map<K,T> map,
Function<Map.Entry<K,T>,byte[]> entryEncoder, Text family) {
Function<Map.Entry<K,T>,Map.Entry<byte[],byte[]>> entryEncoder, Text family) {
IteratorSetting is = new IteratorSetting(ConditionalTabletMutatorImpl.INITIAL_ITERATOR_PRIO,
SetEqualityIterator.class);
is.addOption(ENCODE_VALUE_OPTION, "true");

Function<Map.Entry<K,T>,byte[]> encoder = entry -> {
T value = entry.getValue();
byte[] keyData = entryEncoder.apply(entry);
byte[] valueData = value instanceof byte[] ? (byte[]) value
: value.toString().getBytes(StandardCharsets.UTF_8);
return encodeEntry(keyData, valueData);
};
Map.Entry<byte[],byte[]> byteEntry = entryEncoder.apply(entry);

return encodeKeyValue(byteEntry.getKey(), byteEntry.getValue());
};
return new Condition(family, EMPTY).setValue(encode(map.entrySet(), encoder)).setIterators(is);
}

private static byte[] encodeEntry(byte[] keyData, byte[] valueData) {
return ByteUtils.concat(ByteUtils.escape(keyData), ByteUtils.escape(valueData));

private static byte[] encodeKeyValue(byte[] key, byte[] value) {
return ByteUtils.concat(ByteUtils.escape(key), ByteUtils.escape(value));
}

// private static byte[] encodeEntry(Map.Entry<byte[],byte[]> bytesEntry) {
// return ByteUtils.concat(ByteUtils.escape(bytesEntry.getKey()),
// ByteUtils.escape(bytesEntry.getValue()));
// }
}

0 comments on commit 65b3c74

Please sign in to comment.