Skip to content

Commit 34532e4

Browse files
committed
Add support for FixedString
1 parent c91541f commit 34532e4

File tree

4 files changed

+12
-1
lines changed

4 files changed

+12
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ void SimplePOJODataTest() throws Exception {
215215
"booleanPrimitive Boolean," +
216216
"booleanObject Boolean," +
217217
"str String," +
218+
"fixedStr FixedString(10)" +
218219
") " +
219220
"ENGINE = MergeTree " +
220221
"ORDER BY (longPrimitive); ";
@@ -483,6 +484,7 @@ void SimplePOJODataTooManyPartsTest() throws Exception {
483484
"booleanPrimitive Boolean," +
484485
"booleanObject Boolean," +
485486
"str String," +
487+
"fixedStr FixedString(10)" +
486488
") " +
487489
"ENGINE = MergeTree " +
488490
"ORDER BY (longPrimitive) " +

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public void instrument(OutputStream out, SimplePOJO input) throws IOException {
3535
Serialize.writeBoolean(out, input.isBooleanPrimitive(), false, false, ClickHouseDataType.Bool, false, "booleanPrimitive");
3636
Serialize.writeBoolean(out, input.getBooleanObject(), false, false, ClickHouseDataType.Bool, false, "booleanObject");
3737

38-
Serialize.writeString(out, input.getStr(), false, false, ClickHouseDataType.String, false, "String");
38+
Serialize.writeString(out, input.getStr(), false, false, ClickHouseDataType.String, false, "str");
39+
Serialize.writeFixedString(out, input.getFixedStr(), false, false, ClickHouseDataType.FixedString, false, 10, "fixedStr");
3940

4041
}
4142
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public class SimplePOJO {
2727

2828
private String str;
2929

30+
private String fixedStr;
31+
3032
private BigInteger bigInteger128;
3133
private BigInteger bigInteger256;
3234

@@ -53,9 +55,12 @@ public SimplePOJO(int index) {
5355
this.booleanObject = Boolean.FALSE;
5456

5557
this.str = "str" + longPrimitive;
58+
this.fixedStr = (str + "_FixedString").substring(0, 10);
5659

5760
this.bigInteger128 = BigInteger.valueOf(longPrimitive);
5861
this.bigInteger256 = BigInteger.valueOf(longPrimitive);
62+
63+
5964
}
6065

6166
public byte getBytePrimitive() {
@@ -115,4 +120,6 @@ public Double getDoubleObject() {
115120
public BigInteger getBigInteger128() { return bigInteger128; }
116121

117122
public BigInteger getBigInteger256() { return bigInteger256; }
123+
124+
public String getFixedStr() { return fixedStr; }
118125
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public static void writeString(OutputStream out, String value, boolean defaultsS
135135
}
136136
}
137137

138+
// Add a boundary check before inserting
138139
public static void writeFixedString(OutputStream out, String value, boolean defaultsSupport, boolean isNullable, ClickHouseDataType dataType, boolean hasDefault, int size, String column) throws IOException {
139140
if (writeValuePreamble(out, defaultsSupport, isNullable, dataType, hasDefault, column, value)) {
140141
BinaryStreamUtils.writeFixedString(out, convertToString(value), size);

0 commit comments

Comments
 (0)