Skip to content

Commit

Permalink
Move system functions to SystemFunctionBundle
Browse files Browse the repository at this point in the history
  • Loading branch information
dain committed Mar 13, 2022
1 parent 65559c5 commit fd76219
Show file tree
Hide file tree
Showing 8 changed files with 754 additions and 711 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ public String toString()
public static FunctionManager createTestingFunctionManager()
{
TypeOperators typeOperators = new TypeOperators();
GlobalFunctionCatalog functionCatalog = new GlobalFunctionCatalog(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), UNKNOWN);
GlobalFunctionCatalog functionCatalog = new GlobalFunctionCatalog();
functionCatalog.addFunctions(SystemFunctionBundle.create(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), UNKNOWN));
functionCatalog.addFunctions(new InternalFunctionBundle(new LiteralFunction(new InternalBlockEncodingSerde(new BlockEncodingManager(), TESTING_TYPE_MANAGER))));
return new FunctionManager(functionCatalog);
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2522,8 +2522,9 @@ public MetadataManager build()

GlobalFunctionCatalog globalFunctionCatalog = this.globalFunctionCatalog;
if (globalFunctionCatalog == null) {
globalFunctionCatalog = new GlobalFunctionCatalog();
TypeOperators typeOperators = new TypeOperators();
globalFunctionCatalog = new GlobalFunctionCatalog(featuresConfig, typeOperators, new BlockTypeOperators(typeOperators), UNKNOWN);
globalFunctionCatalog.addFunctions(SystemFunctionBundle.create(featuresConfig, typeOperators, new BlockTypeOperators(typeOperators), UNKNOWN));
globalFunctionCatalog.addFunctions(new InternalFunctionBundle(new LiteralFunction(new InternalBlockEncodingSerde(new BlockEncodingManager(), typeManager))));
}

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.google.inject.Binder;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.multibindings.ProvidesIntoSet;
import io.airlift.concurrent.BoundedExecutor;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.airlift.http.server.HttpServerConfig;
Expand Down Expand Up @@ -67,6 +68,7 @@
import io.trino.metadata.DisabledSystemSecurityMetadata;
import io.trino.metadata.DiscoveryNodeManager;
import io.trino.metadata.ForNodeManager;
import io.trino.metadata.FunctionBundle;
import io.trino.metadata.FunctionManager;
import io.trino.metadata.GlobalFunctionCatalog;
import io.trino.metadata.HandleJsonModule;
Expand All @@ -82,6 +84,7 @@
import io.trino.metadata.SessionPropertyManager;
import io.trino.metadata.StaticCatalogStore;
import io.trino.metadata.StaticCatalogStoreConfig;
import io.trino.metadata.SystemFunctionBundle;
import io.trino.metadata.SystemSecurityMetadata;
import io.trino.metadata.TableProceduresPropertyManager;
import io.trino.metadata.TableProceduresRegistry;
Expand Down Expand Up @@ -158,6 +161,7 @@
import javax.inject.Singleton;

import java.util.List;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -391,8 +395,8 @@ protected void setup(Binder binder)

// function
binder.bind(FunctionManager.class).in(Scopes.SINGLETON);
// literal function must be registered lazily to break circular dependency
binder.bind(LiteralFunctionRegistrar.class).asEagerSingleton();
newSetBinder(binder, FunctionBundle.class);
binder.bind(RegisterFunctionBundles.class).asEagerSingleton();

// type
binder.bind(TypeAnalyzer.class).in(Scopes.SINGLETON);
Expand Down Expand Up @@ -494,16 +498,32 @@ protected void setup(Binder binder)
binder.bind(ExecutorCleanup.class).in(Scopes.SINGLETON);
}

private static class LiteralFunctionRegistrar
private static class RegisterFunctionBundles
{
@Inject
public LiteralFunctionRegistrar(BlockEncodingSerde blockEncodingSerde, GlobalFunctionCatalog globalFunctionCatalog)
public RegisterFunctionBundles(GlobalFunctionCatalog globalFunctionCatalog, Set<FunctionBundle> functionBundles)
{
LiteralFunction literalFunction = new LiteralFunction(blockEncodingSerde);
globalFunctionCatalog.addFunctions(new InternalFunctionBundle(ImmutableList.of(literalFunction)));
for (FunctionBundle functionBundle : functionBundles) {
globalFunctionCatalog.addFunctions(functionBundle);
}
}
}

@ProvidesIntoSet
@Singleton
public static FunctionBundle systemFunctionBundle(FeaturesConfig featuresConfig, TypeOperators typeOperators, BlockTypeOperators blockTypeOperators, NodeVersion nodeVersion)
{
return SystemFunctionBundle.create(featuresConfig, typeOperators, blockTypeOperators, nodeVersion);
}

@ProvidesIntoSet
@Singleton
// literal function must be registered lazily to break circular dependency
public static FunctionBundle literalFunctionBundle(BlockEncodingSerde blockEncodingSerde)
{
return new InternalFunctionBundle(new LiteralFunction(blockEncodingSerde));
}

@Provides
@Singleton
public static TypeOperators createTypeOperators(TypeOperatorsCache typeOperatorsCache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import io.trino.metadata.SchemaPropertyManager;
import io.trino.metadata.SessionPropertyManager;
import io.trino.metadata.Split;
import io.trino.metadata.SystemFunctionBundle;
import io.trino.metadata.TableHandle;
import io.trino.metadata.TableProceduresPropertyManager;
import io.trino.metadata.TableProceduresRegistry;
Expand Down Expand Up @@ -347,8 +348,9 @@ private LocalQueryRunner(
TypeManager typeManager = new InternalTypeManager(typeRegistry);
InternalBlockEncodingSerde blockEncodingSerde = new InternalBlockEncodingSerde(blockEncodingManager, typeManager);

this.globalFunctionCatalog = new GlobalFunctionCatalog(featuresConfig, typeOperators, blockTypeOperators, nodeManager.getCurrentNode().getNodeVersion());
this.globalFunctionCatalog = new GlobalFunctionCatalog();
globalFunctionCatalog.addFunctions(new InternalFunctionBundle(new LiteralFunction(blockEncodingSerde)));
globalFunctionCatalog.addFunctions(SystemFunctionBundle.create(featuresConfig, typeOperators, blockTypeOperators, nodeManager.getCurrentNode().getNodeVersion()));
this.functionManager = new FunctionManager(globalFunctionCatalog);
MetadataManager metadata = new MetadataManager(
featuresConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public void testDuplicateFunctions()
FunctionBundle functionBundle = extractFunctions(CustomAdd.class);

TypeOperators typeOperators = new TypeOperators();
GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), NodeVersion.UNKNOWN);
GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog();
globalFunctionCatalog.addFunctions(SystemFunctionBundle.create(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), NodeVersion.UNKNOWN));
globalFunctionCatalog.addFunctions(functionBundle);
assertThatThrownBy(() -> globalFunctionCatalog.addFunctions(functionBundle))
.isInstanceOf(IllegalArgumentException.class)
Expand All @@ -112,7 +113,8 @@ public void testConflictingScalarAggregation()
FunctionBundle functions = extractFunctions(ScalarSum.class);

TypeOperators typeOperators = new TypeOperators();
GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), NodeVersion.UNKNOWN);
GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog();
globalFunctionCatalog.addFunctions(SystemFunctionBundle.create(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), NodeVersion.UNKNOWN));
assertThatThrownBy(() -> globalFunctionCatalog.addFunctions(functions))
.isInstanceOf(IllegalStateException.class)
.hasMessage("'sum' is both an aggregation and a scalar function");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.trino.metadata.Metadata;
import io.trino.metadata.MetadataManager;
import io.trino.metadata.MetadataManager.TestMetadataManagerBuilder;
import io.trino.metadata.SystemFunctionBundle;
import io.trino.metadata.TypeRegistry;
import io.trino.spi.block.BlockEncodingSerde;
import io.trino.spi.type.ParametricType;
Expand Down Expand Up @@ -107,7 +108,8 @@ public PlannerContext build()
types.forEach(typeRegistry::addType);
parametricTypes.forEach(typeRegistry::addParametricType);

GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog(featuresConfig, typeOperators, new BlockTypeOperators(typeOperators), UNKNOWN);
GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog();
globalFunctionCatalog.addFunctions(SystemFunctionBundle.create(featuresConfig, typeOperators, new BlockTypeOperators(typeOperators), UNKNOWN));
functionBundles.forEach(globalFunctionCatalog::addFunctions);

BlockEncodingSerde blockEncodingSerde = new InternalBlockEncodingSerde(new BlockEncodingManager(), typeManager);
Expand Down

0 comments on commit fd76219

Please sign in to comment.