Skip to content

Commit a15f08f

Browse files
authored
Simplify config loading (#102)
1 parent 8922004 commit a15f08f

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

hoptimator-jdbc/src/main/java/com/linkedin/hoptimator/jdbc/HoptimatorDriver.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Properties;
77
import java.util.function.Supplier;
88

9+
import org.apache.calcite.avatica.ConnectStringParser;
910
import org.apache.calcite.avatica.DriverVersion;
1011
import org.apache.calcite.jdbc.CalciteConnection;
1112
import org.apache.calcite.jdbc.CalcitePrepare;
@@ -69,28 +70,32 @@ public Connection connect(String url, Properties props) throws SQLException {
6970
CalciteConnection calciteConnection = (CalciteConnection) connection;
7071
SchemaPlus rootSchema = calciteConnection.getRootSchema();
7172

72-
String remaining = url.substring(getConnectStringPrefix().length()).trim();
73-
String[] catalogs = remaining.split(",");
74-
7573
// built-in schemas
7674
rootSchema.add("DEFAULT", new AbstractSchema());
7775

7876
calciteConnection.setSchema("DEFAULT");
7977

8078
WrappedSchemaPlus wrappedRootSchema = new WrappedSchemaPlus(rootSchema);
79+
80+
// Load properties from url and from getConnection()
81+
Properties properties = new Properties();
82+
properties.putAll(props); // via getConnection()
83+
properties.putAll(ConnectStringParser.parse(url.substring(getConnectStringPrefix().length())));
84+
String[] catalogs = properties.getProperty("catalogs", "").split(",");
85+
8186
if (catalogs.length == 0 || catalogs[0].length() == 0) {
8287
// load all catalogs (typical usage)
8388
for (Catalog catalog : CatalogService.catalogs()) {
84-
catalog.register(wrappedRootSchema, props);
89+
catalog.register(wrappedRootSchema, properties);
8590
}
8691
} else {
87-
// load specific catalogs when loaded as `jdbc:hoptimator://foo,bar`
92+
// load specific catalogs when loaded as `jdbc:hoptimator://catalogs=foo,bar`
8893
for (String catalog : catalogs) {
8994
CatalogService.catalog(catalog).register(wrappedRootSchema, props);
9095
}
9196
}
9297

93-
return new HoptimatorConnection(calciteConnection, props);
98+
return new HoptimatorConnection(calciteConnection, properties);
9499
} catch (Exception e) {
95100
throw new SQLException("Problem loading " + url, e);
96101
}

hoptimator-jdbc/src/testFixtures/java/com/linkedin/hoptimator/jdbc/QuidemTestBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected void run(URI resource) throws IOException {
4242
Quidem.Config config = Quidem.configBuilder()
4343
.withReader(r)
4444
.withWriter(w)
45-
.withConnectionFactory((x, y) -> DriverManager.getConnection("jdbc:hoptimator://" + x))
45+
.withConnectionFactory((x, y) -> DriverManager.getConnection("jdbc:hoptimator://catalogs=" + x))
4646
.withCommandHandler(new CustomCommandHandler())
4747
.build();
4848
new Quidem(config).execute();

hoptimator-kafka/src/main/java/com/linkedin/hoptimator/kafka/KafkaDriver.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import org.apache.calcite.jdbc.Driver;
1212
import org.apache.calcite.schema.SchemaPlus;
1313

14-
import com.linkedin.hoptimator.util.ConfigService;
15-
1614

1715
/** JDBC driver for Kafka topics. */
1816
public class KafkaDriver extends Driver {
@@ -36,9 +34,9 @@ public Connection connect(String url, Properties props) throws SQLException {
3634
if (!url.startsWith(getConnectStringPrefix())) {
3735
return null;
3836
}
39-
// Connection string properties are given precedence over config properties
40-
Properties properties = ConfigService.config(null);
37+
Properties properties = new Properties();
4138
properties.putAll(ConnectStringParser.parse(url.substring(getConnectStringPrefix().length())));
39+
properties.putAll(props); // in case the driver is loaded via getConnection()
4240
try {
4341
Connection connection = super.connect(url, props);
4442
if (connection == null) {

hoptimator-util/src/main/java/com/linkedin/hoptimator/util/ConfigService.java

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public final class ConfigService {
1616
private ConfigService() {
1717
}
1818

19-
// Null namespace will default to current namespace, may not be used by some ConfigProviders.
2019
// loadTopLevelConfigs=true loads top level configs and expands input fields as file-like properties
2120
// loadTopLevelConfigs=false will only expand input fields as file-like properties
2221
// Ex:

hoptimator-venice/src/main/java/com/linkedin/hoptimator/venice/VeniceDriver.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.apache.calcite.jdbc.Driver;
1313
import org.apache.calcite.schema.SchemaPlus;
1414

15-
import com.linkedin.hoptimator.util.ConfigService;
16-
1715

1816
/** JDBC driver for Venice stores. */
1917
public class VeniceDriver extends Driver {
@@ -40,8 +38,9 @@ public Connection connect(String url, Properties props) throws SQLException {
4038
return null;
4139
}
4240
// Connection string properties are given precedence over config properties
43-
Properties properties = ConfigService.config(null, CONFIG_NAME);
41+
Properties properties = new Properties();
4442
properties.putAll(ConnectStringParser.parse(url.substring(getConnectStringPrefix().length())));
43+
properties.putAll(props); // in case the driver is loaded via getConnection()
4544
String cluster = properties.getProperty("cluster");
4645
if (cluster == null) {
4746
throw new IllegalArgumentException("Missing required cluster property. Need: jdbc:venice://cluster=...");

0 commit comments

Comments
 (0)