Search in sources :

Example 1 with OperatorDependency

use of com.facebook.presto.spi.function.OperatorDependency in project presto by prestodb.

the class MapDistinctFromOperator method isDistinctFrom.

@TypeParameter("K")
@TypeParameter("V")
@SqlType(StandardTypes.BOOLEAN)
public static boolean isDistinctFrom(@OperatorDependency(operator = EQUAL, argumentTypes = { "K", "K" }) MethodHandle keyEqualsFunction, @OperatorDependency(operator = HASH_CODE, argumentTypes = { "K" }) MethodHandle keyHashcodeFunction, @OperatorDependency(operator = IS_DISTINCT_FROM, argumentTypes = { "V", "V" }, convention = @Convention(arguments = { BLOCK_POSITION, BLOCK_POSITION }, result = FAIL_ON_NULL)) MethodHandle valueDistinctFromFunction, @TypeParameter("map(K, V)") Type mapType, @SqlType("map(K,V)") Block leftMapBlock, @IsNull boolean leftMapNull, @SqlType("map(K,V)") Block rightMapBlock, @IsNull boolean rightMapNull) {
    if (leftMapNull != rightMapNull) {
        return true;
    }
    if (leftMapNull) {
        return false;
    }
    Type keyType = ((MapType) mapType).getKeyType();
    MethodHandle keyBlockEqualsFunction = compose(keyEqualsFunction, nativeValueGetter(keyType));
    MethodHandle keyBlockHashCodeFunction = compose(keyHashcodeFunction, nativeValueGetter(keyType));
    // Note that we compare to NOT distinct here and so negate the result.
    return !MapGenericEquality.genericEqual(keyType, keyHashcodeFunction, keyBlockEqualsFunction, keyBlockHashCodeFunction, leftMapBlock, rightMapBlock, (leftMapIndex, rightMapIndex) -> !(boolean) valueDistinctFromFunction.invokeExact(leftMapBlock, leftMapIndex, rightMapBlock, rightMapIndex));
}
Also used : Convention(com.facebook.presto.spi.function.Convention) HASH_CODE(com.facebook.presto.common.function.OperatorType.HASH_CODE) MethodHandle(java.lang.invoke.MethodHandle) MapType(com.facebook.presto.common.type.MapType) StandardTypes(com.facebook.presto.common.type.StandardTypes) OperatorDependency(com.facebook.presto.spi.function.OperatorDependency) TypeParameter(com.facebook.presto.spi.function.TypeParameter) BLOCK_POSITION(com.facebook.presto.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION) MethodHandleUtil.compose(com.facebook.presto.common.block.MethodHandleUtil.compose) BlockPosition(com.facebook.presto.spi.function.BlockPosition) IS_DISTINCT_FROM(com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM) BlockIndex(com.facebook.presto.spi.function.BlockIndex) MethodHandleUtil.nativeValueGetter(com.facebook.presto.common.block.MethodHandleUtil.nativeValueGetter) ScalarOperator(com.facebook.presto.spi.function.ScalarOperator) IsNull(com.facebook.presto.spi.function.IsNull) EQUAL(com.facebook.presto.common.function.OperatorType.EQUAL) FAIL_ON_NULL(com.facebook.presto.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL) Block(com.facebook.presto.common.block.Block) Type(com.facebook.presto.common.type.Type) SqlType(com.facebook.presto.spi.function.SqlType) MapType(com.facebook.presto.common.type.MapType) Type(com.facebook.presto.common.type.Type) SqlType(com.facebook.presto.spi.function.SqlType) MapType(com.facebook.presto.common.type.MapType) MethodHandle(java.lang.invoke.MethodHandle) TypeParameter(com.facebook.presto.spi.function.TypeParameter) SqlType(com.facebook.presto.spi.function.SqlType)

Aggregations

Block (com.facebook.presto.common.block.Block)1 MethodHandleUtil.compose (com.facebook.presto.common.block.MethodHandleUtil.compose)1 MethodHandleUtil.nativeValueGetter (com.facebook.presto.common.block.MethodHandleUtil.nativeValueGetter)1 EQUAL (com.facebook.presto.common.function.OperatorType.EQUAL)1 HASH_CODE (com.facebook.presto.common.function.OperatorType.HASH_CODE)1 IS_DISTINCT_FROM (com.facebook.presto.common.function.OperatorType.IS_DISTINCT_FROM)1 MapType (com.facebook.presto.common.type.MapType)1 StandardTypes (com.facebook.presto.common.type.StandardTypes)1 Type (com.facebook.presto.common.type.Type)1 BlockIndex (com.facebook.presto.spi.function.BlockIndex)1 BlockPosition (com.facebook.presto.spi.function.BlockPosition)1 Convention (com.facebook.presto.spi.function.Convention)1 BLOCK_POSITION (com.facebook.presto.spi.function.InvocationConvention.InvocationArgumentConvention.BLOCK_POSITION)1 FAIL_ON_NULL (com.facebook.presto.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL)1 IsNull (com.facebook.presto.spi.function.IsNull)1 OperatorDependency (com.facebook.presto.spi.function.OperatorDependency)1 ScalarOperator (com.facebook.presto.spi.function.ScalarOperator)1 SqlType (com.facebook.presto.spi.function.SqlType)1 TypeParameter (com.facebook.presto.spi.function.TypeParameter)1 MethodHandle (java.lang.invoke.MethodHandle)1