Skip to content

Commit 84050eb

Browse files
committed
fixed handling driver properties and default values. Fixed passing custom_ properties to server
1 parent c1be459 commit 84050eb

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

client-v2/src/main/java/com/clickhouse/client/api/ClientConfigProperties.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ public <T> T getDefObjVal() {
224224

225225
public static final String SERVER_SETTING_PREFIX = "clickhouse_setting_";
226226

227+
public static final String CUSTOM_SETTING_PREFIX = "custom_";
228+
227229
// Key used to identify default value in configuration map
228230
public static final String DEFAULT_KEY = "_default_";
229231

@@ -339,6 +341,8 @@ public static Map<String, Object> parseConfigMap(Map<String, String> configMap)
339341
for (String key : new HashSet<>(tmpMap.keySet())) {
340342
if (key.startsWith(HTTP_HEADER_PREFIX) || key.startsWith(SERVER_SETTING_PREFIX)) {
341343
parsedConfig.put(key, tmpMap.remove(key));
344+
} else if (key.startsWith(CUSTOM_SETTING_PREFIX)) {
345+
parsedConfig.put(serverSetting(key), tmpMap.remove(key));
342346
}
343347
}
344348

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,12 @@ private void initProperties(Map<String, String> urlProperties, Properties provid
240240

241241
// Copy provided properties
242242
Map<String, String> props = new HashMap<>();
243+
// Set driver properties defaults (client will do the same)
244+
for (DriverProperties prop : DriverProperties.values()) {
245+
if (prop.getDefaultValue() != null) {
246+
props.put(prop.getKey(), prop.getDefaultValue());
247+
}
248+
}
243249
for (Map.Entry<Object, Object> entry : providedProperties.entrySet()) {
244250
if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
245251
props.put((String) entry.getKey(), (String) entry.getValue());
@@ -264,8 +270,10 @@ private void initProperties(Map<String, String> urlProperties, Properties provid
264270
DriverPropertyInfo propertyInfo = new DriverPropertyInfo(prop.getKey(), prop.getValue());
265271
propertyInfo.description = "(User Defined)";
266272
propertyInfos.put(prop.getKey(), propertyInfo);
267-
if (!DRIVER_PROP_KEYS.contains(prop.getKey())) {
268-
// filter out driver properties
273+
274+
if (DRIVER_PROP_KEYS.contains(prop.getKey())) {
275+
driverProperties.put(prop.getKey(), prop.getValue());
276+
} else {
269277
clientProperties.put(prop.getKey(), prop.getValue());
270278
}
271279
}
@@ -288,11 +296,6 @@ private void initProperties(Map<String, String> urlProperties, Properties provid
288296
propertyInfo = new DriverPropertyInfo(driverProp.getKey(), driverProp.getDefaultValue());
289297
propertyInfos.put(driverProp.getKey(), propertyInfo);
290298
}
291-
292-
String value = clientProperties.get(driverProp.getKey());
293-
if (value != null) {
294-
driverProperties.put(driverProp.getKey(), value);
295-
}
296299
}
297300

298301
listOfProperties = propertyInfos.values().stream().sorted(Comparator.comparing(o -> o.name)).collect(Collectors.toList());

jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ public class JdbcConfigurationTest {
3232
new JdbcConfigurationTestData("jdbc:clickhouse://localhost")
3333
.withAdditionalConnectionParameters(
3434
Map.of(JdbcConfiguration.USE_SSL_PROP, "true"))
35-
.withExpectedConnectionURL("https://localhost:8443")
36-
.withAdditionalExpectedClientProperties(
37-
Map.of("ssl", "true")),
35+
.withExpectedConnectionURL("https://localhost:8443"), // ssl should not be passed to client
3836
new JdbcConfigurationTestData("jdbc:clickhouse://[::1]")
3937
.withExpectedConnectionURL("http://[::1]:8123"),
4038
new JdbcConfigurationTestData("jdbc:clickhouse://[::1]:8123")
@@ -60,59 +58,59 @@ public class JdbcConfigurationTest {
6058
new JdbcConfigurationTestData("jdbc:clickhouse://localhost/☺")
6159
.withAdditionalExpectedClientProperties(
6260
Map.of("database", "☺")),
63-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?key1=val1&key2=val2")
61+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?custom_key1=val1&custom_key2=val2")
6462
.withAdditionalExpectedClientProperties(
6563
Map.of(
6664
"database", "db",
67-
"key1", "val1",
68-
"key2", "val2"
65+
"custom_key1", "val1",
66+
"custom_key2", "val2"
6967
)),
70-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?key1=val%201")
68+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?custom_key1=val%201")
7169
.withAdditionalExpectedClientProperties(
7270
Map.of(
7371
"database", "db",
74-
"key1", "val 1"
72+
"custom_key1", "val 1"
7573
)),
76-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost/?key1=val1")
74+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost/?custom_key1=val1")
7775
.withAdditionalExpectedClientProperties(
7876
Map.of(
79-
"key1", "val1"
77+
"custom_key1", "val1"
8078
)),
81-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost?key1=val1")
79+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=val1")
8280
.withAdditionalExpectedClientProperties(
8381
Map.of(
84-
"key1", "val1"
82+
"custom_key1", "val1"
8583
)),
86-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123?key1=val1")
84+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123?custom_key1=val1")
8785
.withExpectedConnectionURL("http://localhost:8123")
8886
.withAdditionalExpectedClientProperties(
8987
Map.of(
90-
"key1", "val1"
88+
"custom_key1", "val1"
9189
)),
92-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/?key1=val1")
90+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/?custom_key1=val1")
9391
.withExpectedConnectionURL("http://localhost:8123")
9492
.withAdditionalExpectedClientProperties(
9593
Map.of(
96-
"key1", "val1"
94+
"custom_key1", "val1"
9795
)),
98-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost?key1=☺")
96+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=☺")
9997
.withAdditionalExpectedClientProperties(
10098
Map.of(
101-
"key1", "☺"
99+
"custom_key1", "☺"
102100
)),
103-
new JdbcConfigurationTestData("jdbc:clickhouse://localhost?key1=val1,val2")
101+
new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=val1,val2")
104102
.withAdditionalExpectedClientProperties(
105103
Map.of(
106-
"key1", "val1,val2"
104+
"custom_key1", "val1,val2"
107105
)),
108106
new JdbcConfigurationTestData(
109-
"jdbc:clickhouse://localhost:8443/default?custom_header1=%22role%201,3,4%22,%27val2%27,val3&param1=value1")
107+
"jdbc:clickhouse://localhost:8443/default?http_header_roles=%22role%201,3,4%22,%27val2%27,val3&ssl=false")
110108
.withExpectedConnectionURL("http://localhost:8443")
111109
.withAdditionalExpectedClientProperties(
112110
Map.of(
113111
"database", "default",
114-
"custom_header1", "\"role 1,3,4\",'val2',val3",
115-
"param1", "value1"
112+
"http_header_roles", "\"role 1,3,4\",'val2',val3"
113+
// ssl should not be passed to client
116114
))
117115
};
118116

@@ -124,7 +122,7 @@ public void testParseURLValid(String jdbcURL, Properties properties,
124122
{
125123
JdbcConfiguration configuration = new JdbcConfiguration(jdbcURL, properties);
126124
assertEquals(configuration.getConnectionUrl(), connectionURL);
127-
assertEquals(configuration.clientProperties, expectedClientProps);
125+
assertEquals(configuration.clientProperties, expectedClientProps, "clientProperties" + configuration.clientProperties + " vs " + expectedClientProps);
128126
Client.Builder bob = new Client.Builder();
129127
configuration.applyClientProperties(bob);
130128
Client client = bob.build();

0 commit comments

Comments
 (0)