Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for integer limits in map type #178

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading