Skip to content

Commit 5e62b34

Browse files
committed
Fix issue #2218
1 parent 935e491 commit 5e62b34

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseColumn.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,9 @@ private static ClickHouseColumn update(ClickHouseColumn column) {
249249
case FixedString:
250250
if (size > 0) {
251251
column.precision = Integer.parseInt(column.parameters.get(0));
252-
if (!column.nullable) {
253-
column.estimatedByteLength += column.precision;
252+
column.estimatedByteLength += column.precision;
253+
if (column.nullable) {
254+
column.estimatedByteLength -= 1;
254255
}
255256
}
256257
column.template = ClickHouseStringValue.ofNull();

jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,36 @@ public void testSwitchDatabase() throws Exception {
573573
}
574574
}
575575
}
576+
577+
@Test(groups = { "integration" })
578+
public void testNullableFixedStringType() throws Exception {
579+
try (Connection conn = getJdbcConnection()) {
580+
String sqlCreate = "CREATE TABLE `data_types` (`f1` FixedString(4),`f2` LowCardinality(FixedString(4)), `f3` Nullable(FixedString(4)), `f4` LowCardinality(Nullable(FixedString(4))) ) ENGINE Memory;";
581+
try (Statement stmt = conn.createStatement()) {
582+
int r = stmt.executeUpdate(sqlCreate);
583+
assertEquals(r, 0);
584+
}
585+
try(Statement stmt = conn.createStatement()) {
586+
String sqlInsert = "INSERT INTO `data_types` VALUES ('val1', 'val2', 'val3', 'val4')";
587+
int r = stmt.executeUpdate(sqlInsert);
588+
assertEquals(r, 1);
589+
}
590+
try(Statement stmt = conn.createStatement()) {
591+
String sqlSelect = "SELECT * FROM `data_types`";
592+
ResultSet rs = stmt.executeQuery(sqlSelect);
593+
assertTrue(rs.next());
594+
assertEquals(rs.getString(1), "val1");
595+
assertEquals(rs.getString(2), "val2");
596+
assertEquals(rs.getString(3), "val3");
597+
assertEquals(rs.getString(4), "val4");
598+
assertFalse(rs.next());
599+
}
600+
try(Statement stmt = conn.createStatement()) {
601+
String sqlSelect = "SELECT f4 FROM `data_types`";
602+
ResultSet rs = stmt.executeQuery(sqlSelect);
603+
assertTrue(rs.next());
604+
assertEquals(rs.getString(1), "val4");
605+
}
606+
}
607+
}
576608
}

0 commit comments

Comments
 (0)