Skip to content

Commit

Permalink
Add support for integer limits in map type (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielwestendorf authored Nov 18, 2024
1 parent 41edbf7 commit 496f04b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
32 changes: 23 additions & 9 deletions lib/active_record/connection_adapters/clickhouse/oid/map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/active_record/connection_adapters/clickhouse_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def extract_limit(sql_type) # :nodoc:
nil
when /(Nullable)?\(?U?Int64\)?/
8
when /(Nullable)?\(?U?Int128\)?/
16
else
super
end
Expand Down

0 comments on commit 496f04b

Please sign in to comment.