Skip to content

Commit

Permalink
Typo fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Shilov <[email protected]>
  • Loading branch information
shlima committed Nov 20, 2022
1 parent 011540c commit d3f6ff3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 20,7 @@ CREATE TABLE assets(visible Boolean, tags Array(Nullable(String))) ENGINE Memory
@schema = ClickHouse.connection.table_schema('assets')

# Json each row
ClickHouse.connection.insert('assets', @schema.serialize({'visible' => true, 'tags' => ['ruby']))
ClickHouse.connection.insert('assets', @schema.serialize({'visible' => true, 'tags' => ['ruby']}))

# Json compact
ClickHouse.connection.insert('assets', columns: %w[visible tags]) do |buffer|
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 373,7 @@ CREATE TABLE assets(visible Boolean, tags Array(Nullable(String))) ENGINE Memory
@schema = ClickHouse.connection.table_schema('assets')

# Json each row
ClickHouse.connection.insert('assets', @schema.serialize({'visible' => true, 'tags' => ['ruby']))
ClickHouse.connection.insert('assets', @schema.serialize({'visible' => true, 'tags' => ['ruby']}))

# Json compact
ClickHouse.connection.insert('assets', columns: %w[visible tags]) do |buffer|
Expand Down
15 changes: 8 additions & 7 deletions lib/click_house/response/result_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,9 @@ class ResultSet
extend Forwardable
include Enumerable

KEY_META_NAME = 'name'
KEY_META_TYPE = 'type'

def_delegators :to_a,
:inspect, :each, :fetch, :length, :count, :size,
:first, :last, :[], :to_h
Expand Down Expand Up @@ -47,10 50,6 @@ def serialize(data)
def serialize_one(row)
row.each_with_object({}) do |(key, value), object|
object[key] = serialize_column(key, value)
rescue KeyError => e
raise SerializeError, "field <#{key}> does not exists in table schema: #{types.keys.join(', ')}", e.backtrace
rescue StandardError => e
raise SerializeError, "failed to serialize <#{key}> with #{stmt}, #{e.class}, #{e.message}", e.backtrace
end
end

Expand All @@ -60,7 59,9 @@ def serialize_column(name, value)
stmt = types.fetch(name)
serialize_type(stmt, value)
rescue KeyError => e
raise SerializeError, "field <#{name}> does not exists in table schema: #{types.keys.join(', ')}", e.backtrace
raise SerializeError, "field <#{name}> does not exists in table schema: #{types}", e.backtrace
rescue StandardError => e
raise SerializeError, "failed to serialize <#{name}> with #{stmt}, #{e.class}, #{e.message}", e.backtrace
end

def to_a
Expand All @@ -74,11 75,11 @@ def to_a
# @return [Hash<String, Ast::Statement>]
def types
@types ||= meta.each_with_object({}) do |row, object|
column = row.fetch(config.key('name'))
column = row.fetch(config.key(KEY_META_NAME))
# make symbol keys, if config.symbolize_keys is true,
# to be able to cast and serialize properly
object[config.key(column)] = begin
current = Ast::Parser.new(row.fetch(config.key('type'))).parse
current = Ast::Parser.new(row.fetch(config.key(KEY_META_TYPE))).parse
assign_type(current)
current
end
Expand Down
4 changes: 4 additions & 0 deletions spec/click_house/integration/table_schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 32,10 @@
it 'errors if column missing' do
expect { schema.serialize_column('foo', 'bar') }.to raise_error(ClickHouse::SerializeError)
end

it 'errors if value has improper type' do
expect { schema.serialize_column('b', nil) }.to raise_error(ClickHouse::SerializeError)
end
end

describe '#serialize_one' do
Expand Down

0 comments on commit d3f6ff3

Please sign in to comment.