forked from linkedin/transport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport-udfs-trino.patch
76 lines (74 loc) · 4.39 KB
/
transport-udfs-trino.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
diff --git a/core/trino-main/src/main/java/io/trino/server/PluginManager.java b/core/trino-main/src/main/java/io/trino/server/PluginManager.java
index 76cc04ca9d..483e609c86 100644
--- a/core/trino-main/src/main/java/io/trino/server/PluginManager.java
+++ b/core/trino-main/src/main/java/io/trino/server/PluginManager.java
@@ -23,6 +23,7 @@ import io.trino.connector.ConnectorManager;
import io.trino.eventlistener.EventListenerManager;
import io.trino.execution.resourcegroups.ResourceGroupManager;
import io.trino.metadata.MetadataManager;
+import io.trino.metadata.SqlScalarFunction;
import io.trino.security.AccessControlManager;
import io.trino.security.GroupProviderManager;
import io.trino.server.security.CertificateAuthenticatorManager;
@@ -55,6 +56,7 @@ import java.util.ServiceLoader;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Supplier;
+import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkState;
import static io.trino.metadata.FunctionExtractor.extractFunctions;
@@ -65,8 +67,27 @@ import static java.util.Objects.requireNonNull;
@ThreadSafe
public class PluginManager
{
+ // As part of enabling SqlScalarFunctions to be loaded as Plugins, we introduce two changes to this
+ // class: 1) adding more packages to the SPI_PACKAGES list so that SqlScalarFunction class and its
+ // dependencies are visible to the PluginClassLoader (which is responsible of resolving Plugin dependencies)
+ // 2) registering SqlScalarFunction classes found in the plugin directory jars (or expressed as pom files)
+ // as it is the case with vanilla plugins.
+ // JIRA: https://jira01.corp.linkedin.com:8443/browse/LIHADOOP-34269
private static final ImmutableList<String> SPI_PACKAGES = ImmutableList.<String>builder()
+ // io.trino.metadata is required for SqlScalarFunction, Metadata, MetadataManager, FunctionBinding,
+ // FunctionDependencies, TypeVariableConstraint, FunctionArgumentDefinition, FunctionKind, FunctionMetadata,
+ // Signature and SignatureBinder classes
+ .add("io.trino.metadata.")
+ // io.trino.operator. is required for AbstractTestFunctions, ScalarFunctionImplementation
+ // & ChoicesScalarFunctionImplementation
+ .add("io.trino.operator.")
+ // io.trino.sql.analyzer.TypeSignatureTranslator. is required for parseTypeSignature
+ .add("io.trino.sql.analyzer.TypeSignatureTranslator.")
.add("io.trino.spi.")
+ // io.trino.type is required for UnknownType
+ .add("io.trino.type.")
+ // io.trino.util is required for Reflection
+ .add("io.trino.util.")
.add("com.fasterxml.jackson.annotation.")
.add("io.airlift.slice.")
.add("org.openjdk.jol.")
@@ -163,11 +184,26 @@ public class PluginManager
{
ServiceLoader<Plugin> serviceLoader = ServiceLoader.load(Plugin.class, pluginClassLoader);
List<Plugin> plugins = ImmutableList.copyOf(serviceLoader);
- checkState(!plugins.isEmpty(), "No service providers of type %s", Plugin.class.getName());
+
+ ServiceLoader<SqlScalarFunction> sqlScalarFunctionsServiceLoader = ServiceLoader.load(SqlScalarFunction.class,
+ pluginClassLoader);
+ List<SqlScalarFunction> sqlScalarFunctions = ImmutableList.copyOf(sqlScalarFunctionsServiceLoader);
+
+ checkState(!plugins.isEmpty() || !sqlScalarFunctions.isEmpty(), "No service providers of type %s or %s", Plugin.class.getName(), SqlScalarFunction.class.getName());
+
for (Plugin plugin : plugins) {
log.info("Installing %s", plugin.getClass().getName());
installPlugin(plugin, pluginClassLoader::duplicate);
}
+
+ for (SqlScalarFunction sqlScalarFunction : sqlScalarFunctions) {
+ log.info("Registering function %s(%s)",
+ sqlScalarFunction.getFunctionMetadata().getSignature().getName(),
+ sqlScalarFunction.getFunctionMetadata().getSignature().getArgumentTypes().stream()
+ .map(e -> e.toString())
+ .collect(Collectors.joining(", ")));
+ metadataManager.addFunctions(ImmutableList.of(sqlScalarFunction));
+ }
}
public void installPlugin(Plugin plugin, Supplier<ClassLoader> duplicatePluginClassLoaderFactory)