Search in sources :

Example 11 with TypedSet

use of io.prestosql.operator.aggregation.TypedSet in project hetu-core by openlookeng.

the class ArrayExceptFunction method except.

@TypeParameter("E")
@SqlType("array(E)")
public static Block except(@TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) {
    int leftPositionCount = leftArray.getPositionCount();
    int rightPositionCount = rightArray.getPositionCount();
    if (leftPositionCount == 0) {
        return leftArray;
    }
    TypedSet typedSet = new TypedSet(type, leftPositionCount + rightPositionCount, "array_except");
    BlockBuilder distinctElementBlockBuilder = type.createBlockBuilder(null, leftPositionCount);
    for (int i = 0; i < rightPositionCount; i++) {
        typedSet.add(rightArray, i);
    }
    for (int i = 0; i < leftPositionCount; i++) {
        if (!typedSet.contains(leftArray, i)) {
            typedSet.add(leftArray, i);
            type.appendTo(leftArray, i, distinctElementBlockBuilder);
        }
    }
    return distinctElementBlockBuilder.build();
}
Also used : TypedSet(io.prestosql.operator.aggregation.TypedSet) BlockBuilder(io.prestosql.spi.block.BlockBuilder) TypeParameter(io.prestosql.spi.function.TypeParameter) SqlType(io.prestosql.spi.function.SqlType)

Aggregations

TypedSet (io.prestosql.operator.aggregation.TypedSet)11 BlockBuilder (io.prestosql.spi.block.BlockBuilder)10 SqlType (io.prestosql.spi.function.SqlType)7 TypeParameter (io.prestosql.spi.function.TypeParameter)6 Block (io.prestosql.spi.block.Block)5 Type (io.prestosql.spi.type.Type)5 PrestoException (io.prestosql.spi.PrestoException)3 MapType (io.prestosql.spi.type.MapType)3 UsedByGeneratedCode (io.prestosql.spi.annotation.UsedByGeneratedCode)2 SqlNullable (io.prestosql.spi.function.SqlNullable)2 ArrayType (io.prestosql.spi.type.ArrayType)2 RowType (io.prestosql.spi.type.RowType)2 ObjectBigArray (io.prestosql.array.ObjectBigArray)1 CastType (io.prestosql.metadata.CastType)1 PageBuilder (io.prestosql.spi.PageBuilder)1 ScalarFunction (io.prestosql.spi.function.ScalarFunction)1 Constraint (io.prestosql.type.Constraint)1 MethodType.methodType (java.lang.invoke.MethodType.methodType)1