diff --git a/lib/active_record/connection_adapters/clickhouse/oid/map.rb b/lib/active_record/connection_adapters/clickhouse/oid/map.rb index 9ae49449..89e420c8 100644 --- a/lib/active_record/connection_adapters/clickhouse/oid/map.rb +++ b/lib/active_record/connection_adapters/clickhouse/oid/map.rb @@ -7,15 +7,16 @@ module OID # :nodoc: class Map < Type::Value # :nodoc: def initialize(sql_type) - @subtype = case sql_type - when /U?Int\d+/ - :integer - when /DateTime/ - :datetime - when /Date/ - :date - else - :string + case sql_type + when /U?Int(\d+)/ + @subtype = :integer + @limit = bits_to_limit(Regexp.last_match(1)&.to_i) + when /DateTime/ + @subtype = :datetime + when /Date/ + @subtype = :date + else + @subtype = :string end end @@ -65,6 +66,19 @@ def serialize(value) end end + private + + def bits_to_limit(bits) + case bits + when 8 then 1 + when 16 then 2 + when 32 then 4 + when 64 then 8 + when 128 then 16 + when 256 then 32 + end + end + end end end diff --git a/lib/active_record/connection_adapters/clickhouse/table_definition.rb b/lib/active_record/connection_adapters/clickhouse/table_definition.rb index a9000cc3..e65f8fd5 100644 --- a/lib/active_record/connection_adapters/clickhouse/table_definition.rb +++ b/lib/active_record/connection_adapters/clickhouse/table_definition.rb @@ -102,7 +102,7 @@ def column(name, type, index: nil, **options) private def valid_column_definition_options - super + [:array, :low_cardinality, :fixed_string, :value, :type, :map, :codec] + super + [:array, :low_cardinality, :fixed_string, :value, :type, :map, :codec, :unsigned] end end diff --git a/lib/active_record/connection_adapters/clickhouse_adapter.rb b/lib/active_record/connection_adapters/clickhouse_adapter.rb index f1a07502..fb739933 100644 --- a/lib/active_record/connection_adapters/clickhouse_adapter.rb +++ b/lib/active_record/connection_adapters/clickhouse_adapter.rb @@ -191,6 +191,8 @@ def extract_limit(sql_type) # :nodoc: nil when /(Nullable)?\(?U?Int64\)?/ 8 + when /(Nullable)?\(?U?Int128\)?/ + 16 else super end