use of io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL 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));
}
use of io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL in project trino by trinodb.
the class FormatFunction method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
Type rowType = boundSignature.getArgumentType(1);
List<BiFunction<ConnectorSession, Block, Object>> converters = mapWithIndex(rowType.getTypeParameters().stream(), (type, index) -> converter(functionDependencies, type, toIntExact(index))).collect(toImmutableList());
return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, ImmutableList.of(NEVER_NULL, NEVER_NULL), METHOD_HANDLE.bindTo(converters));
}
use of io.trino.spi.function.InvocationConvention.InvocationReturnConvention.FAIL_ON_NULL 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