Skip to content

Commit

Permalink
Rename FunctionInvoker to ScalarImplementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Sep 4, 2022
1 parent 728da10 commit bed3b0b
Show file tree
Hide file tree
Showing 40 changed files with 129 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface FunctionBundle

FunctionDependencyDeclaration getFunctionDependencies(FunctionId functionId, BoundSignature boundSignature);

FunctionInvoker getScalarFunctionInvoker(
ScalarFunctionImplementation getScalarFunctionImplementation(
FunctionId functionId,
BoundSignature boundSignature,
FunctionDependencies functionDependencies,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ public interface FunctionDependencies

FunctionNullability getCastNullability(Type fromType, Type toType);

FunctionInvoker getFunctionInvoker(QualifiedFunctionName name, List<Type> parameterTypes, InvocationConvention invocationConvention);
ScalarFunctionImplementation getScalarFunctionImplementation(QualifiedFunctionName name, List<Type> parameterTypes, InvocationConvention invocationConvention);

FunctionInvoker getFunctionSignatureInvoker(QualifiedFunctionName name, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention);
ScalarFunctionImplementation getScalarFunctionImplementationSignature(QualifiedFunctionName name, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention);

FunctionInvoker getOperatorInvoker(OperatorType operatorType, List<Type> parameterTypes, InvocationConvention invocationConvention);
ScalarFunctionImplementation getOperatorImplementation(OperatorType operatorType, List<Type> parameterTypes, InvocationConvention invocationConvention);

FunctionInvoker getOperatorSignatureInvoker(OperatorType operatorType, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention);
ScalarFunctionImplementation getOperatorImplementationSignature(OperatorType operatorType, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention);

FunctionInvoker getCastInvoker(Type fromType, Type toType, InvocationConvention invocationConvention);
ScalarFunctionImplementation getCastImplementation(Type fromType, Type toType, InvocationConvention invocationConvention);

FunctionInvoker getCastSignatureInvoker(TypeSignature fromType, TypeSignature toType, InvocationConvention invocationConvention);
ScalarFunctionImplementation getCastImplementationSignature(TypeSignature fromType, TypeSignature toType, InvocationConvention invocationConvention);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

public class FunctionManager
{
private final NonEvictableCache<FunctionKey, FunctionInvoker> specializedScalarCache;
private final NonEvictableCache<FunctionKey, ScalarFunctionImplementation> specializedScalarCache;
private final NonEvictableCache<FunctionKey, AggregationMetadata> specializedAggregationCache;
private final NonEvictableCache<FunctionKey, WindowFunctionSupplier> specializedWindowCache;

Expand All @@ -75,27 +75,27 @@ public FunctionManager(GlobalFunctionCatalog globalFunctionCatalog)
this.globalFunctionCatalog = globalFunctionCatalog;
}

public FunctionInvoker getScalarFunctionInvoker(ResolvedFunction resolvedFunction, InvocationConvention invocationConvention)
public ScalarFunctionImplementation getScalarFunctionImplementation(ResolvedFunction resolvedFunction, InvocationConvention invocationConvention)
{
try {
return uncheckedCacheGet(specializedScalarCache, new FunctionKey(resolvedFunction, invocationConvention), () -> getScalarFunctionInvokerInternal(resolvedFunction, invocationConvention));
return uncheckedCacheGet(specializedScalarCache, new FunctionKey(resolvedFunction, invocationConvention), () -> getScalarFunctionImplementationInternal(resolvedFunction, invocationConvention));
}
catch (UncheckedExecutionException e) {
throwIfInstanceOf(e.getCause(), TrinoException.class);
throw new RuntimeException(e.getCause());
}
}

private FunctionInvoker getScalarFunctionInvokerInternal(ResolvedFunction resolvedFunction, InvocationConvention invocationConvention)
private ScalarFunctionImplementation getScalarFunctionImplementationInternal(ResolvedFunction resolvedFunction, InvocationConvention invocationConvention)
{
FunctionDependencies functionDependencies = getFunctionDependencies(resolvedFunction);
FunctionInvoker functionInvoker = globalFunctionCatalog.getScalarFunctionInvoker(
ScalarFunctionImplementation scalarFunctionImplementation = globalFunctionCatalog.getScalarFunctionImplementation(
resolvedFunction.getFunctionId(),
resolvedFunction.getSignature(),
functionDependencies,
invocationConvention);
verifyMethodHandleSignature(resolvedFunction.getSignature(), functionInvoker, invocationConvention);
return functionInvoker;
verifyMethodHandleSignature(resolvedFunction.getSignature(), scalarFunctionImplementation, invocationConvention);
return scalarFunctionImplementation;
}

public AggregationMetadata getAggregateFunctionImplementation(ResolvedFunction resolvedFunction)
Expand Down Expand Up @@ -140,12 +140,12 @@ private WindowFunctionSupplier getWindowFunctionImplementationInternal(ResolvedF

private FunctionDependencies getFunctionDependencies(ResolvedFunction resolvedFunction)
{
return new InternalFunctionDependencies(this::getScalarFunctionInvoker, resolvedFunction.getTypeDependencies(), resolvedFunction.getFunctionDependencies());
return new InternalFunctionDependencies(this::getScalarFunctionImplementation, resolvedFunction.getTypeDependencies(), resolvedFunction.getFunctionDependencies());
}

private static void verifyMethodHandleSignature(BoundSignature boundSignature, FunctionInvoker functionInvoker, InvocationConvention convention)
private static void verifyMethodHandleSignature(BoundSignature boundSignature, ScalarFunctionImplementation scalarFunctionImplementation, InvocationConvention convention)
{
MethodHandle methodHandle = functionInvoker.getMethodHandle();
MethodHandle methodHandle = scalarFunctionImplementation.getMethodHandle();
MethodType methodType = methodHandle.type();

checkArgument(convention.getArgumentConventions().size() == boundSignature.getArgumentTypes().size(),
Expand All @@ -155,16 +155,16 @@ private static void verifyMethodHandleSignature(BoundSignature boundSignature, F
.mapToInt(InvocationArgumentConvention::getParameterCount)
.sum();
expectedParameterCount += methodType.parameterList().stream().filter(ConnectorSession.class::equals).count();
if (functionInvoker.getInstanceFactory().isPresent()) {
if (scalarFunctionImplementation.getInstanceFactory().isPresent()) {
expectedParameterCount++;
}
checkArgument(expectedParameterCount == methodType.parameterCount(),
"Expected %s method parameters, but got %s", expectedParameterCount, methodType.parameterCount());

int parameterIndex = 0;
if (functionInvoker.getInstanceFactory().isPresent()) {
if (scalarFunctionImplementation.getInstanceFactory().isPresent()) {
verifyFunctionSignature(convention.supportsInstanceFactory(), "Method requires instance factory, but calling convention does not support an instance factory");
MethodHandle factoryMethod = functionInvoker.getInstanceFactory().orElseThrow();
MethodHandle factoryMethod = scalarFunctionImplementation.getInstanceFactory().orElseThrow();
verifyFunctionSignature(methodType.parameterType(parameterIndex).equals(factoryMethod.type().returnType()), "Invalid return type");
parameterIndex++;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ private static void verifyMethodHandleSignature(BoundSignature boundSignature, F
verifyFunctionSignature(parameterType.equals(InOut.class), "Expected IN_OUT argument type to be InOut");
break;
case FUNCTION:
Class<?> lambdaInterface = functionInvoker.getLambdaInterfaces().get(lambdaArgumentIndex);
Class<?> lambdaInterface = scalarFunctionImplementation.getLambdaInterfaces().get(lambdaArgumentIndex);
verifyFunctionSignature(parameterType.equals(lambdaInterface),
"Expected function interface to be %s, but is %s", lambdaInterface, parameterType);
lambdaArgumentIndex++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ public FunctionDependencyDeclaration getFunctionDependencies(FunctionId function
return functions.getFunctionBundle(functionId).getFunctionDependencies(functionId, boundSignature);
}

public FunctionInvoker getScalarFunctionInvoker(
public ScalarFunctionImplementation getScalarFunctionImplementation(
FunctionId functionId,
BoundSignature boundSignature,
FunctionDependencies functionDependencies,
InvocationConvention invocationConvention)
{
return functions.getFunctionBundle(functionId).getScalarFunctionInvoker(functionId, boundSignature, functionDependencies, invocationConvention);
return functions.getFunctionBundle(functionId).getScalarFunctionImplementation(functionId, boundSignature, functionDependencies, invocationConvention);
}

private static class FunctionMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public FunctionDependencyDeclaration getFunctionDependencies(FunctionId function
}

@Override
public FunctionInvoker getScalarFunctionInvoker(
public ScalarFunctionImplementation getScalarFunctionImplementation(
FunctionId functionId,
BoundSignature boundSignature,
FunctionDependencies functionDependencies,
Expand All @@ -126,7 +126,7 @@ public FunctionInvoker getScalarFunctionInvoker(
throwIfInstanceOf(e.getCause(), TrinoException.class);
throw new RuntimeException(e.getCause());
}
return specializedSqlScalarFunction.getScalarFunctionInvoker(invocationConvention);
return specializedSqlScalarFunction.getScalarFunctionImplementation(invocationConvention);
}

private SpecializedSqlScalarFunction specializeScalarFunction(FunctionId functionId, BoundSignature boundSignature, FunctionDependencies functionDependencies)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
public class InternalFunctionDependencies
implements FunctionDependencies
{
private final BiFunction<ResolvedFunction, InvocationConvention, FunctionInvoker> specialization;
private final BiFunction<ResolvedFunction, InvocationConvention, ScalarFunctionImplementation> specialization;
private final Map<TypeSignature, Type> types;
private final Map<FunctionKey, ResolvedFunction> functions;
private final Map<OperatorKey, ResolvedFunction> operators;
private final Map<CastKey, ResolvedFunction> casts;

public InternalFunctionDependencies(
BiFunction<ResolvedFunction, InvocationConvention, FunctionInvoker> specialization,
BiFunction<ResolvedFunction, InvocationConvention, ScalarFunctionImplementation> specialization,
Map<TypeSignature, Type> typeDependencies,
Collection<ResolvedFunction> functionDependencies)
{
Expand Down Expand Up @@ -112,7 +112,7 @@ public FunctionNullability getCastNullability(Type fromType, Type toType)
}

@Override
public FunctionInvoker getFunctionInvoker(QualifiedFunctionName name, List<Type> parameterTypes, InvocationConvention invocationConvention)
public ScalarFunctionImplementation getScalarFunctionImplementation(QualifiedFunctionName name, List<Type> parameterTypes, InvocationConvention invocationConvention)
{
FunctionKey functionKey = new FunctionKey(name, toTypeSignatures(parameterTypes));
ResolvedFunction resolvedFunction = functions.get(functionKey);
Expand All @@ -123,7 +123,7 @@ public FunctionInvoker getFunctionInvoker(QualifiedFunctionName name, List<Type>
}

@Override
public FunctionInvoker getFunctionSignatureInvoker(QualifiedFunctionName name, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention)
public ScalarFunctionImplementation getScalarFunctionImplementationSignature(QualifiedFunctionName name, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention)
{
FunctionKey functionKey = new FunctionKey(name, parameterTypes);
ResolvedFunction resolvedFunction = functions.get(functionKey);
Expand All @@ -134,7 +134,7 @@ public FunctionInvoker getFunctionSignatureInvoker(QualifiedFunctionName name, L
}

@Override
public FunctionInvoker getOperatorInvoker(OperatorType operatorType, List<Type> parameterTypes, InvocationConvention invocationConvention)
public ScalarFunctionImplementation getOperatorImplementation(OperatorType operatorType, List<Type> parameterTypes, InvocationConvention invocationConvention)
{
OperatorKey operatorKey = new OperatorKey(operatorType, toTypeSignatures(parameterTypes));
ResolvedFunction resolvedFunction = operators.get(operatorKey);
Expand All @@ -145,7 +145,7 @@ public FunctionInvoker getOperatorInvoker(OperatorType operatorType, List<Type>
}

@Override
public FunctionInvoker getOperatorSignatureInvoker(OperatorType operatorType, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention)
public ScalarFunctionImplementation getOperatorImplementationSignature(OperatorType operatorType, List<TypeSignature> parameterTypes, InvocationConvention invocationConvention)
{
OperatorKey operatorKey = new OperatorKey(operatorType, parameterTypes);
ResolvedFunction resolvedFunction = operators.get(operatorKey);
Expand All @@ -156,7 +156,7 @@ public FunctionInvoker getOperatorSignatureInvoker(OperatorType operatorType, Li
}

@Override
public FunctionInvoker getCastInvoker(Type fromType, Type toType, InvocationConvention invocationConvention)
public ScalarFunctionImplementation getCastImplementation(Type fromType, Type toType, InvocationConvention invocationConvention)
{
CastKey castKey = new CastKey(fromType.getTypeSignature(), toType.getTypeSignature());
ResolvedFunction resolvedFunction = casts.get(castKey);
Expand All @@ -167,7 +167,7 @@ public FunctionInvoker getCastInvoker(Type fromType, Type toType, InvocationConv
}

@Override
public FunctionInvoker getCastSignatureInvoker(TypeSignature fromType, TypeSignature toType, InvocationConvention invocationConvention)
public ScalarFunctionImplementation getCastImplementationSignature(TypeSignature fromType, TypeSignature toType, InvocationConvention invocationConvention)
{
CastKey castKey = new CastKey(fromType, toType);
ResolvedFunction resolvedFunction = casts.get(castKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

import static java.util.Objects.requireNonNull;

public class FunctionInvoker
public class ScalarFunctionImplementation
{
private final MethodHandle methodHandle;
private final Optional<MethodHandle> instanceFactory;
private final List<Class<?>> lambdaInterfaces;

private FunctionInvoker(MethodHandle methodHandle, Optional<MethodHandle> instanceFactory, List<Class<?>> lambdaInterfaces)
private ScalarFunctionImplementation(MethodHandle methodHandle, Optional<MethodHandle> instanceFactory, List<Class<?>> lambdaInterfaces)
{
this.methodHandle = requireNonNull(methodHandle, "methodHandle is null");
this.instanceFactory = requireNonNull(instanceFactory, "instanceFactory is null");
Expand Down Expand Up @@ -80,9 +80,9 @@ public Builder lambdaInterfaces(List<Class<?>> lambdaInterfaces)
return this;
}

public FunctionInvoker build()
public ScalarFunctionImplementation build()
{
return new FunctionInvoker(methodHandle, Optional.ofNullable(instanceFactory), lambdaInterfaces);
return new ScalarFunctionImplementation(methodHandle, Optional.ofNullable(instanceFactory), lambdaInterfaces);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.trino.metadata.FunctionBinding;
import io.trino.metadata.FunctionDependencies;
import io.trino.metadata.FunctionDependencyDeclaration.FunctionDependencyDeclarationBuilder;
import io.trino.metadata.FunctionInvoker;
import io.trino.metadata.ScalarFunctionImplementation;
import io.trino.spi.function.InvocationConvention;
import io.trino.spi.type.TypeSignature;

Expand Down Expand Up @@ -55,11 +55,11 @@ public void declareDependencies(FunctionDependencyDeclarationBuilder builder)
}

@Override
protected FunctionInvoker getInvoker(FunctionBinding functionBinding, FunctionDependencies functionDependencies, InvocationConvention invocationConvention)
protected ScalarFunctionImplementation getImplementation(FunctionBinding functionBinding, FunctionDependencies functionDependencies, InvocationConvention invocationConvention)
{
TypeSignature from = applyBoundVariables(fromType, functionBinding);
TypeSignature to = applyBoundVariables(toType, functionBinding);
return functionDependencies.getCastSignatureInvoker(from, to, invocationConvention);
return functionDependencies.getCastImplementationSignature(from, to, invocationConvention);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import io.trino.metadata.FunctionBinding;
import io.trino.metadata.FunctionDependencies;
import io.trino.metadata.FunctionDependencyDeclaration.FunctionDependencyDeclarationBuilder;
import io.trino.metadata.FunctionInvoker;
import io.trino.metadata.QualifiedFunctionName;
import io.trino.metadata.ScalarFunctionImplementation;
import io.trino.spi.function.InvocationConvention;
import io.trino.spi.type.TypeSignature;

Expand Down Expand Up @@ -57,10 +57,10 @@ public void declareDependencies(FunctionDependencyDeclarationBuilder builder)
}

@Override
protected FunctionInvoker getInvoker(FunctionBinding functionBinding, FunctionDependencies functionDependencies, InvocationConvention invocationConvention)
protected ScalarFunctionImplementation getImplementation(FunctionBinding functionBinding, FunctionDependencies functionDependencies, InvocationConvention invocationConvention)
{
List<TypeSignature> types = applyBoundVariables(argumentTypes, functionBinding);
return functionDependencies.getFunctionSignatureInvoker(fullyQualifiedFunctionName, types, invocationConvention);
return functionDependencies.getScalarFunctionImplementationSignature(fullyQualifiedFunctionName, types, invocationConvention);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.trino.metadata.FunctionBinding;
import io.trino.metadata.FunctionDependencies;
import io.trino.metadata.FunctionDependencyDeclaration.FunctionDependencyDeclarationBuilder;
import io.trino.metadata.FunctionInvoker;
import io.trino.metadata.ScalarFunctionImplementation;
import io.trino.spi.function.InvocationConvention;
import io.trino.spi.function.OperatorType;
import io.trino.spi.type.TypeSignature;
Expand Down Expand Up @@ -62,10 +62,10 @@ public void declareDependencies(FunctionDependencyDeclarationBuilder builder)
}

@Override
protected FunctionInvoker getInvoker(FunctionBinding functionBinding, FunctionDependencies functionDependencies, InvocationConvention invocationConvention)
protected ScalarFunctionImplementation getImplementation(FunctionBinding functionBinding, FunctionDependencies functionDependencies, InvocationConvention invocationConvention)
{
List<TypeSignature> types = applyBoundVariables(argumentTypes, functionBinding);
return functionDependencies.getOperatorSignatureInvoker(operator, types, invocationConvention);
return functionDependencies.getOperatorImplementationSignature(operator, types, invocationConvention);
}

@Override
Expand Down
Loading

0 comments on commit bed3b0b

Please sign in to comment.