use of com.facebook.presto.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL 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));
}
Aggregations