Skip to content

Commit b61cacc

Browse files
author
Paultagoras
committed
Add Bool serialization support
1 parent db60351 commit b61cacc

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,10 @@ private static void binaryReaderMethodForType(MethodVisitor mv, Class<?> targetT
957957
readerMethod = "readShortLE";
958958
readerMethodReturnType = Type.getDescriptor(short.class);
959959
break;
960+
case Bool:
961+
readerMethod = "readByte";
962+
readerMethodReturnType = Type.getDescriptor(byte.class);
963+
break;
960964
default:
961965
throw new ClientException("Column type '" + dataType + "' cannot be set to a primitive type '" + targetType + "'");
962966
}

client-v2/src/test/java/com/clickhouse/client/query/QuerySamplePOJO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ public static String generateTableCreateSQL(String tableName) {
558558
"decimal64 Decimal64(3), " +
559559
"decimal128 Decimal128(4), " +
560560
"decimal256 Decimal256(5), " +
561-
"bool UInt8, " +
561+
"bool Bool, " +
562562
"string String, " +
563563
"fixedString FixedString(3), " +
564564
"date Date, " +

client-v2/src/test/java/com/clickhouse/client/query/QueryTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,13 +1800,20 @@ public void testConcurrentQueries() throws Exception{
18001800
@Test(groups = {"integration"})
18011801
public void testQueryReadToPOJO() {
18021802
int limit = 10;
1803-
final String sql = "SELECT toInt32(rand32()) as id, toInt32(number * 10) as age, concat('name_', toString(number + 1)) as name " +
1803+
final String sql = "SELECT toInt32(rand32()) as id, toInt32(number * 10) as age, concat('name_', toString(number + 1)) as name, true as bool " +
18041804
" FROM system.numbers LIMIT " + limit;
18051805
TableSchema schema = client.getTableSchemaFromQuery(sql);
18061806
client.register(SimplePOJO.class, schema);
18071807

18081808
List<SimplePOJO> pojos = client.queryAll(sql, SimplePOJO.class, schema);
18091809
Assert.assertEquals(pojos.size(), limit);
1810+
1811+
for (SimplePOJO pojo : pojos) {
1812+
Assert.assertNotNull(pojo.getId());
1813+
Assert.assertNotNull(pojo.getAge());
1814+
Assert.assertNotNull(pojo.getName());
1815+
Assert.assertTrue(pojo.getBool());
1816+
}
18101817
}
18111818

18121819
@Test(groups = {"integration"})

client-v2/src/test/java/com/clickhouse/client/query/SimplePOJO.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public class SimplePOJO {
99

1010
Integer age = null;
1111

12+
Boolean bool = false;
13+
1214
public long getId() {
1315
return id;
1416
}
@@ -33,12 +35,21 @@ public void setAge(Integer age) {
3335
this.age = age;
3436
}
3537

38+
public Boolean getBool() {
39+
return bool;
40+
}
41+
42+
public void setBool(Boolean bool) {
43+
this.bool = bool;
44+
}
45+
3646
@Override
3747
public String toString() {
3848
return "SimplePOJO{" +
3949
"id=" + id +
4050
", name='" + name + '\'' +
4151
", age=" + age +
52+
", bool=" + bool +
4253
'}';
4354
}
4455
}

0 commit comments

Comments
 (0)