Skip to content

Commit ebbfdac

Browse files
pdabre12abevk2023Joe-Abrahamdeepthydavis
authored andcommitted
Integrate session property SPI with Presto engine
Co-authored-by: Abe Varghese Kodiyan <abe.varghese@ibm.com> Co-authored-by: Joe Abraham <joe.abraham@ibm.com> Co-authored-by: Deepthy Davis <deepthy.davis@ibm.com>
1 parent 524fbea commit ebbfdac

File tree

18 files changed

+650
-3
lines changed

18 files changed

+650
-3
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
<module>presto-singlestore</module>
202202
<module>presto-hana</module>
203203
<module>presto-openapi</module>
204+
<module>presto-native-sidecar-plugin</module>
204205
</modules>
205206

206207
<dependencyManagement>
@@ -457,6 +458,12 @@
457458
<version>${project.version}</version>
458459
</dependency>
459460

461+
<dependency>
462+
<groupId>com.facebook.presto</groupId>
463+
<artifactId>presto-session-property-providers</artifactId>
464+
<version>${project.version}</version>
465+
</dependency>
466+
460467
<dependency>
461468
<groupId>com.facebook.presto</groupId>
462469
<artifactId>presto-bigquery</artifactId>

presto-main/src/main/java/com/facebook/presto/metadata/SessionPropertyManager.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.facebook.presto.common.type.DoubleType;
2525
import com.facebook.presto.common.type.IntegerType;
2626
import com.facebook.presto.common.type.MapType;
27+
import com.facebook.presto.common.type.TinyintType;
2728
import com.facebook.presto.common.type.Type;
2829
import com.facebook.presto.common.type.TypeManager;
2930
import com.facebook.presto.common.type.VarcharType;
@@ -137,11 +138,11 @@ public static SessionPropertyManager createTestingSessionPropertyManager(
137138
Optional.empty());
138139
}
139140

140-
public void loadSessionPropertyProvider(String sessionPropertyProviderName)
141+
public void loadSessionPropertyProvider(String sessionPropertyProviderName, Optional<TypeManager> typeManager, Optional<NodeManager> nodeManager)
141142
{
142143
WorkerSessionPropertyProviderFactory factory = workerSessionPropertyProviderFactories.get(sessionPropertyProviderName);
143144
checkState(factory != null, "No factory for session property provider : " + sessionPropertyProviderName);
144-
WorkerSessionPropertyProvider sessionPropertyProvider = factory.create(new SessionPropertyContext(functionAndTypeManager, nodeManager));
145+
WorkerSessionPropertyProvider sessionPropertyProvider = factory.create(new SessionPropertyContext(typeManager, nodeManager));
145146
if (workerSessionPropertyProviders.putIfAbsent(sessionPropertyProviderName, sessionPropertyProvider) != null) {
146147
throw new IllegalArgumentException("System session property provider is already registered for property provider : " + sessionPropertyProviderName);
147148
}
@@ -150,7 +151,14 @@ public void loadSessionPropertyProvider(String sessionPropertyProviderName)
150151
public void loadSessionPropertyProviders()
151152
{
152153
for (String sessionPropertyProviderName : workerSessionPropertyProviderFactories.keySet()) {
153-
loadSessionPropertyProvider(sessionPropertyProviderName);
154+
loadSessionPropertyProvider(sessionPropertyProviderName, functionAndTypeManager, nodeManager);
155+
}
156+
}
157+
158+
public void addSessionPropertyProviderFactory(WorkerSessionPropertyProviderFactory factory)
159+
{
160+
if (workerSessionPropertyProviderFactories.putIfAbsent(factory.getName(), factory) != null) {
161+
throw new IllegalArgumentException(format("System Session property provider factory" + factory.getName() + "is already registered"));
154162
}
155163
}
156164

@@ -367,6 +375,9 @@ public static String serializeSessionProperty(Type type, Object value)
367375
if (VarcharType.VARCHAR.equals(type)) {
368376
return value.toString();
369377
}
378+
if (TinyintType.TINYINT.equals(type)) {
379+
return value.toString();
380+
}
370381
if (type instanceof ArrayType || type instanceof MapType) {
371382
return getJsonCodecForType(type).toJson(value);
372383
}
@@ -393,6 +404,9 @@ private static Object deserializeSessionProperty(Type type, String value)
393404
if (DoubleType.DOUBLE.equals(type)) {
394405
return Double.valueOf(value);
395406
}
407+
if (TinyintType.TINYINT.equals(type)) {
408+
return Byte.valueOf(value);
409+
}
396410
if (type instanceof ArrayType || type instanceof MapType) {
397411
return getJsonCodecForType(type).fromJson(value);
398412
}
@@ -416,6 +430,9 @@ private static <T> JsonCodec<T> getJsonCodecForType(Type type)
416430
if (DoubleType.DOUBLE.equals(type)) {
417431
return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Double.class);
418432
}
433+
if (TinyintType.TINYINT.equals(type)) {
434+
return (JsonCodec<T>) JSON_CODEC_FACTORY.jsonCodec(Byte.class);
435+
}
419436
if (type instanceof ArrayType) {
420437
Type elementType = ((ArrayType) type).getElementType();
421438
return (JsonCodec<T>) JSON_CODEC_FACTORY.listJsonCodec(getJsonCodecForType(elementType));
@@ -445,6 +462,9 @@ private static Class<?> getMapKeyType(Type type)
445462
if (DoubleType.DOUBLE.equals(type)) {
446463
return Double.class;
447464
}
465+
if (TinyintType.TINYINT.equals(type)) {
466+
return Byte.class;
467+
}
448468
throw new PrestoException(INVALID_SESSION_PROPERTY, format("Session property map key type %s is not supported", type));
449469
}
450470

