Search in sources :

Example 71 with ImmutableBytesPtr

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);
}
Also used : ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Aggregator(org.apache.phoenix.expression.aggregator.Aggregator)

Example 72 with ImmutableBytesPtr

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);
}
Also used : ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)

Example 73 with ImmutableBytesPtr

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;
}
Also used : ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)

Example 74 with ImmutableBytesPtr

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());
}
Also used : ArrayElemRefExpression(org.apache.phoenix.expression.function.ArrayElemRefExpression) ArrayElemRefExpression(org.apache.phoenix.expression.function.ArrayElemRefExpression) ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Test(org.junit.Test)

Example 75 with ImmutableBytesPtr

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();
        }
    };
}
Also used : ImmutableBytesPtr(org.apache.phoenix.hbase.index.util.ImmutableBytesPtr) Entry(java.util.Map.Entry) PName(org.apache.phoenix.schema.PName) PLong(org.apache.phoenix.schema.types.PLong) Iterator(java.util.Iterator) List(java.util.List) Mutation(org.apache.hadoop.hbase.client.Mutation) Pair(org.apache.hadoop.hbase.util.Pair)

Aggregations

ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)120 Mutation (org.apache.hadoop.hbase.client.Mutation)31 PTable (org.apache.phoenix.schema.PTable)28 ArrayList (java.util.ArrayList)27 Region (org.apache.hadoop.hbase.regionserver.Region)22 PMetaDataEntity (org.apache.phoenix.schema.PMetaDataEntity)22 Test (org.junit.Test)21 Cell (org.apache.hadoop.hbase.Cell)20 Put (org.apache.hadoop.hbase.client.Put)18 List (java.util.List)15 Scan (org.apache.hadoop.hbase.client.Scan)15 Pair (org.apache.hadoop.hbase.util.Pair)15 IOException (java.io.IOException)14 Expression (org.apache.phoenix.expression.Expression)14 PColumn (org.apache.phoenix.schema.PColumn)14 RowLock (org.apache.hadoop.hbase.regionserver.Region.RowLock)13 PSmallint (org.apache.phoenix.schema.types.PSmallint)12 HashMap (java.util.HashMap)11 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)11 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)11