Skip to content

Commit 496f04b

Browse files
Add support for integer limits in map type (#178)
1 parent 41edbf7 commit 496f04b

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

lib/active_record/connection_adapters/clickhouse/oid/map.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ module OID # :nodoc:
77
class Map < Type::Value # :nodoc:
88

99
def initialize(sql_type)
10-
@subtype = case sql_type
11-
when /U?Int\d+/
12-
:integer
13-
when /DateTime/
14-
:datetime
15-
when /Date/
16-
:date
17-
else
18-
:string
10+
case sql_type
11+
when /U?Int(\d+)/
12+
@subtype = :integer
13+
@limit = bits_to_limit(Regexp.last_match(1)&.to_i)
14+
when /DateTime/
15+
@subtype = :datetime
16+
when /Date/
17+
@subtype = :date
18+
else
19+
@subtype = :string
1920
end
2021
end
2122

@@ -65,6 +66,19 @@ def serialize(value)
6566
end
6667
end
6768

69+
private
70+
71+
def bits_to_limit(bits)
72+
case bits
73+
when 8 then 1
74+
when 16 then 2
75+
when 32 then 4
76+
when 64 then 8
77+
when 128 then 16
78+
when 256 then 32
79+
end
80+
end
81+
6882
end
6983
end
7084
end

lib/active_record/connection_adapters/clickhouse/table_definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def column(name, type, index: nil, **options)
102102
private
103103

104104
def valid_column_definition_options
105-
super + [:array, :low_cardinality, :fixed_string, :value, :type, :map, :codec]
105+
super + [:array, :low_cardinality, :fixed_string, :value, :type, :map, :codec, :unsigned]
106106
end
107107
end
108108

lib/active_record/connection_adapters/clickhouse_adapter.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ def extract_limit(sql_type) # :nodoc:
191191
nil
192192
when /(Nullable)?\(?U?Int64\)?/
193193
8
194+
when /(Nullable)?\(?U?Int128\)?/
195+
16
194196
else
195197
super
196198
end

0 commit comments

Comments
 (0)