Skip to content

Commit

Permalink
handle decimal values correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmarc committed Sep 4, 2014
1 parent 177c9a4 commit 10cc573
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/impala/cursor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def convert_raw_value(value, schema)
end
when 'tinyint', 'smallint', 'int', 'bigint'
value.to_i
when 'double', 'float'
when 'double', 'float', 'decimal'
value.to_f
when "timestamp"
Time.parse(value)
Expand Down
7 changes: 6 additions & 1 deletion test/test_impala_connected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def connect
end

it 'can handle double values' do
ret = @connection.query('SELECT 1.23 AS foo')
ret = @connection.query('SELECT CAST(1.23 AS double) AS foo')
assert_equal([{:foo=>1.23}], ret, "the result should be a float")
end

Expand All @@ -69,6 +69,11 @@ def connect
assert_instance_of(Float, ret.first[:foo], "the result should be a float")
end

it 'can handle decimal values' do
ret = @connection.query('SELECT CAST(1.5 AS decimal(9,4)) as foo')
assert_instance_of(Float, ret.first[:foo], "the result should be a float")
end

it 'can handle timestamp values' do
ret = @connection.query('SELECT NOW() AS foo')
assert_instance_of(Time, ret.first[:foo], "the result should be a timestamp")
Expand Down

0 comments on commit 10cc573

Please sign in to comment.