Skip to content

Commit

Permalink
Clean up TypeManager APIs
Browse files Browse the repository at this point in the history
Some of the APIs in TypeManager are only relavent to the engine and not useful
to connectors / plugins. Remove the following functions from TypeManager:
* getTypes
* getParametricTypes
* getCommonSuperType
* isTypeOnlyCoercion
* coerceTypeBase
  • Loading branch information
rongrong committed Nov 10, 2020
1 parent ae66246 commit cd44d24
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
*/
package com.facebook.presto.common.type;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

public interface TypeManager
{
Expand All @@ -29,21 +27,5 @@ public interface TypeManager
*/
Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);

/**
* Gets a list of all registered types.
*/
List<Type> getTypes();

/**
* Gets all registered parametric types.
*/
Collection<ParametricType> getParametricTypes();

Optional<Type> getCommonSuperType(Type firstType, Type secondType);

boolean canCoerce(Type actualType, Type expectedType);

boolean isTypeOnlyCoercion(Type actualType, Type expectedType);

Optional<Type> coerceTypeBase(Type sourceType, String resultTypeBase);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@

import com.google.common.collect.ImmutableList;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

import static com.facebook.presto.common.type.BigintType.BIGINT;
import static com.facebook.presto.common.type.BooleanType.BOOLEAN;
Expand Down Expand Up @@ -49,39 +47,14 @@ public Type getParameterizedType(String baseTypeName, List<TypeSignatureParamete
return getType(new TypeSignature(baseTypeName, typeParameters));
}

@Override
public List<Type> getTypes()
{
return ImmutableList.of(BOOLEAN, BIGINT, DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, ID, HYPER_LOG_LOG);
}

@Override
public Collection<ParametricType> getParametricTypes()
{
return ImmutableList.of();
}

@Override
public Optional<Type> getCommonSuperType(Type firstType, Type secondType)
{
throw new UnsupportedOperationException();
}

@Override
public boolean canCoerce(Type actualType, Type expectedType)
{
throw new UnsupportedOperationException();
}

@Override
public boolean isTypeOnlyCoercion(Type actualType, Type expectedType)
{
return false;
}

@Override
public Optional<Type> coerceTypeBase(Type sourceType, String resultTypeBase)
private List<Type> getTypes()
{
throw new UnsupportedOperationException();
return ImmutableList.of(BOOLEAN, BIGINT, DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, ID, HYPER_LOG_LOG);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import com.facebook.presto.common.predicate.TupleDomain;
import com.facebook.presto.common.type.ParametricType;
import com.facebook.presto.common.type.Type;
import com.facebook.presto.common.type.TypeManager;
import com.facebook.presto.metadata.FunctionAndTypeManager;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.ConnectorTableMetadata;
import com.facebook.presto.spi.InMemoryRecordSet;
Expand Down Expand Up @@ -66,12 +66,12 @@ public class TypesJdbcTable
.column("num_prec_radix", BIGINT)
.build();

private final TypeManager typeManager;
private final FunctionAndTypeManager functionAndTypeManager;

@Inject
public TypesJdbcTable(TypeManager typeManager)
public TypesJdbcTable(FunctionAndTypeManager typeManager)
{
this.typeManager = requireNonNull(typeManager, "typeManager is null");
this.functionAndTypeManager = requireNonNull(typeManager, "typeManager is null");
}

@Override
Expand All @@ -84,10 +84,10 @@ public ConnectorTableMetadata getTableMetadata()
public RecordCursor cursor(ConnectorTransactionHandle transactionHandle, ConnectorSession connectorSession, TupleDomain<Integer> constraint)
{
Builder table = InMemoryRecordSet.builder(METADATA);
for (Type type : typeManager.getTypes()) {
for (Type type : functionAndTypeManager.getTypes()) {
addTypeRow(table, type);
}
addParametricTypeRows(table, typeManager.getParametricTypes());
addParametricTypeRows(table, functionAndTypeManager.getParametricTypes());
return table.build().cursor();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,32 @@ public void addFunctionNamespace(String catalogName, FunctionNamespaceManager fu
}
}

@Override
public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
{
Optional<FunctionNamespaceManager<?>> functionNamespaceManager = getServingFunctionNamespaceManager(functionHandle.getFunctionNamespace());
checkArgument(functionNamespaceManager.isPresent(), "Cannot find function namespace for '%s'", functionHandle.getFunctionNamespace());
return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
}

@Override
public Type getType(TypeSignature signature)
{
return builtInTypeRegistry.getType(signature);
}

@Override
public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
{
return builtInTypeRegistry.getParameterizedType(baseTypeName, typeParameters);
}

@Override
public boolean canCoerce(Type actualType, Type expectedType)
{
return builtInTypeRegistry.canCoerce(actualType, expectedType);
}

public FunctionInvokerProvider getFunctionInvokerProvider()
{
return functionInvokerProvider;
Expand Down Expand Up @@ -242,16 +268,6 @@ else if (!exists) {
}
}

public void addType(Type type)
{
builtInTypeRegistry.addType(type);
}

public void addParametricType(ParametricType parametricType)
{
builtInTypeRegistry.addParametricType(parametricType);
}

public static QualifiedFunctionName qualifyFunctionName(QualifiedName name)
{
if (!name.getPrefix().isPresent()) {
Expand Down Expand Up @@ -279,62 +295,41 @@ public FunctionHandle resolveFunction(Optional<TransactionId> transactionId, Qua
return resolveFunctionInternal(transactionId, functionName, parameterTypes);
}

@Override
public Type getType(TypeSignature signature)
public void addType(Type type)
{
return builtInTypeRegistry.getType(signature);
builtInTypeRegistry.addType(type);
}

@Override
public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
public void addParametricType(ParametricType parametricType)
{
return builtInTypeRegistry.getParameterizedType(baseTypeName, typeParameters);
builtInTypeRegistry.addParametricType(parametricType);
}

@Override
public List<Type> getTypes()
{
return builtInTypeRegistry.getTypes();
}

@Override
public Collection<ParametricType> getParametricTypes()
{
return builtInTypeRegistry.getParametricTypes();
}

@Override
public Optional<Type> getCommonSuperType(Type firstType, Type secondType)
{
return builtInTypeRegistry.getCommonSuperType(firstType, secondType);
}

@Override
public boolean canCoerce(Type actualType, Type expectedType)
{
return builtInTypeRegistry.canCoerce(actualType, expectedType);
}

@Override
public boolean isTypeOnlyCoercion(Type actualType, Type expectedType)
{
return builtInTypeRegistry.isTypeOnlyCoercion(actualType, expectedType);
}

@Override
public Optional<Type> coerceTypeBase(Type sourceType, String resultTypeBase)
{
return builtInTypeRegistry.coerceTypeBase(sourceType, resultTypeBase);
}

@Override
public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
{
Optional<FunctionNamespaceManager<?>> functionNamespaceManager = getServingFunctionNamespaceManager(functionHandle.getFunctionNamespace());
checkArgument(functionNamespaceManager.isPresent(), "Cannot find function namespace for '%s'", functionHandle.getFunctionNamespace());
return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
}

public ScalarFunctionImplementation getScalarFunctionImplementation(FunctionHandle functionHandle)
{
Optional<FunctionNamespaceManager<?>> functionNamespaceManager = getServingFunctionNamespaceManager(functionHandle.getFunctionNamespace());
Expand Down

0 comments on commit cd44d24

Please sign in to comment.