Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public final class StandardTypes
public static final String VARCHAR_ENUM = "VarcharEnum";
public static final String DISTINCT_TYPE = "DistinctType";
public static final String UUID = "uuid";
public static final String UNKNOWN = "unknown";

private StandardTypes() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package com.facebook.presto.common.type;

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

public interface TypeManager
Expand All @@ -29,19 +28,4 @@ public interface TypeManager
Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters);

boolean canCoerce(Type actualType, Type expectedType);

default Type instantiateParametricType(TypeSignature typeSignature)
{
throw new UnsupportedOperationException();
}

List<Type> getTypes();

/**
* Gets all registered parametric types.
*/
default Collection<ParametricType> getParametricTypes()
{
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public boolean canCoerce(Type actualType, Type expectedType)
throw new UnsupportedOperationException();
}

@Override
public List<Type> getTypes()
private List<Type> getTypes()
{
return ImmutableList.of(BOOLEAN, INTEGER, BIGINT, DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, ID, HYPER_LOG_LOG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ public boolean canCoerce(Type actualType, Type expectedType)
throw new UnsupportedOperationException();
}

@Override
public List<Type> getTypes()
private List<Type> getTypes()
{
return ImmutableList.of(BOOLEAN, INTEGER, BIGINT, DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, HYPER_LOG_LOG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@ public boolean canCoerce(Type actualType, Type expectedType)
throw new UnsupportedOperationException();
}

@Override
public List<Type> getTypes()
private List<Type> getTypes()
{
return ImmutableList.of(BooleanType.BOOLEAN, INTEGER, BIGINT, DoubleType.DOUBLE, VARCHAR, VARBINARY, TIMESTAMP, DATE, HYPER_LOG_LOG);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@

@ThreadSafe
public class BuiltInTypeAndFunctionNamespaceManager
implements FunctionNamespaceManager<SqlFunction>, TypeManager
implements FunctionNamespaceManager<SqlFunction>
{
public static final CatalogSchemaName JAVA_BUILTIN_NAMESPACE = new CatalogSchemaName("presto", "default");
public static final String ID = "builtin";
Expand Down Expand Up @@ -1262,34 +1262,21 @@ public ScalarFunctionImplementation getScalarFunctionImplementation(Signature si
}
}

@Override
public Type getType(TypeSignature typeSignature)
public Optional<Type> getType(TypeSignature typeSignature)
{
Type type = types.get(typeSignature);
if (type != null) {
return type;
return Optional.of(type);
}
try {
return parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature));
return Optional.ofNullable(parametricTypeCache.getUnchecked(new ExactTypeSignature(typeSignature)));
}
catch (UncheckedExecutionException e) {
throwIfUnchecked(e.getCause());
throw new RuntimeException(e.getCause());
}
}

@Override
public Type getParameterizedType(String baseTypeName, List<TypeSignatureParameter> typeParameters)
{
throw new UnsupportedOperationException();
}

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

public List<Type> getTypes()
{
return ImmutableList.copyOf(types.values());
Expand All @@ -1309,22 +1296,14 @@ public void addParametricType(ParametricType parametricType)
parametricTypes.putIfAbsent(name, parametricType);
}

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

private Type instantiateParametricType(ExactTypeSignature exactTypeSignature)
{
return instantiateParametricType(exactTypeSignature.getTypeSignature(), functionAndTypeManager, parametricTypes);
}

public Type instantiateParametricType(
TypeSignature signature,
FunctionAndTypeManager functionAndTypeManager,
Map<String, ParametricType> parametricTypes)
private Type instantiateParametricType(ExactTypeSignature exactSignature)
{
TypeSignature signature = exactSignature.getTypeSignature();
List<TypeParameter> parameters = new ArrayList<>();

for (TypeSignatureParameter parameter : signature.getParameters()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@
import com.facebook.presto.spi.function.SqlFunctionId;
import com.facebook.presto.spi.function.SqlFunctionSupplier;
import com.facebook.presto.spi.function.SqlInvokedFunction;
import com.facebook.presto.spi.type.TypeManagerContext;
import com.facebook.presto.spi.type.TypeManagerFactory;
import com.facebook.presto.sql.analyzer.FeaturesConfig;
import com.facebook.presto.sql.analyzer.FunctionAndTypeResolver;
import com.facebook.presto.sql.analyzer.FunctionsConfig;
Expand All @@ -63,7 +61,6 @@
import com.facebook.presto.transaction.TransactionManager;
import com.facebook.presto.type.TypeCoercer;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Supplier;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
Expand All @@ -85,7 +82,6 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;

import static com.facebook.presto.SystemSessionProperties.isExperimentalFunctionsEnabled;
Expand All @@ -111,7 +107,6 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.collect.ImmutableMap.toImmutableMap;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
import static java.lang.String.format;
import static java.util.Collections.emptyList;
Expand All @@ -133,18 +128,14 @@ public class FunctionAndTypeManager
private final BuiltInTypeAndFunctionNamespaceManager builtInTypeAndFunctionNamespaceManager;
private final FunctionInvokerProvider functionInvokerProvider;
private final Map<String, FunctionNamespaceManagerFactory> functionNamespaceManagerFactories = new ConcurrentHashMap<>();
private final Map<String, TypeManagerFactory> typeManagerFactories = new ConcurrentHashMap<>();
private final HandleResolver handleResolver;
private final Map<String, FunctionNamespaceManager<? extends SqlFunction>> functionNamespaceManagers = new ConcurrentHashMap<>();
private final Map<String, TypeManager> typeManagers = new ConcurrentHashMap<>();
private final FunctionSignatureMatcher functionSignatureMatcher;
private final TypeCoercer typeCoercer;
private final LoadingCache<FunctionResolutionCacheKey, FunctionHandle> functionCache;
private final CacheStatsMBean cacheStatsMBean;
private final boolean nativeExecution;
private final CatalogSchemaName defaultNamespace;
private final AtomicReference<TypeManager> servingTypeManager;
private final AtomicReference<Supplier<Map<String, ParametricType>>> servingTypeManagerParametricTypesSupplier;

@Inject
public FunctionAndTypeManager(
Expand All @@ -160,7 +151,6 @@ public FunctionAndTypeManager(
this.builtInTypeAndFunctionNamespaceManager = new BuiltInTypeAndFunctionNamespaceManager(blockEncodingSerde, functionsConfig, types, this);
this.functionNamespaceManagers.put(JAVA_BUILTIN_NAMESPACE.getCatalogName(), builtInTypeAndFunctionNamespaceManager);
this.functionInvokerProvider = new FunctionInvokerProvider(this);
this.typeManagers.put(JAVA_BUILTIN_NAMESPACE.getCatalogName(), builtInTypeAndFunctionNamespaceManager);
this.handleResolver = requireNonNull(handleResolver, "handleResolver is null");
// TODO: Provide a more encapsulated way for TransactionManager to register FunctionNamespaceManager
transactionManager.registerFunctionNamespaceManager(JAVA_BUILTIN_NAMESPACE.getCatalogName(), builtInTypeAndFunctionNamespaceManager);
Expand All @@ -174,8 +164,6 @@ public FunctionAndTypeManager(
this.typeCoercer = new TypeCoercer(functionsConfig, this);
this.nativeExecution = featuresConfig.isNativeExecutionEnabled();
this.defaultNamespace = configureDefaultNamespace(functionsConfig.getDefaultNamespacePrefix());
this.servingTypeManager = new AtomicReference<>(builtInTypeAndFunctionNamespaceManager);
this.servingTypeManagerParametricTypesSupplier = new AtomicReference<>(this::getServingTypeManagerParametricTypes);
}

public static FunctionAndTypeManager createTestFunctionAndTypeManager()
Expand Down Expand Up @@ -246,24 +234,6 @@ public SqlFunctionSupplier getSpecializedFunctionKey(Signature signature)
return FunctionAndTypeManager.this.getSpecializedFunctionKey(signature);
}

@Override
public Type instantiateParametricType(TypeSignature typeSignature)
{
return FunctionAndTypeManager.this.instantiateParametricType(typeSignature);
}

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

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

@Override
public Collection<SqlFunction> listBuiltInFunctions()
{
Expand Down Expand Up @@ -349,15 +319,6 @@ public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle)
return functionNamespaceManager.get().getFunctionMetadata(functionHandle);
}

@Override
public Type instantiateParametricType(TypeSignature typeSignature)
{
return builtInTypeAndFunctionNamespaceManager.instantiateParametricType(
typeSignature,
this,
servingTypeManagerParametricTypesSupplier.get().get());
}

@Override
public Type getType(TypeSignature signature)
{
Expand All @@ -366,12 +327,12 @@ public Type getType(TypeSignature signature)
if (signature.isDistinctType()) {
return getDistinctType(signature.getParameters().get(0).getDistinctTypeInfo());
}
Type type = servingTypeManager.get().getType(signature.getStandardTypeSignature());
if (type != null) {
Optional<Type> type = builtInTypeAndFunctionNamespaceManager.getType(signature.getStandardTypeSignature());
if (type.isPresent()) {
if (signature.getTypeSignatureBase().hasTypeName()) {
return new TypeWithName(signature.getTypeSignatureBase().getTypeName(), type);
return new TypeWithName(signature.getTypeSignatureBase().getTypeName(), type.get());
}
return type;
return type.get();
}
}

Expand Down Expand Up @@ -403,35 +364,6 @@ public void addFunctionNamespaceFactory(FunctionNamespaceManagerFactory factory)
handleResolver.addFunctionNamespace(factory.getName(), factory.getHandleResolver());
}

public void loadTypeManager(String typeManagerName)
{
requireNonNull(typeManagerName, "typeManagerName is null");
TypeManagerFactory factory = typeManagerFactories.get(typeManagerName);
checkState(factory != null, "No factory for type manager %s", typeManagerName);
TypeManager typeManager = factory.create(new TypeManagerContext(this));

if (typeManagers.putIfAbsent(typeManagerName, typeManager) != null) {
throw new IllegalArgumentException(format("Type manager [%s] is already registered", typeManager));
}
servingTypeManager.compareAndSet(servingTypeManager.get(), typeManager);
// Reset the parametric types cache
servingTypeManagerParametricTypesSupplier.set(this::getServingTypeManagerParametricTypes);
}

public void loadTypeManagers()
{
for (String typeManagerName : typeManagerFactories.keySet()) {
loadTypeManager(typeManagerName);
}
}

public void addTypeManagerFactory(TypeManagerFactory factory)
{
if (typeManagerFactories.putIfAbsent(factory.getName(), factory) != null) {
throw new IllegalArgumentException(format("Type manager '%s' is already registered", factory.getName()));
}
}

public void registerBuiltInFunctions(List<? extends SqlFunction> functions)
{
builtInTypeAndFunctionNamespaceManager.registerBuiltInFunctions(functions);
Expand Down Expand Up @@ -579,7 +511,7 @@ public List<Type> getTypes()

public Collection<ParametricType> getParametricTypes()
{
return builtInTypeAndFunctionNamespaceManager.getParametricTypes();
return ImmutableList.copyOf(builtInTypeAndFunctionNamespaceManager.getParametricTypes());
}

public Optional<Type> getCommonSuperType(Type firstType, Type secondType)
Expand Down Expand Up @@ -903,12 +835,6 @@ public CatalogSchemaName configureDefaultNamespace(String defaultNamespacePrefix
return new CatalogSchemaName(catalogSchemaNameString[0], catalogSchemaNameString[1]);
}

private Map<String, ParametricType> getServingTypeManagerParametricTypes()
{
return servingTypeManager.get().getParametricTypes().stream()
.collect(toImmutableMap(ParametricType::getName, parametricType -> parametricType));
}

private static class FunctionResolutionCacheKey
{
private final QualifiedObjectName functionName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import com.facebook.presto.spi.tracing.TracerProvider;
import com.facebook.presto.spi.ttl.ClusterTtlProviderFactory;
import com.facebook.presto.spi.ttl.NodeTtlFetcherFactory;
import com.facebook.presto.spi.type.TypeManagerFactory;
import com.facebook.presto.sql.analyzer.AnalyzerProviderManager;
import com.facebook.presto.sql.analyzer.QueryPreparerProviderManager;
import com.facebook.presto.sql.expressions.ExpressionOptimizerManager;
Expand Down Expand Up @@ -403,11 +402,6 @@ public void installCoordinatorPlugin(CoordinatorPlugin plugin)
log.info("Registering expression optimizer factory %s", expressionOptimizerFactory.getName());
expressionOptimizerManager.addExpressionOptimizerFactory(expressionOptimizerFactory);
}

for (TypeManagerFactory typeManagerFactory : plugin.getTypeManagerFactories()) {
log.info("Registering type manager factory %s", typeManagerFactory.getName());
metadata.getFunctionAndTypeManager().addTypeManagerFactory(typeManagerFactory);
}
}

private URLClassLoader buildClassLoader(String plugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ default void loadSessionPropertyProvider(String sessionPropertyProviderName)

Lock getExclusiveLock();

default void loadTypeManager(String typeManagerName)
{
throw new UnsupportedOperationException();
}

class MaterializedResultWithPlan
{
private final MaterializedResult materializedResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.facebook.presto.metadata.Catalog;
import com.facebook.presto.metadata.CatalogManager;
import com.facebook.presto.metadata.DiscoveryNodeManager;
import com.facebook.presto.metadata.FunctionAndTypeManager;
import com.facebook.presto.metadata.InternalNodeManager;
import com.facebook.presto.metadata.SessionPropertyManager;
import com.facebook.presto.metadata.StaticCatalogStore;
Expand Down Expand Up @@ -191,7 +190,6 @@ public void run()
injector.getInstance(NodeStatusNotificationManager.class).loadNodeStatusNotificationProvider();
injector.getInstance(GracefulShutdownHandler.class).loadNodeStatusNotification();
injector.getInstance(SessionPropertyManager.class).loadSessionPropertyProviders();
injector.getInstance(FunctionAndTypeManager.class).loadTypeManagers();
PlanCheckerProviderManager planCheckerProviderManager = injector.getInstance(PlanCheckerProviderManager.class);
InternalNodeManager nodeManager = injector.getInstance(DiscoveryNodeManager.class);
NodeInfo nodeInfo = injector.getInstance(NodeInfo.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
import com.facebook.presto.sidecar.functionNamespace.NativeFunctionNamespaceManagerFactory;
import com.facebook.presto.sidecar.nativechecker.NativePlanCheckerProviderFactory;
import com.facebook.presto.sidecar.sessionpropertyproviders.NativeSystemSessionPropertyProviderFactory;
import com.facebook.presto.sidecar.typemanager.NativeTypeManagerFactory;
import com.facebook.presto.spi.CoordinatorPlugin;
import com.facebook.presto.spi.function.FunctionNamespaceManagerFactory;
import com.facebook.presto.spi.plan.PlanCheckerProviderFactory;
import com.facebook.presto.spi.session.WorkerSessionPropertyProviderFactory;
import com.facebook.presto.spi.type.TypeManagerFactory;
import com.google.common.collect.ImmutableList;

public class NativeSidecarPlugin
Expand All @@ -33,12 +31,6 @@ public Iterable<WorkerSessionPropertyProviderFactory> getWorkerSessionPropertyPr
return ImmutableList.of(new NativeSystemSessionPropertyProviderFactory());
}

@Override
public Iterable<TypeManagerFactory> getTypeManagerFactories()
{
return ImmutableList.of(new NativeTypeManagerFactory());
}

@Override
public Iterable<PlanCheckerProviderFactory> getPlanCheckerProviderFactories()
{
Expand Down
Loading
Loading