use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class SpillManager method toCacheEntry.
/**
* Helper function to deserialize a byte array into a CacheEntry
* @param <K>
* @param bytes
* @throws IOException
*/
@SuppressWarnings("unchecked")
public <K extends ImmutableBytesWritable> CacheEntry<K> toCacheEntry(byte[] bytes) throws IOException {
ImmutableBytesPtr key = SpillManager.getKey(bytes);
Aggregator[] aggs = getAggregators(bytes);
return new CacheEntry<K>((K) key, aggs);
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class SpillManager method spill.
/**
* Function that spills a key/value groupby tuple into a partition Spilling always triggers a
* serialize call
* @param key
* @param value
* @throws IOException
*/
public void spill(ImmutableBytesWritable key, Aggregator[] value) throws IOException {
SpillMap spillMap = spillMaps.get(getPartition(key));
ImmutableBytesPtr keyPtr = new ImmutableBytesPtr(key);
byte[] data = serialize(keyPtr, value, aggregators);
spillMap.put(keyPtr, data);
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class SpillMap method get.
/**
* Get a key from the spillable data structures. page is determined via hash partitioning, and a bloomFilter check
* is used to determine if its worth paging in the data.
*/
@Override
public byte[] get(Object key) {
if (!(key instanceof ImmutableBytesPtr)) {
// TODO ... work on type safety
}
ImmutableBytesPtr ikey = (ImmutableBytesPtr) key;
byte[] value = null;
int bucketIndex = getBucketIndex(ikey);
MappedByteBufferMap byteMap = directory[bucketIndex];
// Decision based on bucket ID, not the directory ID due to the n:1 relationship
if (directory[curMapBufferIndex].pageIndex != byteMap.pageIndex) {
// map not paged in
MappedByteBufferMap curByteMap = directory[curMapBufferIndex];
// Use bloomFilter to check if key was spilled before
if (byteMap.containsKey(ikey.copyBytesIfNecessary())) {
// ensure consistency and flush current memory page to disk
// fflush current buffer
curByteMap.flushBuffer();
// page in new buffer
byteMap.pageIn();
// update index
curMapBufferIndex = bucketIndex;
}
}
// get KV from current map
value = byteMap.getPagedInElement(ikey);
return value;
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class ArrayConstructorExpressionTest method testLeadingNulls.
@Test
public void testLeadingNulls() throws Exception {
List<Expression> children = Lists.newArrayListWithExpectedSize(4);
LiteralExpression nullExpression = LiteralExpression.newConstant(null);
children.add(nullExpression);
children.add(nullExpression);
children.add(LiteralExpression.newConstant(BYTE_ARRAY1, PVarbinary.INSTANCE));
children.add(LiteralExpression.newConstant(BYTE_ARRAY2, PVarbinary.INSTANCE));
ArrayConstructorExpression arrayConstructorExpression = new ArrayConstructorExpression(children, PVarbinary.INSTANCE, false);
ImmutableBytesPtr ptr = new ImmutableBytesPtr();
ArrayElemRefExpression arrayElemRefExpression = new ArrayElemRefExpression(Lists.<Expression>newArrayList(arrayConstructorExpression));
arrayElemRefExpression.setIndex(1);
arrayElemRefExpression.evaluate(null, ptr);
assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptr.copyBytesIfNecessary());
arrayElemRefExpression.setIndex(2);
arrayElemRefExpression.evaluate(null, ptr);
assertArrayEquals(ByteUtil.EMPTY_BYTE_ARRAY, ptr.copyBytesIfNecessary());
arrayElemRefExpression.setIndex(3);
arrayElemRefExpression.evaluate(null, ptr);
assertArrayEquals(BYTE_ARRAY1, ptr.copyBytesIfNecessary());
arrayElemRefExpression.setIndex(4);
arrayElemRefExpression.evaluate(null, ptr);
assertArrayEquals(BYTE_ARRAY2, ptr.copyBytesIfNecessary());
}
use of org.apache.phoenix.hbase.index.util.ImmutableBytesPtr in project phoenix by apache.
the class MutationState method toMutations.
public Iterator<Pair<byte[], List<Mutation>>> toMutations(final boolean includeMutableIndexes, final Long tableTimestamp) {
final Iterator<Map.Entry<TableRef, Map<ImmutableBytesPtr, RowMutationState>>> iterator = this.mutations.entrySet().iterator();
if (!iterator.hasNext()) {
return Iterators.emptyIterator();
}
Long scn = connection.getSCN();
final long timestamp = getMutationTimestamp(tableTimestamp, scn);
return new Iterator<Pair<byte[], List<Mutation>>>() {
private Map.Entry<TableRef, Map<ImmutableBytesPtr, RowMutationState>> current = iterator.next();
private Iterator<Pair<byte[], List<Mutation>>> innerIterator = init();
private Iterator<Pair<byte[], List<Mutation>>> init() {
final Iterator<Pair<PName, List<Mutation>>> mutationIterator = addRowMutations(current.getKey(), current.getValue(), timestamp, includeMutableIndexes, true);
return new Iterator<Pair<byte[], List<Mutation>>>() {
@Override
public boolean hasNext() {
return mutationIterator.hasNext();
}
@Override
public Pair<byte[], List<Mutation>> next() {
Pair<PName, List<Mutation>> pair = mutationIterator.next();
return new Pair<byte[], List<Mutation>>(pair.getFirst().getBytes(), pair.getSecond());
}
@Override
public void remove() {
mutationIterator.remove();
}
};
}
@Override
public boolean hasNext() {
return innerIterator.hasNext() || iterator.hasNext();
}
@Override
public Pair<byte[], List<Mutation>> next() {
if (!innerIterator.hasNext()) {
current = iterator.next();
innerIterator = init();
}
return innerIterator.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
Aggregations