[client-v2] Reader API that decodes RowBinary values without per-value objects

Đang mở
#3,449 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java
Lĩnh vực
backend, performance

Hướng nghiên cứu

Start by tracing RowBinaryWithNamesAndTypesFormatReader, BinaryStreamReader, and the typed getter path described in the issue. Compare the existing reader behavior with the Spark connector workaround in ClickHouse/spark-clickhouse-connector#588, then identify how a buffered stream and row cursor would fit the current API. Done means callers can decode supported RowBinary types without per-value objects while existing getters retain their behavior; the issue does not name tests to run.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

client data-types enhancement performance

Problem

RowBinaryWithNamesAndTypesFormatReader turns every value into a Java object before the caller sees it:

  • One stream call per value. BinaryStreamReader reads each value from the InputStream separately. For example, readIntLE calls readNBytes(input, buff, 0, 4) and puts the int together with shifts, so there's at least one read call per value, through CompressedBlockInputStream and its wrappers.
  • One object per value. readRecord stores each value in an Object[] (record[i] = val), and the typed getters go through it: getInteger → readNumberValue → readValue(index). That means:
    • Int32 → Integer
    • UInt64 → BigInteger
    • Date → LocalDate
    • DateTime64 → ZonedDateTime
    • String → String, or with binary_string_support a StringValue around a new byte[]

A caller that writes values into its own format, such as Spark's rows, pays for these objects and then converts them back.

Workaround in the Spark connector

ClickHouse/spark-clickhouse-connector#588 reads the RowBinary bytes itself, with its own buffered reader. It only uses client-v2 for the query, the HTTP transport, decompression and parsing the column types. In our benchmark against client-v2 0.9.5 decoding, it used 1.6–5.3× less CPU, depending on the column types. That figure covers buffering and avoiding objects together; we didn't measure them separately.

The cost is that the connector has to copy client-v2's behaviour exactly, and notice when it changes. Moving from 0.9.5 to 0.11.1 changed:

  • The name of the decompressing stream class (ClickHouseLZ4InputStream → CompressedBlockInputStream)
  • The Date conversion
  • The varint length limit
  • The wrapper around the response stream
  • The text of read errors

Proposal

  1. Buffered reads. Read the decompressed stream in large chunks into an internal buffer. Decode fixed-width values from it with a little-endian ByteBuffer view (getInt, getLong), and only call the stream when the buffer is used up. This helps every caller, including the existing object API.

  2. A cursor over the row, without per-value objects. RowBinary has no offsets, so values are read in column order, each exactly once:

    • Primitives: integers and floats as primitives, UInt64 as its raw long bits.
    • Dates and times: Date and Date32 as an epoch-day int, DateTime and DateTime64 as raw seconds or ticks (long), with the scale taken from the column.
    • Strings: String and FixedString as a buffer, offset and length, valid until the next row.
    • Nullable: a null flag before the value, at any depth.
    • Array: the length, then each element with the same accessors.
    • Map: the entry count, then key, value, key, value.
    • Tuple: the fields in order.

    JSON, Variant, Dynamic and the interval types could stay on the object API to start with; the connector sends those to client-v2 today too. The existing getters, which allow random access, could be built on the cursor.

With this, the connector would drop its own reader and its copies of client-v2's behaviour, and only map values into Spark rows.

Ngôn ngữ chính
Java
Star
1.6k
Fork
657
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
36

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ClickHouse/clickhouse-java

Tất cả issue của ClickHouse/clickhouse-java

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.