Skip to content

Commit

Permalink
Remove TypeManager from BuiltInFunctionNamespaceManager
Browse files Browse the repository at this point in the history
  • Loading branch information
rongrong authored and Rongrong Zhong committed Oct 13, 2020
1 parent ca07a42 commit 7fffbd8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public class BuiltInFunctionNamespaceManager
public static final CatalogSchemaName DEFAULT_NAMESPACE = new CatalogSchemaName("presto", "default");
public static final String ID = "builtin";

private final TypeManager typeManager;
private final FunctionAndTypeManager functionAndTypeManager;
private final LoadingCache<Signature, SpecializedFunctionKey> specializedFunctionKeyCache;
private final LoadingCache<SpecializedFunctionKey, ScalarFunctionImplementation> specializedScalarCache;
private final LoadingCache<SpecializedFunctionKey, InternalAggregationFunction> specializedAggregationCache;
Expand All @@ -400,12 +400,11 @@ public class BuiltInFunctionNamespaceManager
private volatile FunctionMap functions = new FunctionMap();

public BuiltInFunctionNamespaceManager(
TypeManager typeManager,
BlockEncodingSerde blockEncodingSerde,
FeaturesConfig featuresConfig,
FunctionAndTypeManager functionAndTypeManager)
{
this.typeManager = requireNonNull(typeManager, "typeManager is null");
this.functionAndTypeManager = requireNonNull(functionAndTypeManager, "functionAndTypeManager is null");
this.magicLiteralFunction = new MagicLiteralFunction(blockEncodingSerde);

specializedFunctionKeyCache = CacheBuilder.newBuilder()
Expand Down Expand Up @@ -925,10 +924,10 @@ private SpecializedFunctionKey doGetSpecializedFunctionKey(Signature signature)
{
Iterable<SqlFunction> candidates = getFunctions(null, signature.getName());
// search for exact match
Type returnType = typeManager.getType(signature.getReturnType());
Type returnType = functionAndTypeManager.getType(signature.getReturnType());
List<TypeSignatureProvider> argumentTypeSignatureProviders = fromTypeSignatures(signature.getArgumentTypes());
for (SqlFunction candidate : candidates) {
Optional<BoundVariables> boundVariables = new SignatureBinder(typeManager, candidate.getSignature(), false)
Optional<BoundVariables> boundVariables = new SignatureBinder(functionAndTypeManager, candidate.getSignature(), false)
.bindVariables(argumentTypeSignatureProviders, returnType);
if (boundVariables.isPresent()) {
return new SpecializedFunctionKey(candidate, boundVariables.get(), argumentTypeSignatureProviders.size());
Expand All @@ -937,22 +936,22 @@ private SpecializedFunctionKey doGetSpecializedFunctionKey(Signature signature)

// TODO: hack because there could be "type only" coercions (which aren't necessarily included as implicit casts),
// so do a second pass allowing "type only" coercions
List<Type> argumentTypes = resolveTypes(signature.getArgumentTypes(), typeManager);
List<Type> argumentTypes = resolveTypes(signature.getArgumentTypes(), functionAndTypeManager);
for (SqlFunction candidate : candidates) {
SignatureBinder binder = new SignatureBinder(typeManager, candidate.getSignature(), true);
SignatureBinder binder = new SignatureBinder(functionAndTypeManager, candidate.getSignature(), true);
Optional<BoundVariables> boundVariables = binder.bindVariables(argumentTypeSignatureProviders, returnType);
if (!boundVariables.isPresent()) {
continue;
}
Signature boundSignature = applyBoundVariables(candidate.getSignature(), boundVariables.get(), argumentTypes.size());

if (!typeManager.isTypeOnlyCoercion(typeManager.getType(boundSignature.getReturnType()), returnType)) {
if (!functionAndTypeManager.isTypeOnlyCoercion(functionAndTypeManager.getType(boundSignature.getReturnType()), returnType)) {
continue;
}
boolean nonTypeOnlyCoercion = false;
for (int i = 0; i < argumentTypes.size(); i++) {
Type expectedType = typeManager.getType(boundSignature.getArgumentTypes().get(i));
if (!typeManager.isTypeOnlyCoercion(argumentTypes.get(i), expectedType)) {
Type expectedType = functionAndTypeManager.getType(boundSignature.getArgumentTypes().get(i));
if (!functionAndTypeManager.isTypeOnlyCoercion(argumentTypes.get(i), expectedType)) {
nonTypeOnlyCoercion = true;
break;
}
Expand All @@ -971,11 +970,11 @@ private SpecializedFunctionKey doGetSpecializedFunctionKey(Signature signature)
String typeName = signature.getNameSuffix().substring(MAGIC_LITERAL_FUNCTION_PREFIX.length());

// lookup the type
Type type = typeManager.getType(parseTypeSignature(typeName));
Type type = functionAndTypeManager.getType(parseTypeSignature(typeName));

// verify we have one parameter of the proper type
checkArgument(parameterTypes.size() == 1, "Expected one argument to literal function, but got %s", parameterTypes);
Type parameterType = typeManager.getType(parameterTypes.get(0));
Type parameterType = functionAndTypeManager.getType(parameterTypes.get(0));
requireNonNull(parameterType, format("Type %s not found", parameterTypes.get(0)));

return new SpecializedFunctionKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public FunctionAndTypeManager(
HandleResolver handleResolver)
{
this.transactionManager = requireNonNull(transactionManager, "transactionManager is null");
this.builtInFunctionNamespaceManager = new BuiltInFunctionNamespaceManager(typeManager, blockEncodingSerde, featuresConfig, this);
this.builtInFunctionNamespaceManager = new BuiltInFunctionNamespaceManager(blockEncodingSerde, featuresConfig, this);
this.functionNamespaceManagers.put(DEFAULT_NAMESPACE.getCatalogName(), builtInFunctionNamespaceManager);
this.functionInvokerProvider = new FunctionInvokerProvider(this);
this.handleResolver = requireNonNull(handleResolver, "handleResolver is null");
Expand Down

0 comments on commit 7fffbd8

Please sign in to comment.