use of com.facebook.presto.sql.FunctionInvoker in project presto by prestodb.
the class MapSubscriptOperator method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, TypeManager typeManager, FunctionRegistry functionRegistry) {
Type keyType = boundVariables.getTypeVariable("K");
Type valueType = boundVariables.getTypeVariable("V");
MethodHandle keyEqualsMethod = functionRegistry.getScalarFunctionImplementation(internalOperator(OperatorType.EQUAL, BooleanType.BOOLEAN, ImmutableList.of(keyType, keyType))).getMethodHandle();
MethodHandle methodHandle;
if (keyType.getJavaType() == boolean.class) {
methodHandle = METHOD_HANDLE_BOOLEAN;
} else if (keyType.getJavaType() == long.class) {
methodHandle = METHOD_HANDLE_LONG;
} else if (keyType.getJavaType() == double.class) {
methodHandle = METHOD_HANDLE_DOUBLE;
} else if (keyType.getJavaType() == Slice.class) {
methodHandle = METHOD_HANDLE_SLICE;
} else {
methodHandle = METHOD_HANDLE_OBJECT;
}
methodHandle = MethodHandles.insertArguments(methodHandle, 0, legacyMissingKey);
FunctionInvoker functionInvoker = new FunctionInvoker(functionRegistry);
methodHandle = methodHandle.bindTo(functionInvoker).bindTo(keyEqualsMethod).bindTo(keyType).bindTo(valueType);
// this casting is necessary because otherwise presto byte code generator will generate illegal byte code
if (valueType.getJavaType() == void.class) {
methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(void.class));
} else {
methodHandle = methodHandle.asType(methodHandle.type().changeReturnType(Primitives.wrap(valueType.getJavaType())));
}
return new ScalarFunctionImplementation(true, ImmutableList.of(false, false), methodHandle, isDeterministic());
}
Aggregations