-
Notifications
You must be signed in to change notification settings - Fork 602
Closed
Labels
area:data-typedata type processing issuesdata type processing issuesbugclient-api-v2jdbc-v2jdbc-v2 issuesjdbc-v2 issues
Description
Hi,
It looks to me that it is not possible to use the JDBC driver to insert data into Array(FixedString(N)) column.
The code looks like this:
ArrayBuilder builder = new ArrayBuilder(needQuote(values));
for (Object value : values) {
builder.append(value);
}
And needQuote will always return true.
Here's full example including notes from this post.
import java.nio.ByteBuffer
import java.sql.Types
import java.util.UUID
import com.google.common.io.BaseEncoding
import ru.yandex.clickhouse.ClickHouseArray
import ru.yandex.clickhouse.util.ClickHouseArrayUtil
import ru.yandex.clickhouse.util.guava.StreamUtils
def toBytes(uuid: UUID): Array[Byte] = {
val bts = ByteBuffer.
allocate(16).
putLong(uuid.getMostSignificantBits).
putLong(uuid.getLeastSignificantBits).
array
val hex = "\\x" + BaseEncoding.base16.withSeparator("\\x", 2).encode(bts)
hex.getBytes
}
val u1 = UUID.randomUUID()
val u2 = UUID.randomUUID()
val arr1 = List(u1, u2).map(toBytes).toArray
val arr2 = List(u1, u2).map(toBytes).map(new String(_, StreamUtils.UTF_8)).toArray
ClickHouseArrayUtil.arrayToString(new ClickHouseArray(Types.BINARY, arr1).getArray)
ClickHouseArrayUtil.arrayToString(new ClickHouseArray(Types.BINARY, arr2).getArray)
ClickHouseArrayUtil.arrayToString(arr2)
And the output:
toBytes: (uuid: java.util.UUID)Array[Byte]
u1: java.util.UUID = efbca4dd-cb17-48d8-92e3-26655d029a9a
u2: java.util.UUID = a776fc26-bf69-4dcb-b9f5-fef6e16836c3
arr1: Array[Array[Byte]] = Array(Array(92, 120, 69, 70, 92, 120, 66, 67, 92, 120, 65, 52, 92, 120, 68, 68, 92, 120, 67, 66, 92, 120, 49, 55, 92, 120, 52, 56, 92, 120, 68, 56, 92, 120, 57, 50, 92, 120, 69, 51, 92, 120, 50, 54, 92, 120, 54, 53, 92, 120, 53, 68, 92, 120, 48, 50, 92, 120, 57, 65, 92, 120, 57, 65), Array(92, 120, 65, 55, 92, 120, 55, 54, 92, 120, 70, 67, 92, 120, 50, 54, 92, 120, 66, 70, 92, 120, 54, 57, 92, 120, 52, 68, 92, 120, 67, 66, 92, 120, 66, 57, 92, 120, 70, 53, 92, 120, 70, 69, 92, 120, 70, 54, 92, 120, 69, 49, 92, 120, 54, 56, 92, 120, 51, 54, 92, 120, 67, 51))
arr2: Array[String] = Array(\xEF\xBC\xA4\xDD\xCB\x17\x48\xD8\x92\xE3\x26\x65\x5D\x02\x9A\x9A, \xA7\x76\xFC\x26\xBF\x69\x4D\xCB\xB9\xF5\xFE\xF6\xE1\x68\x36\xC3)
res0: String = [[92,120,69,70,92,120,66,67,92,120,65,52,92,120,68,68,92,120,67,66,92,120,49,55,92,120,52,56,92,120,68,56,92,120,57,50,92,120,69,51,92,120,50,54,92,120,54,53,92,120,53,68,92,120,48,50,92,120,57,65,92,120,57,65],[92,120,65,55,92,120,55,54,92,120,70,67,92,120,50,54,92,120,66,70,92,120,54,57,92,120,52,68,92,120,67,66,92,120,66,57,92,120,70,53,92,120,70,69,92,120,70,54,92,120,69,49,92,120,54,56,92,120,51,54,92,120,67,51]]
res1: String = ['\\xEF\\xBC\\xA4\\xDD\\xCB\\x17\\x48\\xD8\\x92\\xE3\\x26\\x65\\x5D\\x02\\x9A\\x9A','\\xA7\\x76\\xFC\\x26\\xBF\\x69\\x4D\\xCB\\xB9\\xF5\\xFE\\xF6\\xE1\\x68\\x36\\xC3']
res2: String = ['\\xEF\\xBC\\xA4\\xDD\\xCB\\x17\\x48\\xD8\\x92\\xE3\\x26\\x65\\x5D\\x02\\x9A\\x9A','\\xA7\\x76\\xFC\\x26\\xBF\\x69\\x4D\\xCB\\xB9\\xF5\\xFE\\xF6\\xE1\\x68\\x36\\xC3']
while what I need is:
['\xEF\xBC\xA4\xDD\xCB\x17\x48\xD8\x92\xE3\x26\x65\x5D\x02\x9A\x9A','\xA7\x76\xFC\x26\xBF\x69\x4D\xCB\xB9\xF5\xFE\xF6\xE1\x68\x36\xC3']
Metadata
Metadata
Assignees
Labels
area:data-typedata type processing issuesdata type processing issuesbugclient-api-v2jdbc-v2jdbc-v2 issuesjdbc-v2 issues