Class: ActiveRecord::ConnectionAdapters::ClickHouse::RowBinary

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/clickhouse/row_binary.rb

Overview

Decodes RowBinaryWithNamesAndTypes bodies: a varint column count, the names, the type strings, then rows of packed values (probed 2026-07-13, PLAN.md ยง2). Yields the same Ruby values the JSON casters produce, so the cast layer treats both wires identically. Types without a binary decoder raise Undecodable and the connection retries the query on the JSON wire.

Constant Summary collapse

Undecodable =

rubocop:disable Style/EmptyClassDefinition

Class.new(StandardError)
INTEGER_FORMATS =
{
  "Int8" => ["c", 1], "Int16" => ["s<", 2], "Int32" => ["l<", 4], "Int64" => ["q<", 8],
  "UInt8" => ["C", 1], "UInt16" => ["S<", 2], "UInt32" => ["L<", 4], "UInt64" => ["Q<", 8]
}.freeze
DECIMAL_BYTES =

Storage width is decided by precision; the server normalizes every Decimal alias to Decimal(precision, scale) in the type header.

[[9, 4], [18, 8], [38, 16], [76, 32]].freeze
UNIX_EPOCH_JULIAN_DAY =
Date.new(1970, 1, 1).jd

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ RowBinary

Returns a new instance of RowBinary.



33
34
35
36
# File 'lib/active_record/connection_adapters/clickhouse/row_binary.rb', line 33

def initialize(body)
  @body = body
  @position = 0
end

Class Method Details

.decode(body) ⇒ Object



31
# File 'lib/active_record/connection_adapters/clickhouse/row_binary.rb', line 31

def self.decode(body) = new(body).decode

Instance Method Details

#decodeObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/active_record/connection_adapters/clickhouse/row_binary.rb', line 38

def decode
  return [[], [], []] if @body.empty?

  names = Array.new(read_varint) { read_string }
  types = Array.new(names.length) { read_string }
  decoders = types.map { |type| value_decoder(TypeParser.parse(type)) }
  rows = []
  rows << decoders.map(&:call) until end_of_body?
  [names, types, rows]
end