Search in sources :

Example 11 with OperatorMethodHandle

use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.

the class TypeOperators method adaptNeverNullEqualToDistinctFrom.

private static OperatorMethodHandle adaptNeverNullEqualToDistinctFrom(MethodHandle neverNullEqual) {
    // boolean distinctFrom(T left, boolean leftIsNull, T right, boolean rightIsNull)
    // {
    // if (leftIsNull || rightIsNull) {
    // return leftIsNull ^ rightIsNull;
    // }
    // return notEqual(equalOperator.invokeExact(left, leftIsNull, right, rightIsNull));
    // }
    MethodHandle eitherArgIsNull = LOGICAL_OR;
    eitherArgIsNull = dropArguments(eitherArgIsNull, 0, neverNullEqual.type().parameterType(0));
    eitherArgIsNull = dropArguments(eitherArgIsNull, 2, neverNullEqual.type().parameterType(1));
    MethodHandle distinctNullValues = LOGICAL_XOR;
    distinctNullValues = dropArguments(distinctNullValues, 0, neverNullEqual.type().parameterType(0));
    distinctNullValues = dropArguments(distinctNullValues, 2, neverNullEqual.type().parameterType(1));
    MethodHandle notEqual = filterReturnValue(neverNullEqual, NOT_EQUAL);
    notEqual = dropArguments(notEqual, 1, boolean.class);
    notEqual = dropArguments(notEqual, 3, boolean.class);
    return new OperatorMethodHandle(simpleConvention(FAIL_ON_NULL, NULL_FLAG, NULL_FLAG), guardWithTest(eitherArgIsNull, distinctNullValues, notEqual));
}
Also used : OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle) MethodHandle(java.lang.invoke.MethodHandle) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle)

Example 12 with OperatorMethodHandle

use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.

the class TypeOperators method adaptNeverNullComparisonToOrdering.

// 
// Adapt comparison to ordering
// 
private static OperatorMethodHandle adaptNeverNullComparisonToOrdering(SortOrder sortOrder, MethodHandle neverNullComparison) {
    MethodType finalSignature = MethodType.methodType(int.class, boolean.class, neverNullComparison.type().parameterType(0), boolean.class, neverNullComparison.type().parameterType(1));
    // (leftIsNull, rightIsNull, leftValue, rightValue)::int
    MethodHandle order = adaptComparisonToOrdering(sortOrder, neverNullComparison);
    // (leftIsNull, leftValue, rightIsNull, rightValue)::int
    order = permuteArguments(order, finalSignature, 0, 2, 1, 3);
    return new OperatorMethodHandle(simpleConvention(FAIL_ON_NULL, NULL_FLAG, NULL_FLAG), order);
}
Also used : MethodType(java.lang.invoke.MethodType) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle) MethodHandle(java.lang.invoke.MethodHandle) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle)

Example 13 with OperatorMethodHandle

use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.

the class TypeOperators method adaptBlockPositionComparisonToOrdering.

private static OperatorMethodHandle adaptBlockPositionComparisonToOrdering(SortOrder sortOrder, MethodHandle blockPositionComparison) {
    MethodType finalSignature = MethodType.methodType(int.class, Block.class, int.class, Block.class, int.class);
    // (leftIsNull, rightIsNull, leftBlock, leftPosition, rightBlock, rightPosition)::int
    MethodHandle order = adaptComparisonToOrdering(sortOrder, blockPositionComparison);
    // (leftBlock, leftPosition, rightBlock, rightPosition, leftBlock, leftPosition, rightBlock, rightPosition)::int
    order = collectArguments(order, 1, BLOCK_IS_NULL);
    order = collectArguments(order, 0, BLOCK_IS_NULL);
    // (leftBlock, leftPosition, rightBlock, rightPosition)::int
    order = permuteArguments(order, finalSignature, 0, 1, 2, 3, 0, 1, 2, 3);
    return new OperatorMethodHandle(simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION), order);
}
Also used : MethodType(java.lang.invoke.MethodType) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle) MethodHandle(java.lang.invoke.MethodHandle) OperatorMethodHandle(io.trino.spi.function.OperatorMethodHandle)

Aggregations

OperatorMethodHandle (io.trino.spi.function.OperatorMethodHandle)13 MethodHandle (java.lang.invoke.MethodHandle)13 StandardErrorCode (io.trino.spi.StandardErrorCode)5 TrinoException (io.trino.spi.TrinoException)5 Block (io.trino.spi.block.Block)5 BlockBuilder (io.trino.spi.block.BlockBuilder)5 BlockBuilderStatus (io.trino.spi.block.BlockBuilderStatus)5 RowBlockBuilder (io.trino.spi.block.RowBlockBuilder)5 ConnectorSession (io.trino.spi.connector.ConnectorSession)5 InvocationConvention (io.trino.spi.function.InvocationConvention)5 BLOCK_POSITION (io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION)5 BOXED_NULLABLE (io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.BOXED_NULLABLE)5 NEVER_NULL (io.trino.spi.function.InvocationConvention.InvocationArgumentConvention.NEVER_NULL)5 FAIL_ON_NULL (io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL)5 NULLABLE_RETURN (io.trino.spi.function.InvocationConvention.InvocationReturnConvention.NULLABLE_RETURN)5 InvocationConvention.simpleConvention (io.trino.spi.function.InvocationConvention.simpleConvention)5 ROW (io.trino.spi.type.StandardTypes.ROW)5 NULL_HASH_CODE (io.trino.spi.type.TypeUtils.NULL_HASH_CODE)5 FALSE (java.lang.Boolean.FALSE)5 TRUE (java.lang.Boolean.TRUE)5