Skip to content

Commit bc4c13b

Browse files
committed
added a test for toKeyValuePairs()
1 parent 15d30e0 commit bc4c13b

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ public static Map<String, Object> parseConfigMap(Map<String, String> configMap)
343343

344344
/**
345345
* Converts given string to key value pairs.
346+
* This is very simple implementation that do not handle edge cases like
347+
* {@code k1=v1, ,k2=v2}
346348
*
347349
* @param str string
348350
* @return non-null key value pairs
@@ -393,6 +395,7 @@ public static Map<String, String> toKeyValuePairs(String str) {
393395
}
394396

395397

398+
396399
public static String mapToString(Map<?,?> map, Function<Object, String> valueConverter) {
397400
StringBuilder sb = new StringBuilder();
398401
for (Map.Entry<?, ?> entry : map.entrySet()) {

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
public abstract class AbstractBinaryFormatReader implements ClickHouseBinaryFormatReader {
5353

54-
public static final Map<ClickHouseDataType, Class<?>> NO_TYPE_HINT_MAPPING = null;
54+
public static final Map<ClickHouseDataType, Class<?>> NO_TYPE_HINT_MAPPING = Collections.emptyMap();
5555

5656
private static final Logger LOG = LoggerFactory.getLogger(AbstractBinaryFormatReader.class);
5757

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.clickhouse.client.api;
2+
3+
4+
import org.testng.Assert;
5+
import org.testng.annotations.Test;
6+
7+
import java.util.Map;
8+
9+
10+
public class ClientConfigPropertiesTest {
11+
12+
@Test(groups = {"unit"})
13+
public void testToKeyValuePairs() {
14+
15+
Map<String, String> map = ClientConfigProperties.toKeyValuePairs("key1=value1,key2=value2");
16+
Assert.assertEquals(map.size(), 2);
17+
Assert.assertEquals(map.get("key1"), "value1");
18+
Assert.assertEquals(map.get("key2"), "value2");
19+
20+
map = ClientConfigProperties.toKeyValuePairs("key1=value1, key2 = value2");
21+
Assert.assertEquals(map.size(), 2);
22+
Assert.assertEquals(map.get("key1"), "value1");
23+
Assert.assertEquals(map.get("key2"), "value2");
24+
25+
map = ClientConfigProperties.toKeyValuePairs("key1");
26+
Assert.assertEquals(map.size(), 0);
27+
28+
// TODO: improve implementation
29+
// map = ClientConfigProperties.toKeyValuePairs("key1=value1, ,key2=value2");
30+
// Assert.assertEquals(map.size(), 2);
31+
// Assert.assertEquals(map.get("key1"), "value1");
32+
// Assert.assertEquals(map.get("key2"), "value2");
33+
}
34+
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ public static Object convert(Object value, Class<?> type, ClickHouseColumn colum
230230
}
231231
return new Array(((BinaryStreamReader.ArrayValue) value).asList(), "Object", JDBCType.JAVA_OBJECT.getVendorTypeNumber());
232232
} else if (type == java.sql.Array.class && value instanceof List<?>) {
233-
System.out.println(value);
234233
if (column != null && column.getArrayBaseColumn() != null) {
235234
return new Array(convertList(((List) value), JdbcUtils.convertToJavaClass(column.getArrayBaseColumn().getDataType())), "Object", JDBCType.JAVA_OBJECT.getVendorTypeNumber());
236235
}

0 commit comments

Comments
 (0)