clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

jdbc isn't allows to insert shorter string into FixedString field

Open TheHett opened this issue 3 years ago • 1 comments

The field declared as FixedString(2)

CREATE TABLE test
(
    country             FixedString(2)
)
    ENGINE = MergeTree()
        PRIMARY KEY (country)
        ORDER BY (country)
;

If we tried to insert data in SQL, its work fine:

INSERT INTO test VALUES('C')

And will selecting it back

SELECT * FROM test WHERE country = 'C'

But jdbc driver isn't allow it:

Caused by: java.lang.IllegalArgumentException: length of byte array value is 1, but it should be 2
	at com.clickhouse.client.ClickHouseChecker.newException(ClickHouseChecker.java:19) ~[clickhouse-cli-client-0.3.2-patch11-shaded.jar:clickhouse-cli-client 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.client.ClickHouseChecker.notWithDifferentLength(ClickHouseChecker.java:382) ~[clickhouse-cli-client-0.3.2-patch11-shaded.jar:clickhouse-cli-client 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.client.ClickHouseChecker.notWithDifferentLength(ClickHouseChecker.java:364) ~[clickhouse-cli-client-0.3.2-patch11-shaded.jar:clickhouse-cli-client 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.client.data.ClickHouseStringValue.asBinary(ClickHouseStringValue.java:230) ~[clickhouse-cli-client-0.3.2-patch11-shaded.jar:clickhouse-cli-client 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.client.ClickHouseValue.asBinary(ClickHouseValue.java:569) ~[clickhouse-cli-client-0.3.2-patch11-shaded.jar:clickhouse-cli-client 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.client.data.ClickHouseRowBinaryProcessor$MappedFunctions.lambda$buildMappingsForDataTypes$63(ClickHouseRowBinaryProcessor.java:334) ~[clickhouse-cli-client-0.3.2-patch11-shaded.jar:clickhouse-cli-client 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.client.data.ClickHouseRowBinaryProcessor$MappedFunctions.serialize(ClickHouseRowBinaryProcessor.java:486) ~[clickhouse-cli-client-0.3.2-patch11-shaded.jar:clickhouse-cli-client 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.jdbc.internal.InputBasedPreparedStatement.addBatch(InputBasedPreparedStatement.java:333) ~[clickhouse-jdbc-0.3.2-patch11.jar:clickhouse-jdbc 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.jdbc.internal.InputBasedPreparedStatement.executeAny(InputBasedPreparedStatement.java:110) ~[clickhouse-jdbc-0.3.2-patch11.jar:clickhouse-jdbc 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.jdbc.internal.InputBasedPreparedStatement.executeLargeUpdate(InputBasedPreparedStatement.java:185) ~[clickhouse-jdbc-0.3.2-patch11.jar:clickhouse-jdbc 0.3.2-patch11 (revision: 27f8951)]
	at com.clickhouse.jdbc.internal.AbstractPreparedStatement.executeUpdate(AbstractPreparedStatement.java:135) ~[clickhouse-jdbc-0.3.2-patch11.jar:clickhouse-jdbc 0.3.2-patch11 (revision: 27f8951)]

TheHett avatar Sep 19 '22 16:09 TheHett

Hi @TheHett, yes it's too restrict. Will fix it later today.

zhicwu avatar Sep 19 '22 22:09 zhicwu

Hi, will this fix be released with a 0.3.2-patch version?

mkeckmkeck avatar Oct 18 '22 09:10 mkeckmkeck

Hi, will this fix be released with a 0.3.2-patch version?

Hi @mkeckmkeck, could you use nightly build for now? As legacy driver being removed in develop branch , the next release will be 0.3.3.

zhicwu avatar Oct 18 '22 09:10 zhicwu

Fixed in v0.4 and above.

zhicwu avatar Mar 16 '23 11:03 zhicwu