vertica 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.9.4
1
+ 0.9.5
@@ -2,9 +2,9 @@ require 'socket'
2
2
 
3
3
  class Vertica::Connection
4
4
 
5
- attr_reader :options, :notices, :transaction_status, :backend_pid, :backend_key, :parameters, :notice_handler, :session_id
5
+ attr_reader :notices, :transaction_status, :backend_pid, :backend_key, :parameters, :notice_handler, :session_id
6
6
 
7
- attr_accessor :row_style, :debug
7
+ attr_accessor :row_style, :debug, :options
8
8
 
9
9
  def self.cancel(existing_conn)
10
10
  existing_conn.cancel
@@ -16,8 +16,11 @@ class Vertica::Connection
16
16
  reset_values
17
17
 
18
18
  @options = {}
19
- options.each { |key, value| @options[key.to_s.to_sym] = value }
19
+
20
+ options.each { |key, value| @options[key.to_s.to_sym] = value if value}
21
+
20
22
  @options[:port] ||= 5433
23
+ @options[:read_timeout] ||= 30
21
24
 
22
25
  @row_style = @options[:row_style] ? @options[:row_style] : :hash
23
26
  unless options[:skip_startup]
@@ -66,7 +69,7 @@ class Vertica::Connection
66
69
  end
67
70
 
68
71
  def ready_for_query?
69
- @ready_for_query == true
72
+ @current_job.nil?
70
73
  end
71
74
 
72
75
  def write(message)
@@ -111,12 +114,17 @@ class Vertica::Connection
111
114
  end
112
115
 
113
116
  def read_message
114
- type = read_bytes(1)
115
- size = read_bytes(4).unpack('N').first
116
- raise Vertica::Error::MessageError.new("Bad message size: #{size}.") unless size >= 4
117
- message = Vertica::Messages::BackendMessage.factory type, read_bytes(size - 4)
118
- puts "<= #{message.inspect}" if @debug
119
- return message
117
+ ready = IO.select([socket], nil, nil, @options[:read_timeout])
118
+ if ready
119
+ type = read_bytes(1)
120
+ size = read_bytes(4).unpack('N').first
121
+ raise Vertica::Error::MessageError.new("Bad message size: #{size}.") unless size >= 4
122
+ message = Vertica::Messages::BackendMessage.factory type, read_bytes(size - 4)
123
+ puts "<= #{message.inspect}" if @debug
124
+ return message
125
+ else
126
+ raise Errno::ETIMEDOUT
127
+ end
120
128
  end
121
129
 
122
130
  def process_message(message)
@@ -132,38 +140,28 @@ class Vertica::Connection
132
140
  @parameters[message.name] = message.value
133
141
  when Vertica::Messages::ReadyForQuery
134
142
  @transaction_status = message.transaction_status
135
- @ready_for_query = true
143
+ @current_job = nil
136
144
  else
137
145
  raise Vertica::Error::MessageError, "Unhandled message: #{message.inspect}"
138
146
  end
139
147
  end
140
148
 
141
- def with_lock(&block)
142
- raise Vertica::Error::SynchronizeError, "The connection is in use!" if busy?
143
- @ready_for_query = false
144
- yield
145
- end
146
-
147
149
  def query(sql, options = {}, &block)
148
- with_lock do
149
- job = Vertica::Query.new(self, sql, { :row_style => @row_style }.merge(options))
150
- job.row_handler = block if block_given?
151
- job.run
152
- end
150
+ job = Vertica::Query.new(self, sql, { :row_style => @row_style }.merge(options))
151
+ job.row_handler = block if block_given?
152
+ run_with_job_lock(job)
153
153
  end
154
154
 
155
155
  def copy(sql, source = nil, &block)
