Skip to content

Commit 65c6229

Browse files
aanejaPresto CUDF CI
authored andcommitted
Add support for the MariaDb driver to the function namespace manager
This can be used in place of MySQL Connector J driver. This should help users who cannot use the MySQL Connector J driver due to its license
1 parent ef746f4 commit 65c6229

File tree

8 files changed

+97
-14
lines changed

8 files changed

+97
-14
lines changed

presto-docs/src/main/sphinx/admin/function-namespace-managers.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ following contents::
5555
function-namespaces-table-name=example_function_namespaces
5656
functions-table-name=example_sql_functions
5757

58+
To use the MariaDB Java driver instead of the MySQL Connector Java
59+
driver, use the following properties for the ``database-`` fields::
60+
61+
database-driver-name=org.mariadb.jdbc.Driver
62+
database-url=jdbc:mariadb://example.net:3306/database?user=root&password=password
63+
5864
When Presto first starts with the above MySQL function namespace
5965
manager configuration, two MySQL tables will be created if they do
6066
not exist.
@@ -86,7 +92,11 @@ The following table lists all configuration properties supported by the MySQL fu
8692
=========================================== ==================================================================================================
8793
Name Description
8894
=========================================== ==================================================================================================
89-
``database-url`` The URL of the MySQL database used by the MySQL function namespace manager.
95+
``database-url`` The JDBC URL of the MySQL database used by the MySQL function namespace manager. If using the MariaDB Java driver, ensure the URL uses the MariaDB connection string format where the string starts with ``jdbc:mariadb:``
96+
``database-driver-name`` (optional) The name of the JDBC driver class to use for connecting to the MySQL database. For the MariaDb Java client use ``org.mariadb.jdbc.Driver``. Defaults to ``com.mysql.jdbc.Driver``.
97+
``database-connection-timeout`` (optional) The timeout in milliseconds for establishing a connection to the database. Defaults to 30 seconds.
98+
``database-connection-max-lifetime`` (optional) The maximum lifetime of a connection in milliseconds. Defaults to 30 minutes.
99+
``function-namespace-manager.name`` The name of the function namespace manager to instantiate. Currently, only ``mysql`` is supported.
90100
``function-namespaces-table-name`` The name of the table that stores all the function namespaces managed by this manager.
91101
``functions-table-name`` The name of the table that stores all the functions managed by this manager.
92102
=========================================== ==================================================================================================

presto-function-namespace-managers/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@
145145
<scope>runtime</scope>
146146
</dependency>
147147

148+
<dependency>
149+
<groupId>org.mariadb.jdbc</groupId>
150+
<artifactId>mariadb-java-client</artifactId>
151+
<version>3.5.4</version>
152+
<scope>runtime</scope>
153+
</dependency>
154+
148155
<dependency>
149156
<groupId>org.jdbi</groupId>
150157
<artifactId>jdbi3-core</artifactId>

presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/mysql/MySqlConnectionConfig.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
public class MySqlConnectionConfig
2020
{
21+
private String jdbcDriverName = "com.mysql.jdbc.Driver";
22+
2123
private String databaseUrl;
2224

2325
@NotNull
@@ -32,4 +34,16 @@ public MySqlConnectionConfig setDatabaseUrl(String databaseUrl)
3234
this.databaseUrl = databaseUrl;
3335
return this;
3436
}
37+
38+
public String getJdbcDriverName()
39+
{
40+
return jdbcDriverName;
41+
}
42+
43+
@Config("database-driver-name")
44+
public MySqlConnectionConfig setJdbcDriverName(String jdbcDriverName)
45+
{
46+
this.jdbcDriverName = jdbcDriverName;
47+
return this;
48+
}
3549
}

