Skip to content

Commit e3b62be

Browse files
committed
Adding String & Boolean support
1 parent e484367 commit e3b62be

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,16 @@ data.sinkTo(csvSink);
117117

118118
## Supported ClickHouse Types
119119

120-
| Java Type | ClickHouse Type | Supported |
121-
|---------------|-----------------|-----------|
122-
| byte/Byte | Int8 ||
123-
| short/Short | Int16 ||
124-
| int/Integer | Int32 ||
125-
| long/Long | Int64 ||
126-
| float/Float | Float ||
127-
| double/Double | Double ||
120+
| Java Type | ClickHouse Type | Supported |
121+
|-----------------|-----------------|-----------|
122+
| byte/Byte | Int8 ||
123+
| short/Short | Int16 ||
124+
| int/Integer | Int32 ||
125+
| long/Long | Int64 ||
126+
| float/Float | Float ||
127+
| double/Double | Double ||
128+
| boolean/Boolean | Boolean ||
129+
| String | String ||
128130

129131
## Configuration Options
130132

flink-connector-clickhouse-1.17/src/test/java/org/apache/flink/connector/clickhouse/sink/ClickHouseSinkTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ void SimplePOJODataTest() throws Exception {
210210
"floatObject Float," +
211211
"doublePrimitive Double," +
212212
"doubleObject Double," +
213+
"booleanPrimitive Boolean," +
214+
"booleanObject Boolean," +
215+
"str String," +
213216
") " +
214217
"ENGINE = MergeTree " +
215218
"ORDER BY (longPrimitive); ";
@@ -468,6 +471,9 @@ void SimplePOJODataTooManyPartsTest() throws Exception {
468471
"floatObject Float," +
469472
"doublePrimitive Double," +
470473
"doubleObject Double," +
474+
"booleanPrimitive Boolean," +
475+
"booleanObject Boolean," +
476+
"str String," +
471477
") " +
472478
"ENGINE = MergeTree " +
473479
"ORDER BY (longPrimitive) " +

flink-connector-clickhouse-1.17/src/test/java/org/apache/flink/connector/clickhouse/sink/convertor/SimplePOJOConvertor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,11 @@ public void instrument(OutputStream out, SimplePOJO input) throws IOException {
2828

2929
Serialize.writeFloat64(out, input.getDoublePrimitive(), false, false, ClickHouseDataType.Float64, false, "doublePrimitive");
3030
Serialize.writeFloat64(out, input.getDoubleObject(), false, false, ClickHouseDataType.Float64, false, "doubleObject");
31+
32+
Serialize.writeBoolean(out, input.isBooleanPrimitive(), false, false, ClickHouseDataType.Bool, false, "booleanPrimitive");
33+
Serialize.writeBoolean(out, input.getBooleanObject(), false, false, ClickHouseDataType.Bool, false, "booleanObject");
34+
35+
Serialize.writeString(out, input.getStr(), false, false, ClickHouseDataType.String, false, "String");
36+
3137
}
3238
}

flink-connector-clickhouse-1.17/src/test/java/org/apache/flink/connector/clickhouse/sink/pojo/SimplePOJO.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class SimplePOJO {
2020
private double doublePrimitive;
2121
private Double doubleObject;
2222

23+
private boolean booleanPrimitive;
24+
private Boolean booleanObject;
25+
26+
private String str;
27+
2328
public SimplePOJO(int index) {
2429
this.bytePrimitive = Byte.MIN_VALUE;
2530
this.byteObject = Byte.MAX_VALUE;
@@ -38,6 +43,11 @@ public SimplePOJO(int index) {
3843

3944
this.doublePrimitive = Double.MIN_VALUE;
4045
this.doubleObject = Double.MAX_VALUE;
46+
47+
this.booleanPrimitive = true;
48+
this.booleanObject = Boolean.FALSE;
49+
50+
this.str = "str" + longPrimitive;
4151
}
4252

4353
public byte getBytePrimitive() {
@@ -87,4 +97,10 @@ public double getDoublePrimitive() {
8797
public Double getDoubleObject() {
8898
return doubleObject;
8999
}
100+
101+
public boolean isBooleanPrimitive() { return booleanPrimitive; }
102+
103+
public Boolean getBooleanObject() { return booleanObject; }
104+
105+
public String getStr() { return str; }
90106
}

flink-connector-clickhouse-base/src/main/java/com/clickhouse/utils/Serialize.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,11 @@ public static void writeFloat64(OutputStream out, Double value, boolean defaults
182182
}
183183
}
184184

185+
// Boolean
186+
public static void writeBoolean(OutputStream out, Boolean value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, String column) throws IOException {
187+
if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) {
188+
BinaryStreamUtils.writeBoolean(out, value);
189+
}
190+
}
191+
185192
}

0 commit comments

Comments
 (0)