impala 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/impala/connection.rb +1 -4
- data/lib/impala/cursor.rb +7 -5
- data/lib/impala/version.rb +1 -1
- data/test/test_impala.rb +0 -15
- data/test/test_impala_connected.rb +2 -0
- metadata +2 -8
data/lib/impala/connection.rb
CHANGED
@@ -58,10 +58,7 @@ module Impala
|
|
58
58
|
# @option query_options [String] :user the user runs the query
|
59
59
|
# @return [Array<Hash>] an array of hashes, one for each row.
|
60
60
|
def query(raw_query, query_options = {})
|
61
|
-
|
62
|
-
cursor.fetch_all
|
63
|
-
ensure
|
64
|
-
cursor.close
|
61
|
+
execute(raw_query, query_options).fetch_all
|
65
62
|
end
|
66
63
|
|
67
64
|
# Perform a query and return a cursor for iterating over the results.
|
data/lib/impala/cursor.rb
CHANGED
@@ -33,8 +33,6 @@ module Impala
|
|
33
33
|
# left
|
34
34
|
# @see #fetch_all
|
35
35
|
def fetch_row
|
36
|
-
raise CursorError.new("Cursor has expired or been closed") unless @open
|
37
|
-
|
38
36
|
if @row_buffer.empty?
|
39
37
|
if @done
|
40
38
|
return nil
|
@@ -85,18 +83,22 @@ module Impala
|
|
85
83
|
end
|
86
84
|
|
87
85
|
def fetch_batch
|
88
|
-
|
86
|
+
raise CursorError.new("Cursor has expired or been closed") unless @open
|
89
87
|
|
90
88
|
begin
|
91
89
|
res = @service.fetch(@handle, false, BUFFER_SIZE)
|
92
90
|
rescue Protocol::Beeswax::BeeswaxException => e
|
93
|
-
@
|
91
|
+
@open = false
|
94
92
|
raise CursorError.new("Cursor has expired or been closed")
|
95
93
|
end
|
96
94
|
|
97
95
|
rows = res.data.map { |raw| parse_row(raw) }
|
98
96
|
@row_buffer.concat(rows)
|
99
|
-
|
97
|
+
|
98
|
+
unless res.has_more
|
99
|
+
@done = true
|
100
|
+
close
|
101
|
+
end
|
100
102
|
end
|
101
103
|
|
102
104
|
def parse_row(raw)
|
data/lib/impala/version.rb
CHANGED
data/test/test_impala.rb
CHANGED
@@ -99,19 +99,4 @@ describe Impala::Connection do
|
|
99
99
|
@connection.execute('query', opt)
|
100
100
|
end
|
101
101
|
end
|
102
|
-
|
103
|
-
describe '#query' do
|
104
|
-
before do
|
105
|
-
Impala::Cursor.any_instance.stubs(:fetch_more)
|
106
|
-
@cursor = Impala::Cursor.new(nil, nil)
|
107
|
-
Impala::Connection.any_instance.stubs(:open)
|
108
|
-
@connection = Impala::Connection.new('test', 1234)
|
109
|
-
@connection.stubs(:open? => true, :sanitize_query => 'sanitized_query', :check_result => nil, :execute => @cursor)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'should close the cursor after returning a value' do
|
113
|
-
@cursor.expects(:close).once
|
114
|
-
@connection.query('query')
|
115
|
-
end
|
116
|
-
end
|
117
102
|
end
|
@@ -159,6 +159,7 @@ describe 'connected tests' do
|
|
159
159
|
|
160
160
|
assert_equal(false, cursor.has_more?, "has_more? should be false")
|
161
161
|
assert_nil(cursor.fetch_row, "subsequent calls to fetch_row should be nil")
|
162
|
+
assert_equal(false, cursor.open?, "the cursor should be closed once it has returned all the rows")
|
162
163
|
end
|
163
164
|
|
164
165
|
it 'can use a cursor to deal with lots of data' do
|
@@ -184,6 +185,7 @@ describe 'connected tests' do
|
|
184
185
|
|
185
186
|
assert_equal(false, cursor.has_more?, "has_more? should be false")
|
186
187
|
assert_nil(cursor.fetch_row, "subsequent calls to fetch_row should be nil")
|
188
|
+
assert_equal(false, cursor.open?, "the cursor should be closed once it has returned all the rows")
|
187
189
|
end
|
188
190
|
|
189
191
|
it 'can handle interspersed NULL values' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: impala
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thrift
|
@@ -228,18 +228,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
228
228
|
- - ! '>='
|
229
229
|
- !ruby/object:Gem::Version
|
230
230
|
version: '0'
|
231
|
-
segments:
|
232
|
-
- 0
|
233
|
-
hash: -146128838497320562
|
234
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
235
232
|
none: false
|
236
233
|
requirements:
|
237
234
|
- - ! '>='
|
238
235
|
- !ruby/object:Gem::Version
|
239
236
|
version: '0'
|
240
|
-
segments:
|
241
|
-
- 0
|
242
|
-
hash: -146128838497320562
|
243
237
|
requirements: []
|
244
238
|
rubyforge_project:
|
245
239
|
rubygems_version: 1.8.23
|