Search in sources :

Example 1 with IntArrayList

use of it.unimi.dsi.fastutil.ints.IntArrayList in project pinot by linkedin.

the class DefaultGroupKeyGenerator method generateKeysForDocIdArrayMapBased.

/**
   * Helper function to generate group keys (int[]) according to the document id. This method should only be called when
   * there are multi value group-by columns.
   * (ARRAY_MAP_BASED storage type)
   *
   * @param index index of the docIdSet.
   * @param docId document id.
   * @return group keys.
   */
private int[] generateKeysForDocIdArrayMapBased(int index, int docId) {
    IntArrayList[] rawKeys = { new IntArrayList(_numGroupByColumns) };
    rawKeys[0].size(_numGroupByColumns);
    int length = 1;
    for (int i = 0; i < _numGroupByColumns; i++) {
        if (_isSingleValueGroupByColumn[i]) {
            int dictId = _reusableSingleDictIds[i][index];
            for (IntArrayList rawKey : rawKeys) {
                rawKey.elements()[i] = dictId;
            }
        } else {
            int numMultiValues = _blockValSets[i].getDictionaryIdsForDocId(docId, _reusableMultiValDictIdBuffer);
            int oldLength = length;
            length *= numMultiValues;
            IntArrayList[] oldRawKeys = rawKeys;
            rawKeys = new IntArrayList[length];
            System.arraycopy(oldRawKeys, 0, rawKeys, 0, oldLength);
            for (int j = 1; j < numMultiValues; j++) {
                int offset = j * oldLength;
                for (int k = 0; k < oldLength; k++) {
                    rawKeys[offset + k] = new IntArrayList(oldRawKeys[k].elements());
                }
            }
            for (int j = 0; j < numMultiValues; j++) {
                int dictId = _reusableMultiValDictIdBuffer[j];
                int offset = j * oldLength;
                for (int k = 0; k < oldLength; k++) {
                    int idx = offset + k;
                    rawKeys[idx].elements()[i] = dictId;
                }
            }
        }
    }
    int[] groupKeys = new int[length];
    for (int i = 0; i < length; i++) {
        groupKeys[i] = updateRawKeyToGroupKeyMapping(rawKeys[i]);
    }
    return groupKeys;
}
Also used : IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Example 2 with IntArrayList

use of it.unimi.dsi.fastutil.ints.IntArrayList in project presto by prestodb.

the class ParquetReader method readMap.

private Block readMap(Type type, List<String> path, IntList elementOffsets) throws IOException {
    List<Type> parameters = type.getTypeParameters();
    checkArgument(parameters.size() == 2, "Maps must have two type parameters, found %d", parameters.size());
    Block[] blocks = new Block[parameters.size()];
    IntList keyOffsets = new IntArrayList();
    IntList valueOffsets = new IntArrayList();
    path.add(MAP_TYPE_NAME);
    blocks[0] = readBlock(MAP_KEY_NAME, parameters.get(0), path, keyOffsets);
    blocks[1] = readBlock(MAP_VALUE_NAME, parameters.get(1), path, valueOffsets);
    path.remove(MAP_TYPE_NAME);
    if (blocks[0].getPositionCount() == 0) {
        for (int i = 0; i < batchSize; i++) {
            elementOffsets.add(0);
        }
        return RunLengthEncodedBlock.create(parameters.get(0), null, batchSize);
    }
    InterleavedBlock interleavedBlock = new InterleavedBlock(new Block[] { blocks[0], blocks[1] });
    int[] offsets = new int[batchSize + 1];
    for (int i = 1; i < offsets.length; i++) {
        int elementPositionCount = keyOffsets.getInt(i - 1) * 2;
        elementOffsets.add(elementPositionCount);
        offsets[i] = offsets[i - 1] + elementPositionCount;
    }
    return new ArrayBlock(batchSize, new boolean[batchSize], offsets, interleavedBlock);
}
Also used : Type(com.facebook.presto.spi.type.Type) MessageType(parquet.schema.MessageType) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) Block(com.facebook.presto.spi.block.Block) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock) IntList(it.unimi.dsi.fastutil.ints.IntList)

Example 3 with IntArrayList

use of it.unimi.dsi.fastutil.ints.IntArrayList in project presto by prestodb.

the class MapStreamReader method createKeyValueBlock.

private static InterleavedBlock createKeyValueBlock(int positionCount, Block keys, Block values, int[] lengths) {
    if (!hasNull(keys)) {
        return new InterleavedBlock(new Block[] { keys, values });
    }
    //
    // Map entries with a null key are skipped in the Hive ORC reader, so skip them here also
    //
    IntArrayList nonNullPositions = new IntArrayList(keys.getPositionCount());
    int position = 0;
    for (int mapIndex = 0; mapIndex < positionCount; mapIndex++) {
        int length = lengths[mapIndex];
        for (int entryIndex = 0; entryIndex < length; entryIndex++) {
            if (keys.isNull(position)) {
                // key is null, so remove this entry from the map
                lengths[mapIndex]--;
            } else {
                nonNullPositions.add(position);
            }
            position++;
        }
    }
    Block newKeys = keys.copyPositions(nonNullPositions);
    Block newValues = values.copyPositions(nonNullPositions);
    return new InterleavedBlock(new Block[] { newKeys, newValues });
}
Also used : Block(com.facebook.presto.spi.block.Block) ArrayBlock(com.facebook.presto.spi.block.ArrayBlock) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) InterleavedBlock(com.facebook.presto.spi.block.InterleavedBlock)