presto-function-namespace-managers/src/main/java/com/facebook/presto/functionNamespace/mysql/MySqlConnectionModule.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ protected void setup(Binder binder)
3636
{
3737
configBinder(binder).bindConfig(MySqlConnectionConfig.class);
3838

39-
String databaseUrl = buildConfigObject(MySqlConnectionConfig.class).getDatabaseUrl();
39+
MySqlConnectionConfig mySqlConnectionConfig = buildConfigObject(MySqlConnectionConfig.class);
40+
String databaseUrl = mySqlConnectionConfig.getDatabaseUrl();
41+
String jdbcDriverName = mySqlConnectionConfig.getJdbcDriverName();
4042
try {
41-
Class.forName("com.mysql.jdbc.Driver");
43+
Class.forName(jdbcDriverName);
4244
}
4345
catch (ClassNotFoundException e) {
4446
throw new RuntimeException(e);

presto-function-namespace-managers/src/test/java/com/facebook/presto/functionNamespace/mysql/TestMySqlConnectionConfig.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ public class TestMySqlConnectionConfig
2828
public void testDefault()
2929
{
3030
assertRecordedDefaults(recordDefaults(MySqlConnectionConfig.class)
31-
.setDatabaseUrl(null));
31+
.setDatabaseUrl(null)
32+
.setJdbcDriverName("com.mysql.jdbc.Driver"));
3233
}
3334

3435
@Test
3536
public void testExplicitPropertyMappings()
3637
{
3738
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
3839
.put("database-url", "localhost:1080")
40+
.put("database-driver-name", "org.mariadb.jdbc.Driver")
3941
.build();
4042
MySqlConnectionConfig expected = new MySqlConnectionConfig()
41-
.setDatabaseUrl("localhost:1080");
43+
.setDatabaseUrl("localhost:1080")
44+
.setJdbcDriverName("org.mariadb.jdbc.Driver");
4245

4346
assertFullMapping(properties, expected);
4447
}

presto-function-namespace-managers/src/test/java/com/facebook/presto/functionNamespace/mysql/TestMySqlFunctionNamespaceManager.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979
@Test(singleThreaded = true)
8080
public class TestMySqlFunctionNamespaceManager
8181
{
82-
private static final String DB = "presto";
82+
protected static final String DB = "presto";
8383

84-
private TestingMySqlServer mySqlServer;
84+
protected TestingMySqlServer mySqlServer;
8585
private Jdbi jdbi;
8686
private Injector injector;
8787
private MySqlFunctionNamespaceManager functionNamespaceManager;
@@ -102,16 +102,10 @@ public void setup()
102102
new DriftNettyClientModule(),
103103
new MySqlConnectionModule());
104104

105-
Map<String, String> config = ImmutableMap.<String, String>builder()
106-
.put("function-cache-expiration", "0s")
107-
.put("function-instance-cache-expiration", "0s")
108-
.put("database-url", mySqlServer.getJdbcUrl(DB))
109-
.build();
110-
111105
try {
112106
this.injector = app
113107
.doNotInitializeLogging()
114-
.setRequiredConfigurationProperties(config)
108+
.setRequiredConfigurationProperties(getConfig())
115109
.initialize();
116110
this.functionNamespaceManager = injector.getInstance(MySqlFunctionNamespaceManager.class);
117111
this.jdbi = injector.getInstance(Jdbi.class);
@@ -122,6 +116,15 @@ public void setup()
122116
}
123117
}
124118

119+
protected Map<String, String> getConfig()
120+
{
121+
return ImmutableMap.<String, String>builder()
122+
.put("function-cache-expiration", "0s")
123+
.put("function-instance-cache-expiration", "0s")
124+
.put("database-url", mySqlServer.getJdbcUrl(DB))
125+
.build();
126+
}
127+
125128
@BeforeMethod
126129
public void setupFunctionNamespace()
127130
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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.functionNamespace.mysql;
15+
16+
import com.google.common.collect.ImmutableMap;
17+
import org.testng.annotations.Test;
18+
19+
import java.util.Map;
20+
21+
@Test(singleThreaded = true)
22+
public class TestMySqlFunctionNamespaceManagerWithMariaDbDriver
23+
extends TestMySqlFunctionNamespaceManager
24+
{
25+
@Override
26+
protected Map<String, String> getConfig()
27+
{
28+
String jdbcUrl = mySqlServer.getJdbcUrl(DB).replaceFirst("jdbc:mysql:", "jdbc:mariadb:");
29+
30+
return ImmutableMap.<String, String>builder()
31+
.put("function-cache-expiration", "0s")
32+
.put("function-instance-cache-expiration", "0s")
33+
.put("database-url", jdbcUrl)
34+
.put("database-driver-name", "org.mariadb.jdbc.Driver")
35+
.build();
36+
}
37+
}

presto-singlestore/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@
167167
<groupId>com.facebook.presto</groupId>
168168
<artifactId>presto-tests</artifactId>
169169
<scope>test</scope>
170+
<exclusions>
171+
<exclusion>
172+
<!-- Exclude MariaDB client to avoid conflict with SingleStore JDBC Driver-->
173+
<groupId>org.mariadb.jdbc</groupId>
174+
<artifactId>mariadb-java-client</artifactId>
175+
</exclusion>
176+
</exclusions>
170177
</dependency>
171178

172179
<dependency>

0 commit comments

Comments
 (0)