vertica 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +6 -3
- data/README.md +5 -6
- data/VERSION +1 -1
- data/lib/vertica/error.rb +6 -5
- data/lib/vertica/query.rb +33 -34
- data/test/functional/connection_test.rb +1 -1
- data/test/test_helper.rb +11 -1
- metadata +38 -63
data/Gemfile.lock
CHANGED
@@ -2,14 +2,17 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
git (1.2.5)
|
5
|
-
jeweler (1.
|
5
|
+
jeweler (1.8.3)
|
6
6
|
bundler (~> 1.0)
|
7
7
|
git (>= 1.2.5)
|
8
8
|
rake
|
9
|
-
|
9
|
+
rdoc
|
10
|
+
json (1.7.3)
|
11
|
+
rake (0.9.2.2)
|
12
|
+
rdoc (3.12)
|
13
|
+
json (~> 1.4)
|
10
14
|
|
11
15
|
PLATFORMS
|
12
|
-
java
|
13
16
|
ruby
|
14
17
|
|
15
18
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# Vertica
|
2
2
|
|
3
3
|
Vertica is a pure Ruby library for connecting to Vertica databases. You can learn more
|
4
|
-
about Vertica at http://www.vertica.com.
|
4
|
+
about Vertica at http://www.vertica.com.
|
5
5
|
|
6
|
-
This library currently supports
|
7
|
-
|
8
|
-
Ruby 1.8 and
|
6
|
+
This library currently supports connecting, executing SQL queries, and transferring data
|
7
|
+
for a "COPY table FROM STDIN" statement. The gem is tested against Vertica version 4.1,
|
8
|
+
5.0, and 5.1, and Ruby version 1.8 and 1.9.
|
9
9
|
|
10
10
|
# Install
|
11
11
|
|
@@ -101,8 +101,7 @@ prefixed with <tt>test_ruby_vertica_</tt>.
|
|
101
101
|
|
102
102
|
### TODO
|
103
103
|
|
104
|
-
*
|
105
|
-
* More tests
|
104
|
+
* Asynchronous / EventMachine version
|
106
105
|
|
107
106
|
## Authors
|
108
107
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.2
|
data/lib/vertica/error.rb
CHANGED
@@ -26,10 +26,11 @@ class Vertica::Error < StandardError
|
|
26
26
|
end
|
27
27
|
|
28
28
|
QUERY_ERROR_CLASSES = {
|
29
|
-
'55V03' => (LockFailure
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
33
|
-
'
|
29
|
+
'55V03' => (LockFailure = Class.new(Vertica::Error::QueryError)),
|
30
|
+
'53000' => (InsufficientResources = Class.new(Vertica::Error::QueryError)),
|
31
|
+
'53200' => (OutOfMemory = Class.new(Vertica::Error::QueryError)),
|
32
|
+
'42601' => (SyntaxError = Class.new(Vertica::Error::QueryError)),
|
33
|
+
'42V01' => (MissingRelation = Class.new(Vertica::Error::QueryError)),
|
34
|
+
'42703' => (MissingColumn = Class.new(Vertica::Error::QueryError))
|
34
35
|
}
|
35
36
|
end
|
data/lib/vertica/query.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
class Vertica::Query
|
2
2
|
|
3
|
-
attr_reader :connection, :sql
|
3
|
+
attr_reader :connection, :sql, :result, :error
|
4
4
|
attr_accessor :row_handler, :copy_handler, :row_style
|
5
5
|
|
6
6
|
def initialize(connection, sql, options = {})
|
@@ -9,27 +9,19 @@ class Vertica::Query
|
|
9
9
|
@row_style = options[:row_style] || @connection.row_style || :hash
|
10
10
|
@row_handler = options[:row_handler]
|
11
11
|
@copy_handler = options[:copy_handler]
|
12
|
+
|
13
|
+
@error = nil
|
14
|
+
@result = Vertica::Result.new(row_style)
|
12
15
|
end
|
13
16
|
|
14
17
|
|
15
18
|
def run
|
16
|
-
@connection.write Vertica::Messages::Query.new(
|
17
|
-
|
19
|
+
@connection.write Vertica::Messages::Query.new(sql)
|
20
|
+
|
18
21
|
begin
|
19
|
-
|
20
|
-
when Vertica::Messages::ErrorResponse
|
21
|
-
error = Vertica::Error::QueryError.from_error_response(message, @sql)
|
22
|
-
when Vertica::Messages::EmptyQueryResponse
|
23
|
-
error = Vertica::Error::EmptyQueryError.new("A SQL string was expected, but the given string was blank or only contained SQL comments.")
|
24
|
-
when Vertica::Messages::CopyInResponse
|
25
|
-
handle_copy_from_stdin
|
26
|
-
when Vertica::Messages::RowDescription, Vertica::Messages::CommandComplete
|
27
|
-
result = retreive_result(message, Vertica::Result.new(row_style))
|
28
|
-
else
|
29
|
-
@connection.process_message(message)
|
30
|
-
end
|
22
|
+
process_message(message = @connection.read_message)
|
31
23
|
end until message.kind_of?(Vertica::Messages::ReadyForQuery)
|
32
|
-
|
24
|
+
|
33
25
|
raise error unless error.nil?
|
34
26
|
return result
|
35
27
|
end
|
@@ -43,6 +35,25 @@ class Vertica::Query
|
|
43
35
|
|
44
36
|
protected
|
45
37
|
|
38
|
+
def process_message(message)
|
39
|
+
case message
|
40
|
+
when Vertica::Messages::ErrorResponse
|
41
|
+
@error = Vertica::Error::QueryError.from_error_response(message, @sql)
|
42
|
+
when Vertica::Messages::EmptyQueryResponse
|
43
|
+
@error = Vertica::Error::EmptyQueryError.new("A SQL string was expected, but the given string was blank or only contained SQL comments.")
|
44
|
+
when Vertica::Messages::CopyInResponse
|
45
|
+
handle_copy_from_stdin
|
46
|
+
when Vertica::Messages::RowDescription
|
47
|
+
result.descriptions = message
|
48
|
+
when Vertica::Messages::DataRow
|
49
|
+
handle_datarow(message)
|
50
|
+
when Vertica::Messages::CommandComplete
|
51
|
+
result.tag = message.tag
|
52
|
+
else
|
53
|
+
@connection.process_message(message)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
46
57
|
def handle_copy_from_stdin
|
47
58
|
if copy_handler.nil?
|
48
59
|
@connection.write Vertica::Messages::CopyFail.new('no handler provided')
|
@@ -59,26 +70,14 @@ class Vertica::Query
|
|
59
70
|
end
|
60
71
|
end
|
61
72
|
end
|
62
|
-
|
63
|
-
def
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
result.descriptions = message
|
68
|
-
when Vertica::Messages::DataRow
|
69
|
-
record = result.format_row(message)
|
70
|
-
result.add_row(record) if buffer_rows?
|
71
|
-
@row_handler.call(record) if @row_handler
|
72
|
-
else
|
73
|
-
@connection.process_message(message)
|
74
|
-
end
|
75
|
-
message = @connection.read_message
|
76
|
-
end
|
77
|
-
result.tag = message.tag
|
78
|
-
return result
|
73
|
+
|
74
|
+
def handle_datarow(datarow_message)
|
75
|
+
record = result.format_row(datarow_message)
|
76
|
+
result.add_row(record) if buffer_rows?
|
77
|
+
row_handler.call(record) if row_handler
|
79
78
|
end
|
80
79
|
|
81
80
|
def buffer_rows?
|
82
|
-
|
81
|
+
row_handler.nil? && copy_handler.nil?
|
83
82
|
end
|
84
83
|
end
|
@@ -64,7 +64,7 @@ class ConnectionTest < Test::Unit::TestCase
|
|
64
64
|
|
65
65
|
def test_interrupt_connection
|
66
66
|
@connection = Vertica::Connection.new(TEST_CONNECTION_HASH.merge(:interruptable => true))
|
67
|
-
assert @connection.interruptable
|
67
|
+
assert @connection.interruptable?, "The connection should be interruptable!"
|
68
68
|
end
|
69
69
|
|
70
70
|
def test_new_with_error_response
|
data/test/test_helper.rb
CHANGED
@@ -6,4 +6,14 @@ require 'test/unit'
|
|
6
6
|
|
7
7
|
require 'vertica'
|
8
8
|
|
9
|
-
|
9
|
+
TEST_CONNECTION_FILENAME = File.expand_path("../connection.yml", __FILE__)
|
10
|
+
|
11
|
+
if File.exist?(TEST_CONNECTION_FILENAME)
|
12
|
+
TEST_CONNECTION_HASH = YAML.load(File.read(TEST_CONNECTION_FILENAME))
|
13
|
+
else
|
14
|
+
puts
|
15
|
+
puts "Create #{TEST_CONNECTION_FILENAME} with connection info "
|
16
|
+
puts "for your Vertica test database in order to run the test suite."
|
17
|
+
puts
|
18
|
+
exit(1)
|
19
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: vertica
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 9
|
9
|
-
- 1
|
10
|
-
version: 0.9.1
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Jeff Smick
|
14
9
|
- Matt Bauer
|
15
10
|
- Willem van Bergen
|
16
11
|
autorequire:
|
17
12
|
bindir: bin
|
18
13
|
cert_chain: []
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
dependencies:
|
23
|
-
- !ruby/object:Gem::Dependency
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ">="
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
14
|
+
date: 2012-08-02 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
33
17
|
name: rake
|
18
|
+
requirement: &70251107449460 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
34
24
|
type: :runtime
|
35
25
|
prerelease: false
|
36
|
-
version_requirements: *
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
|
-
requirements:
|
41
|
-
- - ">="
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
hash: 3
|
44
|
-
segments:
|
45
|
-
- 0
|
46
|
-
version: "0"
|
26
|
+
version_requirements: *70251107449460
|
27
|
+
- !ruby/object:Gem::Dependency
|
47
28
|
name: jeweler
|
29
|
+
requirement: &70251107448680 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
48
35
|
type: :runtime
|
49
36
|
prerelease: false
|
50
|
-
version_requirements: *
|
37
|
+
version_requirements: *70251107448680
|
51
38
|
description: Query Vertica with ruby
|
52
39
|
email: sprsquish@gmail.com
|
53
40
|
executables: []
|
54
|
-
|
55
41
|
extensions: []
|
56
|
-
|
57
|
-
extra_rdoc_files:
|
42
|
+
extra_rdoc_files:
|
58
43
|
- LICENSE
|
59
44
|
- README.md
|
60
|
-
files:
|
45
|
+
files:
|
61
46
|
- Gemfile
|
62
47
|
- Gemfile.lock
|
63
48
|
- LICENSE
|
@@ -112,41 +97,31 @@ files:
|
|
112
97
|
- test/unit/backend_message_test.rb
|
113
98
|
- test/unit/frontend_message_test.rb
|
114
99
|
- test/unit/quoting_test.rb
|
115
|
-
has_rdoc: true
|
116
100
|
homepage: http://github.com/sprsquish/vertica
|
117
101
|
licenses: []
|
118
|
-
|
119
102
|
post_install_message:
|
120
103
|
rdoc_options: []
|
121
|
-
|
122
|
-
require_paths:
|
104
|
+
require_paths:
|
123
105
|
- lib
|
124
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
107
|
none: false
|
126
|
-
requirements:
|
127
|
-
- -
|
128
|
-
- !ruby/object:Gem::Version
|
129
|
-
|
130
|
-
|
131
|
-
- 0
|
132
|
-
version: "0"
|
133
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ! '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
113
|
none: false
|
135
|
-
requirements:
|
136
|
-
- -
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
|
139
|
-
segments:
|
140
|
-
- 0
|
141
|
-
version: "0"
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
142
118
|
requirements: []
|
143
|
-
|
144
119
|
rubyforge_project:
|
145
|
-
rubygems_version: 1.
|
120
|
+
rubygems_version: 1.8.16
|
146
121
|
signing_key:
|
147
122
|
specification_version: 3
|
148
123
|
summary: Pure ruby library for interacting with Vertica
|
149
|
-
test_files:
|
124
|
+
test_files:
|
150
125
|
- test/functional/connection_test.rb
|
151
126
|
- test/functional/query_test.rb
|
152
127
|
- test/functional/value_conversion_test.rb
|