presto-main/src/main/java/com/facebook/presto/server/PluginManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.facebook.presto.spi.security.PasswordAuthenticatorFactory;
4343
import com.facebook.presto.spi.security.SystemAccessControlFactory;
4444
import com.facebook.presto.spi.session.SessionPropertyConfigurationManagerFactory;
45+
import com.facebook.presto.spi.session.WorkerSessionPropertyProviderFactory;
4546
import com.facebook.presto.spi.statistics.HistoryBasedPlanStatisticsProvider;
4647
import com.facebook.presto.spi.storage.TempStorageFactory;
4748
import com.facebook.presto.spi.tracing.TracerProvider;
@@ -366,6 +367,11 @@ public void installCoordinatorPlugin(CoordinatorPlugin plugin)
366367
log.info("Registering function namespace manager %s", functionNamespaceManagerFactory.getName());
367368
metadata.getFunctionAndTypeManager().addFunctionNamespaceFactory(functionNamespaceManagerFactory);
368369
}
370+
371+
for (WorkerSessionPropertyProviderFactory providerFactory : plugin.getWorkerSessionPropertyProviderFactories()) {
372+
log.info("Registering system session property provider factory %s", providerFactory.getName());
373+
metadata.getSessionPropertyManager().addSessionPropertyProviderFactory(providerFactory);
374+
}
369375
}
370376

371377
private URLClassLoader buildClassLoader(String plugin)

presto-main/src/main/java/com/facebook/presto/server/testing/TestingPrestoServer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.facebook.presto.metadata.InternalNode;
5252
import com.facebook.presto.metadata.InternalNodeManager;
5353
import com.facebook.presto.metadata.Metadata;
54+
import com.facebook.presto.nodeManager.PluginNodeManager;
5455
import com.facebook.presto.resourcemanager.ResourceManagerClusterStateProvider;
5556
import com.facebook.presto.security.AccessControlManager;
5657
import com.facebook.presto.server.GracefulShutdownHandler;
@@ -61,6 +62,7 @@
6162
import com.facebook.presto.server.security.ServerSecurityModule;
6263
import com.facebook.presto.spi.ConnectorId;
6364
import com.facebook.presto.spi.CoordinatorPlugin;
65+
import com.facebook.presto.spi.NodeManager;
6466
import com.facebook.presto.spi.Plugin;
6567
import com.facebook.presto.spi.QueryId;
6668
import com.facebook.presto.spi.eventlistener.EventListener;
@@ -175,6 +177,7 @@ public class TestingPrestoServer
175177
private final ServerInfoResource serverInfoResource;
176178
private final ResourceManagerClusterStateProvider clusterStateProvider;
177179
private final PlanCheckerProviderManager planCheckerProviderManager;
180+
private final NodeManager pluginNodeManager;
178181

