Search in sources :

Example 1 with LongSet

use of it.unimi.dsi.fastutil.longs.LongSet in project presto by prestodb.

the class ArrayUnionFunction method bigintUnion.

@SqlType("array(bigint)")
public static Block bigintUnion(@SqlType("array(bigint)") Block leftArray, @SqlType("array(bigint)") Block rightArray) {
    int leftArrayCount = leftArray.getPositionCount();
    int rightArrayCount = rightArray.getPositionCount();
    LongSet set = new LongOpenHashSet(leftArrayCount + rightArrayCount);
    BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), leftArrayCount + rightArrayCount);
    AtomicBoolean containsNull = new AtomicBoolean(false);
    appendBigintArray(leftArray, containsNull, set, distinctElementBlockBuilder);
    appendBigintArray(rightArray, containsNull, set, distinctElementBlockBuilder);
    return distinctElementBlockBuilder.build();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LongSet(it.unimi.dsi.fastutil.longs.LongSet) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) SqlType(com.facebook.presto.spi.function.SqlType)

Example 2 with LongSet

use of it.unimi.dsi.fastutil.longs.LongSet in project presto by prestodb.

the class ArrayDistinctFunction method bigintDistinct.

@SqlType("array(bigint)")
public static Block bigintDistinct(@SqlType("array(bigint)") Block array) {
    if (array.getPositionCount() == 0) {
        return array;
    }
    boolean containsNull = false;
    LongSet set = new LongOpenHashSet(array.getPositionCount());
    BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), array.getPositionCount());
    for (int i = 0; i < array.getPositionCount(); i++) {
        if (array.isNull(i)) {
            if (!containsNull) {
                containsNull = true;
                distinctElementBlockBuilder.appendNull();
            }
            continue;
        }
        long value = BIGINT.getLong(array, i);
        if (set.add(value)) {
            BIGINT.writeLong(distinctElementBlockBuilder, value);
        }
    }
    return distinctElementBlockBuilder.build();
}
Also used : LongSet(it.unimi.dsi.fastutil.longs.LongSet) LongOpenHashSet(it.unimi.dsi.fastutil.longs.LongOpenHashSet) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)2 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)2 SqlType (com.facebook.presto.spi.function.SqlType)2 LongOpenHashSet (it.unimi.dsi.fastutil.longs.LongOpenHashSet)2 LongSet (it.unimi.dsi.fastutil.longs.LongSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1