Module: ClickhouseRuby::Types

Defined in:
lib/clickhouse_ruby/types.rb,
lib/clickhouse_ruby/types/map.rb,
lib/clickhouse_ruby/types/base.rb,
lib/clickhouse_ruby/types/uuid.rb,
lib/clickhouse_ruby/types/array.rb,
lib/clickhouse_ruby/types/float.rb,
lib/clickhouse_ruby/types/tuple.rb,
lib/clickhouse_ruby/types/parser.rb,
lib/clickhouse_ruby/types/string.rb,
lib/clickhouse_ruby/types/boolean.rb,
lib/clickhouse_ruby/types/integer.rb,
lib/clickhouse_ruby/types/nullable.rb,
lib/clickhouse_ruby/types/registry.rb,
lib/clickhouse_ruby/types/date_time.rb,
lib/clickhouse_ruby/types/low_cardinality.rb

Overview

Type system for mapping between ClickHouse and Ruby types

Key features:

  • AST-based type parser (handles nested types correctly)

  • Bidirectional conversion (Ruby ↔ ClickHouse)

  • Proper handling of complex types (Array, Map, Tuple, Nullable)

Examples:

Parse a complex type

parser = ClickhouseRuby::Types::Parser.new
ast = parser.parse('Array(Tuple(String, UInt64))')
# => { type: 'Array', args: [{ type: 'Tuple', args: [...] }] }

Convert values

type = ClickhouseRuby::Types.lookup('UInt64')
type.cast(42)          # => 42
type.serialize(42)     # => "42"
type.deserialize("42") # => 42

Defined Under Namespace

Classes: Array, Base, Boolean, DateTime, Float, Integer, LowCardinality, Map, Nullable, Parser, Registry, String, Tuple, UUID

Class Method Summary collapse

Class Method Details

.lookup(type_string) ⇒ Base

Looks up a type by its ClickHouse type string

Parameters:

  • type_string (String)

    the ClickHouse type (e.g., ‘Array(String)’)

Returns:

  • (Base)

    the type instance



51
52
53
# File 'lib/clickhouse_ruby/types.rb', line 51

def lookup(type_string)
  registry.lookup(type_string)
end

.parse(type_string) ⇒ Hash

Parses a ClickHouse type string into an AST

Parameters:

  • type_string (String)

    the ClickHouse type string

Returns:

  • (Hash)

    the parsed AST



59
60
61
# File 'lib/clickhouse_ruby/types.rb', line 59

def parse(type_string)
  Parser.new.parse(type_string)
end

.registryRegistry

Returns the global type registry

Returns:



43
44
45
# File 'lib/clickhouse_ruby/types.rb', line 43

def registry
  @registry ||= Registry.new.tap(&:register_defaults)
end

.reset!Object

Resets the registry (useful for testing)



64
65
66
# File 'lib/clickhouse_ruby/types.rb', line 64

def reset!
  @registry = nil
end