JDBC batch insert with FixedString

477 views
Skip to first unread message

Félix

unread,
Apr 6, 2017, 12:00:54 PM4/6/17
to ClickHouse
Hi,

I'm trying to write to a FixedString column in Java with the JDBC driver in batch mode.
But I'm getting the error:

ru.yandex.clickhouse.except.ClickHouseException: ClickHouse exception, code: 131, host: localhost, port: 8123; [}*����󌪬cBijGCode: 131, e.displayText() = DB::Exception: Too large value for FixedString(16), e.wha?Ption

I tried:
  • transforming the UUID into an 16 bytes array and passing it like that,
  • encoding the bytes array as an hex string eg. "\x15\xD2\x9B\x1C\x1B\x62\x40\x4F\xB4\x53\xDD\x36\x38\x94\x48\x42"
  • passing the UUID as with a function "UUIDStringToNum('dff24ad6-1adb-11e7-93ae-92361f002671')"

I double checked and the size of the byte array is always 16. 

The table look like
CREATE TABLE fixedstring_test
(
    event_date
Date,
    event_id
FixedString(16)
) ENGINE = MergeTree(event_date, event_id, 8192)

Did I miss something?

Vitaliy Lyudvichenko

unread,
Apr 7, 2017, 9:15:58 AM4/7/17
to ClickHouse
Hi

Most likely the problem is not related with JDBC driver.
Could you provide your full inset query?

I cannot reproduce the problem. The following queries work for me:
insert into fixedstring_test (event_id) VALUES ('\x15\xD2\x9B\x1C\x1B\x62\x40\x4F\xB4\x53\xDD\x36\x38\x94\x48\x42'), (UUIDStringToNum('dff24ad6-1adb-11e7-93ae-92361f002671'))


insert into fixedstring_test (event_id) FORMAT TSV \x15\xD2\x9B\x1C\x1B\x62\x40\x4F\xB4\x53\xDD\x36\x38\x94\x48\x42

select UUIDNumToString(event_id) FROM fixedstring_test FORMAT TSV


15d29b1c-1b62-404f-b453-dd3638944842
15d29b1c-1b62-404f-b453-dd3638944842
dff24ad6
-1adb-11e7-93ae-92361f002671



четверг, 6 апреля 2017 г., 19:00:54 UTC+3 пользователь Félix написал:

Félix

unread,
Apr 7, 2017, 11:12:41 AM4/7/17
to ClickHouse
ok my bad I was involuntarily escaping twice the data.

In essence I was doing:

UUID uuid = UUID.fromString(event.getId());
byte[] bts = ByteBuffer.allocate(16)
       
.putLong(uuid.getMostSignificantBits())
       
.putLong(uuid.getLeastSignificantBits())
       
.array();
String hex = "\\x" + BaseEncoding.base16().withSeparator("\\x", 2).encode(bts);

query
.setDate(1, DateTimeUtils.protoTimestampToSqlDate(event.getTimestamp()));
query
.setString(2, hex); // bad the data are escaped by the jdbc driver
query
.setBytes(2, hex.getBytes()); // good


Reply all
Reply to author
Forward
0 new messages