Example 4 with IntArrayList

use of it.unimi.dsi.fastutil.ints.IntArrayList in project Glowstone by GlowstoneMC.

the class ChunkSection method loadTypeArray.

/**
     * Loads the contents of this chunk section from the given type array,
     * initializing the palette.
     *
     * @param types The type array.
     */
public void loadTypeArray(char[] types) {
    if (types.length != ARRAY_SIZE) {
        throw new IllegalArgumentException("Types array length was not " + ARRAY_SIZE + ": " + types.length);
    }
    // Build the palette, and the count
    this.count = 0;
    this.palette = new IntArrayList();
    for (char type : types) {
        if (type != 0) {
            count++;
        }
        if (!palette.contains(type)) {
            palette.add(type);
        }
    }
    // Now that we've built a palette, build the list
    int bitsPerBlock = VariableValueArray.calculateNeededBits(palette.size());
    if (bitsPerBlock < 4) {
        bitsPerBlock = 4;
    } else if (bitsPerBlock > 8) {
        palette = null;
        bitsPerBlock = GLOBAL_PALETTE_BITS_PER_BLOCK;
    }
    this.data = new VariableValueArray(bitsPerBlock, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++) {
        if (palette != null) {
            data.set(i, palette.indexOf(types[i]));
        } else {
            data.set(i, types[i]);
        }
    }
}
Also used : VariableValueArray(net.glowstone.util.VariableValueArray) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList)

Example 5 with IntArrayList

use of it.unimi.dsi.fastutil.ints.IntArrayList in project gatk by broadinstitute.

the class ContextCovariate method contextWith.

/**
     * calculates the context of a base independent of the covariate mode (mismatch, insertion or deletion)
     *
     * @param bases       the bases in the read to build the context from
     * @param contextSize context size to use building the context
     * @param mask        mask for pulling out just the context bits
     */
private static IntList contextWith(final byte[] bases, final int contextSize, final int mask) {
    final int readLength = bases.length;
    //Note: we use a specialized collection to avoid the cost of boxing and unboxing that otherwise comes up on the profiler.
    final IntList keys = new IntArrayList(readLength);
    // the first contextSize-1 bases will not have enough previous context
    for (int i = 1; i < contextSize && i <= readLength; i++) {
        keys.add(-1);
    }
    if (readLength < contextSize) {
        return keys;
    }
    final int newBaseOffset = 2 * (contextSize - 1) + LENGTH_BITS;
    // get (and add) the key for the context starting at the first base
    int currentKey = keyFromContext(bases, 0, contextSize);
    keys.add(currentKey);
    // if the first key was -1 then there was an N in the context; figure out how many more consecutive contexts it affects
    int currentNPenalty = 0;
    if (currentKey == -1) {
        currentKey = 0;
        currentNPenalty = contextSize - 1;
        int offset = newBaseOffset;
        while (bases[currentNPenalty] != 'N') {
            final int baseIndex = BaseUtils.simpleBaseToBaseIndex(bases[currentNPenalty]);
            currentKey |= (baseIndex << offset);
            offset -= 2;
            currentNPenalty--;
        }
    }
    for (int currentIndex = contextSize; currentIndex < readLength; currentIndex++) {
        final int baseIndex = BaseUtils.simpleBaseToBaseIndex(bases[currentIndex]);
        if (baseIndex == -1) {
            // ignore non-ACGT bases
            currentNPenalty = contextSize;
            // reset the key
            currentKey = 0;
        } else {
            // push this base's contribution onto the key: shift everything 2 bits, mask out the non-context bits, and add the new base and the length in
            currentKey = (currentKey >> 2) & mask;
            currentKey |= (baseIndex << newBaseOffset);
            currentKey |= contextSize;
        }
        if (currentNPenalty == 0) {
            keys.add(currentKey);
        } else {
            currentNPenalty--;
            keys.add(-1);
        }
    }
    return keys;
}
Also used : IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)10 ArrayBlock (com.facebook.presto.spi.block.ArrayBlock)3 Block (com.facebook.presto.spi.block.Block)3 InterleavedBlock (com.facebook.presto.spi.block.InterleavedBlock)3 IntList (it.unimi.dsi.fastutil.ints.IntList)3 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)2 Type (com.facebook.presto.spi.type.Type)2 MessageType (parquet.schema.MessageType)2 NamedTypeSignature (com.facebook.presto.spi.type.NamedTypeSignature)1 TypeSignatureParameter (com.facebook.presto.spi.type.TypeSignatureParameter)1 Supplier (com.google.common.base.Supplier)1 BlockValSet (com.linkedin.pinot.core.common.BlockValSet)1 IntOpenHashSet (it.unimi.dsi.fastutil.ints.IntOpenHashSet)1 ArrayList (java.util.ArrayList)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 VariableValueArray (net.glowstone.util.VariableValueArray)1 GATKRead (org.broadinstitute.hellbender.utils.read.GATKRead)1 Test (org.junit.Test)1