179182
public static class TestShutdownAction
180183
implements ShutdownAction
@@ -440,6 +443,7 @@ else if (catalogServer) {
440443
announcer = injector.getInstance(Announcer.class);
441444
requestBlocker = injector.getInstance(RequestBlocker.class);
442445
serverInfoResource = injector.getInstance(ServerInfoResource.class);
446+
pluginNodeManager = injector.getInstance(PluginNodeManager.class);
443447

444448
// Announce Thrift server address
445449
DriftServer driftServer = injector.getInstance(DriftServer.class);
@@ -510,6 +514,7 @@ public PluginManager getPluginManager()
510514
{
511515
return pluginManager;
512516
}
517+
513518
public void installPlugin(Plugin plugin)
514519
{
515520
pluginManager.installPlugin(plugin);
@@ -647,6 +652,11 @@ public InternalNodeManager getNodeManager()
647652
return nodeManager;
648653
}
649654

655+
public NodeManager getPluginNodeManager()
656+
{
657+
return pluginNodeManager;
658+
}
659+
650660
public NodePartitioningManager getNodePartitioningManager()
651661
{
652662
return nodePartitioningManager;

presto-main/src/main/java/com/facebook/presto/testing/QueryRunner.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ default void installCoordinatorPlugin(CoordinatorPlugin plugin)
9797

9898
void loadFunctionNamespaceManager(String functionNamespaceManagerName, String catalogName, Map<String, String> properties);
9999

100+
default void loadSessionPropertyProvider(String sessionPropertyProviderName)
101+
{
102+
throw new UnsupportedOperationException();
103+
}
104+
100105
Lock getExclusiveLock();
101106

102107
class MaterializedResultWithPlan

presto-native-sidecar-plugin/pom.xml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.facebook.presto</groupId>
7+
<artifactId>presto-root</artifactId>
8+
<version>0.290-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>presto-native-sidecar-plugin</artifactId>
12+
<description>Presto - Native Sidecar Plugin</description>
13+
<packaging>presto-plugin</packaging>
14+
15+
<properties>
16+
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>com.facebook.airlift</groupId>
22+
<artifactId>bootstrap</artifactId>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>com.facebook.airlift</groupId>
27+
<artifactId>log</artifactId>
28+
</dependency>
29+
30+
<dependency>
31+
<groupId>com.facebook.airlift</groupId>
32+
<artifactId>json</artifactId>
33+
</dependency>
34+
35+
<dependency>
36+
<groupId>com.google.guava</groupId>
37+
<artifactId>guava</artifactId>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.google.inject</groupId>
42+
<artifactId>guice</artifactId>
43+
</dependency>
44+
45+
<!-- Presto SPI -->
46+
<dependency>
47+
<groupId>com.facebook.presto</groupId>
48+
<artifactId>presto-spi</artifactId>
49+
<scope>provided</scope>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>com.facebook.presto</groupId>
54+
<artifactId>presto-common</artifactId>
55+
<scope>provided</scope>
56+
</dependency>
57+
58+
<dependency>
59+
<groupId>io.airlift</groupId>
60+
<artifactId>units</artifactId>
61+
<scope>provided</scope>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>com.fasterxml.jackson.core</groupId>
66+
<artifactId>jackson-annotations</artifactId>
67+
<scope>provided</scope>
68+
</dependency>
69+
70+
<dependency>
71+
<groupId>com.facebook.drift</groupId>
72+
<artifactId>drift-api</artifactId>
73+
<scope>provided</scope>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>io.airlift</groupId>
78+
<artifactId>slice</artifactId>
79+
<scope>provided</scope>
80+
</dependency>
81+
82+
<dependency>
83+
<groupId>org.openjdk.jol</groupId>
84+
<artifactId>jol-core</artifactId>
85+
<scope>provided</scope>
86+
</dependency>
87+
88+
<!-- for testing -->
89+
<dependency>
90+
<groupId>com.facebook.presto</groupId>
91+
<artifactId>presto-testng-services</artifactId>
92+
<scope>test</scope>
93+
</dependency>
94+
95+
<dependency>
96+
<groupId>org.testng</groupId>
97+
<artifactId>testng</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
101+
<dependency>
102+
<groupId>com.facebook.airlift</groupId>
103+
<artifactId>testing</artifactId>
104+
<scope>test</scope>
105+
</dependency>
106+
</dependencies>
107+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.sidecar;
15+
16+
import com.facebook.presto.sidecar.sessionpropertyproviders.NativeSystemSessionPropertyProviderFactory;
17+
import com.facebook.presto.spi.CoordinatorPlugin;
18+
import com.facebook.presto.spi.session.WorkerSessionPropertyProviderFactory;
19+
import com.google.common.collect.ImmutableList;
20+
21+
public class NativeSidecarPlugin
22+
implements CoordinatorPlugin
23+
{
24+
@Override
25+
public Iterable<WorkerSessionPropertyProviderFactory> getWorkerSessionPropertyProviderFactories()
26+
{
27+
return ImmutableList.of(new NativeSystemSessionPropertyProviderFactory());
28+
}
29+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.sidecar;
15+
16+
import com.facebook.presto.spi.Plugin;
17+
18+
/**
19+
* Todo: Remove this class when support for CoordinatorPlugin is added in presto-maven-plugin.
20+
*/
21+
public class NoOpPlugin
22+
implements Plugin
23+
{
24+
}

0 commit comments

Comments
 (0)