Skip to content

Commit 90f5881

Browse files
authored
Pass Pinot Connection properties from JDBC driver (#7822)
1 parent 819cba0 commit 90f5881

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotConnection.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.sql.SQLException;
2525
import java.sql.Statement;
2626
import java.util.List;
27+
import java.util.Properties;
2728
import org.apache.pinot.client.base.AbstractBaseConnection;
2829
import org.apache.pinot.client.controller.PinotControllerTransport;
2930
import org.apache.pinot.client.controller.response.ControllerTenantBrokerResponse;
@@ -40,11 +41,20 @@ public class PinotConnection extends AbstractBaseConnection {
4041
private PinotControllerTransport _controllerTransport;
4142

4243
PinotConnection(String controllerURL, PinotClientTransport transport, String tenant) {
43-
this(controllerURL, transport, tenant, null);
44+
this(new Properties(), controllerURL, transport, tenant, null);
45+
}
46+
47+
PinotConnection(Properties properties, String controllerURL, PinotClientTransport transport, String tenant) {
48+
this(properties, controllerURL, transport, tenant, null);
4449
}
4550

4651
PinotConnection(String controllerURL, PinotClientTransport transport, String tenant,
4752
PinotControllerTransport controllerTransport) {
53+
this(new Properties(), controllerURL, transport, tenant, controllerTransport);
54+
}
55+
56+
PinotConnection(Properties properties, String controllerURL, PinotClientTransport transport, String tenant,
57+
PinotControllerTransport controllerTransport) {
4858
_closed = false;
4959
_controllerURL = controllerURL;
5060
if (controllerTransport == null) {
@@ -53,7 +63,7 @@ public class PinotConnection extends AbstractBaseConnection {
5363
_controllerTransport = controllerTransport;
5464
}
5565
List<String> brokers = getBrokerList(controllerURL, tenant);
56-
_session = new org.apache.pinot.client.Connection(brokers, transport);
66+
_session = new org.apache.pinot.client.Connection(properties, brokers, transport);
5767
}
5868

5969
public org.apache.pinot.client.Connection getSession() {

pinot-clients/pinot-jdbc-client/src/main/java/org/apache/pinot/client/PinotDriver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public Connection connect(String url, Properties info)
5858

5959
Map<String, String> headers =
6060
info.entrySet().stream().filter(entry -> entry.getKey().toString().startsWith(INFO_HEADERS + ".")).map(
61-
entry -> Pair
62-
.of(entry.getKey().toString().substring(INFO_HEADERS.length() + 1), entry.getValue().toString()))
61+
entry -> Pair
62+
.of(entry.getKey().toString().substring(INFO_HEADERS.length() + 1), entry.getValue().toString()))
6363
.collect(Collectors.toMap(Pair::getKey, Pair::getValue));
6464
if (!headers.isEmpty()) {
6565
factory.setHeaders(headers);
@@ -68,7 +68,7 @@ public Connection connect(String url, Properties info)
6868
PinotClientTransport pinotClientTransport = factory.buildTransport();
6969
String controllerUrl = DriverUtils.getControllerFromURL(url);
7070
String tenant = info.getProperty(INFO_TENANT, DEFAULT_TENANT);
71-
return new PinotConnection(controllerUrl, pinotClientTransport, tenant);
71+
return new PinotConnection(info, controllerUrl, pinotClientTransport, tenant);
7272
} catch (Exception e) {
7373
throw new SQLException(String.format("Failed to connect to url : %s", url), e);
7474
}

pinot-clients/pinot-jdbc-client/src/test/java/org/apache/pinot/client/PinotPreparedStatementTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.sql.PreparedStatement;
2424
import java.sql.Time;
2525
import java.sql.Timestamp;
26+
import java.util.Properties;
2627
import org.apache.commons.codec.binary.Hex;
2728
import org.apache.pinot.client.utils.DateTimeUtils;
2829
import org.testng.Assert;
@@ -41,7 +42,8 @@ public class PinotPreparedStatementTest {
4142
public void testSetAndClearValues()
4243
throws Exception {
4344
PinotConnection connection =
44-
new PinotConnection("dummy", _dummyPinotClientTransport, "dummy", _dummyPinotControllerTransport);
45+
new PinotConnection(new Properties(), "dummy", _dummyPinotClientTransport, "dummy",
46+
_dummyPinotControllerTransport);
4547
PreparedStatement preparedStatement = connection.prepareStatement(QUERY);
4648

4749
preparedStatement.setString(1, "foo");

0 commit comments

Comments
 (0)