156
- with_lock do
157
- job = Vertica::Query.new(self, sql, :row_style => @row_style)
158
- if block_given?
159
- job.copy_handler = block
160
- elsif source && File.exists?(source.to_s)
161
- job.copy_handler = lambda { |data| file_copy_handler(source, data) }
162
- elsif source.respond_to?(:read) && source.respond_to?(:eof?)
163
- job.copy_handler = lambda { |data| io_copy_handler(source, data) }
164
- end
165
- job.run
156
+ job = Vertica::Query.new(self, sql, :row_style => @row_style)
157
+ if block_given?
158
+ job.copy_handler = block
159
+ elsif source && File.exists?(source.to_s)
160
+ job.copy_handler = lambda { |data| file_copy_handler(source, data) }
161
+ elsif source.respond_to?(:read) && source.respond_to?(:eof?)
162
+ job.copy_handler = lambda { |data| io_copy_handler(source, data) }
166
163
  end
164
+ run_with_job_lock(job)
167
165
  end
168
166
 
169
167
  def inspect
@@ -173,6 +171,12 @@ class Vertica::Connection
173
171
 
174
172
  protected
175
173
 
174
+ def run_with_job_lock(job)
175
+ raise Vertica::Error::SynchronizeError.new(@current_job, job) if busy?
176
+ @current_job = job
177
+ job.run
178
+ end
179
+
176
180
  COPY_FROM_IO_BLOCK_SIZE = 1024 * 4096
177
181
 
178
182
  def file_copy_handler(input_file, output)
@@ -223,7 +227,7 @@ class Vertica::Connection
223
227
  @backend_key = nil
224
228
  @transaction_status = nil
225
229
  @socket = nil
226
- @ready_for_query = false
230
+ @current_job = '<initialization>'
227
231
  end
228
232
  end
229
233
 
data/lib/vertica/error.rb CHANGED
@@ -5,9 +5,17 @@ class Vertica::Error < StandardError
5
5
  class SSLNotSupported < ConnectionError; end
6
6
  class InterruptImpossible < Vertica::Error; end
7
7
  class MessageError < Vertica::Error; end
8
- class SynchronizeError < Vertica::Error; end
9
8
  class EmptyQueryError < Vertica::Error; end
10
9
 
10
+ class SynchronizeError < Vertica::Error
11
+ attr_reader :running_job, :requested_job
12
+
13
+ def initialize(running_job, requested_job)
14
+ @running_job, @requested_job = running_job, requested_job
15
+ super("Cannot execute #{running_job}, connection is in use for #{requested_job}!")
16
+ end
17
+ end
18
+
11
19
  class QueryError < Vertica::Error
12
20
 
13
21
  attr_reader :error_response, :sql
data/lib/vertica/query.rb CHANGED
@@ -13,8 +13,7 @@ class Vertica::Query
13
13
  @error = nil
14
14
  @result = Vertica::Result.new(row_style)
15
15
  end
16
-
17
-
16
+
18
17
  def run
19
18
  @connection.write Vertica::Messages::Query.new(sql)
20
19
 
@@ -32,6 +31,10 @@ class Vertica::Query
32
31
  end
33
32
 
34
33
  alias_method :<<, :write
34
+
35
+ def to_s
36
+ @sql
37
+ end
35
38
 
36
39
  protected
37
40
 
@@ -109,6 +109,13 @@ class QueryTest < Test::Unit::TestCase
109
109
  end
110
110
  end
111
111
 
112
+ def test_read_timeout
113
+ assert_raises(Errno::ETIMEDOUT) do
114
+ @connection.options[:read_timeout] = 0.0001
115
+ @connection.query("SELECT * FROM test_ruby_vertica_table")
116
+ end
117
+ end
118
+
112
119
  def test_sql_error
113
120
  assert_raises Vertica::Error::MissingColumn do
114
121
  @connection.query("SELECT asad FROM test_ruby_vertica_table")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vertica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-01-15 00:00:00.000000000 Z
14
+ date: 2013-03-25 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rake
18
- requirement: &70135370266420 !ruby/object:Gem::Requirement
18
+ requirement: &70173422199940 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ! '>='
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70135370266420
26
+ version_requirements: *70173422199940
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: jeweler
29
- requirement: &70135370265940 !ruby/object:Gem::Requirement
29
+ requirement: &70173422199440 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,7 +34,7 @@ dependencies:
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70135370265940
37
+ version_requirements: *70173422199440
38
38
  description: Query Vertica with ruby
39
39
  email: sprsquish@gmail.com
40
40
  executables: []