use of io.trino.spi.function.InvocationConvention.InvocationReturnConvention.NULLABLE_RETURN in project trino by trinodb.
the class RowType method getEqualOperatorMethodHandles.
private static List<OperatorMethodHandle> getEqualOperatorMethodHandles(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> equalOperators = fields.stream().map(field -> typeOperators.getEqualOperator(field.getType(), simpleConvention(NULLABLE_RETURN, BLOCK_POSITION, BLOCK_POSITION))).collect(toUnmodifiableList());
return singletonList(new OperatorMethodHandle(EQUAL_CONVENTION, EQUAL.bindTo(equalOperators)));
}
// (Block, Block):Boolean
MethodHandle equal = dropArguments(constant(Boolean.class, TRUE), 0, Block.class, Block.class);
for (int fieldId = 0; fieldId < fields.size(); fieldId++) {
Field field = fields.get(fieldId);
// (Block, Block, int, MethodHandle, Block, Block):Boolean
equal = collectArguments(CHAIN_EQUAL, 0, equal);
// field equal
MethodHandle fieldEqualOperator = typeOperators.getEqualOperator(field.getType(), simpleConvention(NULLABLE_RETURN, BLOCK_POSITION, BLOCK_POSITION));
// (Block, Block, Block, Block):Boolean
equal = insertArguments(equal, 2, fieldId, fieldEqualOperator);
// (Block, Block):Boolean
equal = permuteArguments(equal, methodType(Boolean.class, Block.class, Block.class), 0, 1, 0, 1);
}
return singletonList(new OperatorMethodHandle(EQUAL_CONVENTION, equal));
}
use of io.trino.spi.function.InvocationConvention.InvocationReturnConvention.NULLABLE_RETURN in project trino by trinodb.
the class AbstractGreatestLeast method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
Type type = boundSignature.getReturnType();
checkArgument(type.isOrderable(), "Type must be orderable");
MethodHandle compareMethod = getMinMaxCompare(functionDependencies, type, simpleConvention(FAIL_ON_NULL, NEVER_NULL, NEVER_NULL), min);
List<Class<?>> javaTypes = IntStream.range(0, boundSignature.getArity()).mapToObj(i -> wrap(type.getJavaType())).collect(toImmutableList());
Class<?> clazz = generate(javaTypes, compareMethod);
MethodHandle methodHandle = methodHandle(clazz, getFunctionMetadata().getSignature().getName(), javaTypes.toArray(new Class<?>[0]));
return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, nCopies(javaTypes.size(), BOXED_NULLABLE), methodHandle);
}
Aggregations