ClickHouse / ClickHouse/clickhouse-js

Cannot read bytes from String or FixedString(N)

Open
#282 5 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
TypeScript
Stars
331
Forks
74
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

Directly select a String or FixedString(N) column which stores raw bytes rather than UTF-8 string, the result will contain

e.g.
![image](https://github.com/ClickHouse/clickhouse-js/assets/12538215/51f19f92-9f21-4636-a5c1-427d5cbd981a)

the correct value of this should be the hash `unhex('000000708550f340a1297eefe721a3b0631d8dc4cc5a3462abaeef1a79726f6b')`

### Steps to reproduce
1. Store raw hash or any other raw bytes in Clickhouse DB
2. Directly select it through clickhouse-js, formatting as any CSV or JSON
3. convert the string to bytes
```javascript
function stringToBytes(str) {
const bytes = [];
for (let i = 0; i < str.length; i++) {
const codeUnit = str.charCodeAt(i);
bytes.push(codeUnit);
}
return bytes;
}
```
4. the value is incorrect and ruined by `65533`

### Expected behaviour

return a correct string or bytes

### Code example

as shown in Steps to reproduce

### Error log

### Configuration
#### Environment
* Client version: latest, 1.1.0
* Language version:
* OS: Chrome

#### ClickHouse server
* ClickHouse Server version: clickhouse/clickhouse-server:23.12.4-alpine
* ClickHouse Server non-default settings, if any:
* `CREATE TABLE` statements for tables involved:
* Sample data for all these tables, use [clickhouse-obfuscator](https://github.com/ClickHouse/ClickHouse/blob/master/programs/obfuscator/Obfuscator.cpp#L42-L80) if necessary

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.