Skip to content

Back out "[presto][diff_train] Add a native type manager" #24961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
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
@@ -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() {}

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

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

public interface TypeManager
@@ -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
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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";
@@ -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());
@@ -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()) {
Original file line number Diff line number Diff line change
@@ -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;
@@ -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;
@@ -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;
@@ -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;
@@ -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(
@@ -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);
@@ -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()
@@ -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()
{
@@ -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)
{
@@ -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();
}
}

@@ -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);
@@ -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)
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
Original file line number Diff line number Diff line change
@@ -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
@@ -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()
{

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@

import com.facebook.presto.sidecar.functionNamespace.NativeFunctionNamespaceManagerFactory;
import com.facebook.presto.sidecar.sessionpropertyproviders.NativeSystemSessionPropertyProviderFactory;
import com.facebook.presto.sidecar.typemanager.NativeTypeManagerFactory;
import com.facebook.presto.testing.QueryRunner;
import com.google.common.collect.ImmutableMap;

@@ -33,6 +32,5 @@ public static void setupNativeSidecarPlugin(QueryRunner queryRunner)
ImmutableMap.of(
"supported-function-languages", "CPP",
"function-implementation-type", "CPP"));
queryRunner.loadTypeManager(NativeTypeManagerFactory.NAME);
}
}
Original file line number Diff line number Diff line change
@@ -11,8 +11,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.presto.sidecar.sessionpropertyproviders;
package com.facebook.presto.sidecar;

import com.facebook.presto.sidecar.sessionpropertyproviders.NativeSystemSessionPropertyProviderConfig;
import com.google.common.collect.ImmutableMap;
import io.airlift.units.Duration;
import org.testng.annotations.Test;
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
import com.facebook.presto.spi.plan.PlanCheckerProviderFactory;
import com.facebook.presto.spi.session.WorkerSessionPropertyProviderFactory;
import com.facebook.presto.spi.sql.planner.ExpressionOptimizerFactory;
import com.facebook.presto.spi.type.TypeManagerFactory;

import static java.util.Collections.emptyList;

@@ -47,9 +46,4 @@ default Iterable<ExpressionOptimizerFactory> getExpressionOptimizerFactories()
{
return emptyList();
}

default Iterable<TypeManagerFactory> getTypeManagerFactories()
{
return emptyList();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -994,14 +994,6 @@ public void loadSessionPropertyProvider(String sessionPropertyProviderName)
}
}

@Override
public void loadTypeManager(String typeManagerName)
{
for (TestingPrestoServer server : servers) {
server.getMetadata().getFunctionAndTypeManager().loadTypeManager(typeManagerName);
}
}

private static void closeUnchecked(AutoCloseable closeable)
{
try {