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

Cannot read bytes from String or FixedString(N)

Open c0mm4nd opened this issue 8 months ago • 4 comments

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

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
                                    function stringToBytes(str) {
                                      const bytes = [];
                                      for (let i = 0; i < str.length; i++) {
                                        const codeUnit = str.charCodeAt(i);
                                        bytes.push(codeUnit);
                                      }
                                      return bytes;
                                    }
  1. 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 if necessary

c0mm4nd avatar Jun 10 '24 10:06 c0mm4nd