Search in sources :

Example 6 with BLOCK_POSITION

use of io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION in project trino by trinodb.

the class RowType method getIndeterminateOperatorInvokers.

private static List<OperatorMethodHandle> getIndeterminateOperatorInvokers(TypeOperators typeOperators, List<Field> fields) {
    boolean comparable = fields.stream().allMatch(field -> field.getType().isComparable());
    if (!comparable) {
        return emptyList();
    }
    // for large rows, use a generic loop with a megamorphic call site
    if (fields.size() > MEGAMORPHIC_FIELD_COUNT) {
        List<MethodHandle> indeterminateOperators = fields.stream().map(field -> typeOperators.getIndeterminateOperator(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION))).collect(toUnmodifiableList());
        return singletonList(new OperatorMethodHandle(INDETERMINATE_CONVENTION, INDETERMINATE.bindTo(indeterminateOperators)));
    }
    // (Block):long
    MethodHandle indeterminate = dropArguments(constant(boolean.class, false), 0, Block.class);
    for (int fieldId = 0; fieldId < fields.size(); fieldId++) {
        Field field = fields.get(fieldId);
        // (Block, int, MethodHandle, Block):boolean
        indeterminate = collectArguments(CHAIN_INDETERMINATE, 0, indeterminate);
        // field indeterminate
        MethodHandle fieldIndeterminateOperator = typeOperators.getIndeterminateOperator(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION));
        // (Block, Block):boolean
        indeterminate = insertArguments(indeterminate, 1, fieldId, fieldIndeterminateOperator);
        // (Block):boolean
        indeterminate = permuteArguments(indeterminate, methodType(boolean.class, Block.class), 0, 0);
    }
    return singletonList(new OperatorMethodHandle(INDETERMINATE_CONVENTION, indeterminate));
}
Also used : MethodHandle(java.lang.invoke.MethodHandle) Arrays(java.util.Arrays) BLOCK_POSITION(io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION) MethodHandles.dropArguments(java.lang.invoke.MethodHandles.dropArguments) ROW(io.trino.spi.type.StandardTypes.ROW) FAIL_ON_NULL(io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL) BiFunction(java.util.function.BiFunction) MethodHandles.insertArguments(java.lang.invoke.MethodHandles.insertArguments) InvocationConvention.simpleConvention(io.trino.spi.function.InvocationConvention.simpleConvention) Function(java.util.function.Function) MethodHandles.lookup(java.lang.invoke.MethodHandles.lookup) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) Lookup(java.lang.invoke.MethodHandles.Lookup) Block(io.trino.spi.block.Block) Objects.requireNonNull(java.util.Objects.requireNonNull) NULL_HASH_CODE(io.trino.spi.type.TypeUtils.NULL_HASH_CODE) NULLABLE_RETURN(io.trino.spi.function.InvocationConvention.InvocationReturnConvention.NULLABLE_RETURN) MethodType.methodType(java.lang.invoke.MethodType.methodType) FALSE(java.lang.Boolean.FALSE) MethodHandles.constant(java.lang.invoke.MethodHandles.constant) BlockBuilderStatus(io.trino.spi.block.BlockBuilderStatus) Collections.emptyList(java.util.Collections.emptyList) BOXED_NULLABLE(io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BOXED_NULLABLE) MethodHandles.permuteArguments(java.lang.invoke.MethodHandles.permuteArguments) TrinoException(io.trino.spi.TrinoException) ConnectorSession(io.trino.spi.connector.ConnectorSession) List(java.util.List) InvocationConvention(io.trino.spi.function.InvocationConvention) MethodHandles.collectArguments(java.lang.invoke.MethodHandles.collectArguments) StandardErrorCode(io.trino.spi.StandardErrorCode) Optional(java.util.Optional) BlockBuilder(io.trino.spi.block.BlockBuilder) RowBlockBuilder(io.trino.spi.block.RowBlockBuilder) Collections(java.util.Collections) TRUE(java.lang.Boolean.TRUE) NEVER_NULL(io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.NEVER_NULL) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle) MethodHandle(java.lang.invoke.MethodHandle) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle)

Aggregations

Block (io.trino.spi.block.Block)6 BLOCK_POSITION (io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION)6 FAIL_ON_NULL (io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL)6 StandardErrorCode (io.trino.spi.StandardErrorCode)5 TrinoException (io.trino.spi.TrinoException)5 InvocationConvention (io.trino.spi.function.InvocationConvention)5 BOXED_NULLABLE (io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BOXED_NULLABLE)5 NEVER_NULL (io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.NEVER_NULL)5 NULLABLE_RETURN (io.trino.spi.function.InvocationConvention.InvocationReturnConvention.NULLABLE_RETURN)5 MethodHandle (java.lang.invoke.MethodHandle)5 MethodHandles.collectArguments (java.lang.invoke.MethodHandles.collectArguments)5 MethodHandles.constant (java.lang.invoke.MethodHandles.constant)5 MethodHandles.dropArguments (java.lang.invoke.MethodHandles.dropArguments)5 MethodHandles.insertArguments (java.lang.invoke.MethodHandles.insertArguments)5 MethodHandles.lookup (java.lang.invoke.MethodHandles.lookup)5 MethodHandles.permuteArguments (java.lang.invoke.MethodHandles.permuteArguments)5 MethodType.methodType (java.lang.invoke.MethodType.methodType)5 List (java.util.List)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Optional (java.util.Optional)5