vertica 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/LICENSE +19 -0
  2. data/README.textile +69 -0
  3. data/Rakefile +44 -0
  4. data/lib/vertica/bit_helper.rb +51 -0
  5. data/lib/vertica/column.rb +68 -0
  6. data/lib/vertica/connection.rb +247 -0
  7. data/lib/vertica/messages/authentication.rb +33 -0
  8. data/lib/vertica/messages/backend_key_data.rb +16 -0
  9. data/lib/vertica/messages/bind.rb +36 -0
  10. data/lib/vertica/messages/bind_complete.rb +8 -0
  11. data/lib/vertica/messages/cancel_request.rb +25 -0
  12. data/lib/vertica/messages/close.rb +30 -0
  13. data/lib/vertica/messages/close_complete.rb +8 -0
  14. data/lib/vertica/messages/command_complete.rb +16 -0
  15. data/lib/vertica/messages/data_row.rb +23 -0
  16. data/lib/vertica/messages/describe.rb +30 -0
  17. data/lib/vertica/messages/empty_query_response.rb +8 -0
  18. data/lib/vertica/messages/error_response.rb +59 -0
  19. data/lib/vertica/messages/execute.rb +24 -0
  20. data/lib/vertica/messages/flush.rb +15 -0
  21. data/lib/vertica/messages/message.rb +85 -0
  22. data/lib/vertica/messages/no_data.rb +8 -0
  23. data/lib/vertica/messages/notice_response.rb +21 -0
  24. data/lib/vertica/messages/notification_response.rb +18 -0
  25. data/lib/vertica/messages/parameter_description.rb +19 -0
  26. data/lib/vertica/messages/parameter_status.rb +17 -0
  27. data/lib/vertica/messages/parse.rb +31 -0
  28. data/lib/vertica/messages/parse_complete.rb +8 -0
  29. data/lib/vertica/messages/password.rb +33 -0
  30. data/lib/vertica/messages/portal_suspended.rb +8 -0
  31. data/lib/vertica/messages/query.rb +20 -0
  32. data/lib/vertica/messages/ready_for_query.rb +14 -0
  33. data/lib/vertica/messages/row_description.rb +29 -0
  34. data/lib/vertica/messages/ssl_request.rb +14 -0
  35. data/lib/vertica/messages/startup.rb +38 -0
  36. data/lib/vertica/messages/sync.rb +15 -0
  37. data/lib/vertica/messages/terminate.rb +14 -0
  38. data/lib/vertica/messages/unknown.rb +11 -0
  39. data/lib/vertica/notice.rb +11 -0
  40. data/lib/vertica/notification.rb +13 -0
  41. data/lib/vertica/result.rb +28 -0
  42. data/lib/vertica/vertica_socket.rb +8 -0
  43. data/lib/vertica.rb +19 -0
  44. data/test/connection_test.rb +191 -0
  45. data/test/create_schema.sql +4 -0
  46. data/test/test_helper.rb +25 -0
  47. data/vertica.gemspec +64 -0
  48. metadata +112 -0
@@ -0,0 +1,191 @@
1
+ require File.join(File.dirname(__FILE__), "test_helper")
2
+
3
+ class ConnectionTest < Test::Unit::TestCase
4
+
5
+ def test_new
6
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
7
+ assert !c.parameters.empty?
8
+ assert c.backend_pid
9
+ assert c.backend_key
10
+ assert c.transaction_status
11
+ assert c.opened?
12
+ assert !c.closed?
13
+ assert_equal({"server_version" => "8.0"}, c.parameters)
14
+ assert_equal([], c.notifications)
15
+ c.close
16
+ assert_equal({}, c.parameters)
17
+ assert_nil c.backend_pid
18
+ assert_nil c.backend_key
19
+ assert_nil c.transaction_status
20
+ end
21
+
22
+ def test_new_with_ssl
23
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH.merge(:ssl => true))
24
+ assert !c.parameters.empty?
25
+ assert c.backend_pid
26
+ assert c.backend_key
27
+ assert c.transaction_status
28
+ c.close
29
+ assert_equal({}, c.parameters)
30
+ assert_nil c.backend_pid
31
+ assert_nil c.backend_key
32
+ assert_nil c.transaction_status
33
+ end
34
+
35
+ def test_reset
36
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
37
+ assert !c.parameters.empty?
38
+ assert c.backend_pid
39
+ assert c.backend_key
40
+ assert c.transaction_status
41
+ c.reset
42
+ assert_equal({}, c.parameters)
43
+ assert_nil c.backend_pid
44
+ assert_nil c.backend_key
45
+ assert_nil c.transaction_status
46
+ c.close
47
+ end
48
+
49
+ def test_new_with_error_response
50
+ assert_raises Vertica::Error::MessageError do
51
+ Vertica::Connection.new(TEST_CONNECTION_HASH.merge(:database => 'nonexistant_db'))
52
+ end
53
+ end
54
+
55
+ def test_select_query_with_results
56
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
57
+ r = c.query("SELECT * FROM test_table")
58
+ assert_equal 1, r.row_count
59
+ assert_equal 2, r.columns.length
60
+ assert_equal :in, r.columns[0].data_type
61
+ assert_equal 'id', r.columns[0].name
62
+ assert_equal :varchar, r.columns[1].data_type
63
+ assert_equal 'name', r.columns[1].name
64
+ assert_equal [[1, 'matt']], r.rows
65
+ c.close
66
+ end
67
+
68
+ def test_select_query_with_no_results
69
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
70
+ r = c.query("SELECT * FROM test_table WHERE 1 != 1")
71
+ assert_equal 0, r.row_count
72
+ assert_equal 2, r.columns.length
73
+ assert_equal :in, r.columns[0].data_type
74
+ assert_equal 'id', r.columns[0].name
75
+ assert_equal :varchar, r.columns[1].data_type
76
+ assert_equal 'name', r.columns[1].name
77
+ assert_equal [], r.rows
78
+ c.close
79
+ end
80
+
81
+ def test_delete_of_no_rows
82
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
83
+ r = c.query("DELETE FROM test_table WHERE 1 != 1")
84
+ assert_equal 1, r.row_count
85
+ assert_equal 1, r.columns.length
86
+ assert_equal :in, r.columns[0].data_type
87
+ assert_equal 'OUTPUT', r.columns[0].name
88
+ assert_equal [[0]], r.rows
89
+ c.close
90
+ end
91
+
92
+ def test_insert
93
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
94
+ r = c.query("INSERT INTO test_table VALUES (2, 'stefanie')")
95
+ assert_equal 1, r.row_count
96
+ assert_equal 1, r.columns.length
97
+ assert_equal :in, r.columns[0].data_type
98
+ assert_equal 'OUTPUT', r.columns[0].name
99
+ assert_equal [[1]], r.rows
100
+ c.close
101
+ end
102
+
103
+ def test_delete_of_a_row
104
+ test_insert
105
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
106
+ r = c.query("DELETE FROM test_table WHERE id = 2")
107
+ assert_equal 1, r.row_count
108
+ assert_equal 1, r.columns.length
109
+ assert_equal :in, r.columns[0].data_type
110
+ assert_equal 'OUTPUT', r.columns[0].name
111
+ assert_equal [[0]], r.rows
112
+ c.close
113
+ end
114
+
115
+ def test_empty_query
116
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
117
+ assert_raises ArgumentError do
118
+ r = c.query("")
119
+ end
120
+ assert_raises ArgumentError do
121
+ r = c.query(nil)
122
+ end
123
+ c.close
124
+ end
125
+
126
+ def test_cancel
127
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
128
+ Vertica::Connection.cancel(c)
129
+ c.close
130
+ end
131
+
132
+ def test_prepared_statement_with_no_params
133
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
134
+ c.prepare("my_ps", "SELECT * FROM test_table")
135
+ r = c.execute_prepared("my_ps")
136
+ assert_equal 1, r.row_count
137
+ assert_equal 2, r.columns.length
138
+ assert_equal :in, r.columns[0].data_type
139
+ assert_equal 'id', r.columns[0].name
140
+ assert_equal :varchar, r.columns[1].data_type
141
+ assert_equal 'name', r.columns[1].name
142
+ assert_equal [[1, 'matt']], r.rows
143
+ c.close
144
+ end
145
+
146
+ def test_prepared_statement_with_one_param
147
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
148
+ c.prepare("my_ps", "SELECT * FROM test_table WHERE id = ?", 1)
149
+ r = c.execute_prepared("my_ps", 1)
150
+ assert_equal 1, r.row_count
151
+ assert_equal 2, r.columns.length
152
+ assert_equal :in, r.columns[0].data_type
153
+ assert_equal 'id', r.columns[0].name
154
+ assert_equal :varchar, r.columns[1].data_type
155
+ assert_equal 'name', r.columns[1].name
156
+ assert_equal [[1, 'matt']], r.rows
157
+ c.close
158
+ end
159
+
160
+ def test_prepared_statement_with_two_params
161
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
162
+ c.prepare("my_ps", "SELECT * FROM test_table WHERE id = ? OR id = ?", 2)
163
+ r = c.execute_prepared("my_ps", 1, 3)
164
+ assert_equal 1, r.row_count
165
+ assert_equal 2, r.columns.length
166
+ assert_equal :in, r.columns[0].data_type
167
+ assert_equal 'id', r.columns[0].name
168
+ assert_equal :varchar, r.columns[1].data_type
169
+ assert_equal 'name', r.columns[1].name
170
+ assert_equal [[1, 'matt']], r.rows
171
+ c.close
172
+ end
173
+
174
+ def test_double_select
175
+ c = Vertica::Connection.new(TEST_CONNECTION_HASH)
176
+ 5.times do
177
+ r = c.query("SELECT * FROM test_table")
178
+ assert_equal 1, r.row_count
179
+ assert_equal 2, r.columns.length
180
+ assert_equal :in, r.columns[0].data_type
181
+ assert_equal 'id', r.columns[0].name
182
+ assert_equal :varchar, r.columns[1].data_type
183
+ assert_equal 'name', r.columns[1].name
184
+ assert_equal [[1, 'matt']], r.rows
185
+ end
186
+ c.close
187
+ end
188
+
189
+ # test parameters
190
+
191
+ end
@@ -0,0 +1,4 @@
1
+ CREATE TABLE test_table (id int, name varchar(100));
2
+ CREATE PROJECTION test_table_p (id, name) AS SELECT * FROM test_table SEGMENTED BY HASH(id) ALL NODES OFFSET 1;
3
+ INSERT INTO test_table VALUES (1, 'matt');
4
+ COMMIT;
@@ -0,0 +1,25 @@
1
+ require "test/unit"
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+ require "vertica"
4
+
5
+ class Test::Unit::TestCase
6
+
7
+ TEST_CONNECTION_USER = 'dbadmin'
8
+ TEST_CONNECTION_PASSWORD = 'cl3v3rcstore'
9
+ TEST_CONNECTION_HOST = 'ec2-174-129-157-242.compute-1.amazonaws.com'
10
+ TEST_CONNECTION_PORT = 5433
11
+ TEST_CONNECTION_DATABASE = 'db'
12
+
13
+ TEST_CONNECTION_HASH = {
14
+ :user => TEST_CONNECTION_USER,
15
+ :password => TEST_CONNECTION_PASSWORD,
16
+ :host => TEST_CONNECTION_HOST,
17
+ :port => TEST_CONNECTION_PORT,
18
+ :database => TEST_CONNECTION_DATABASE
19
+ }
20
+
21
+ end
22
+
23
+ class StringIO
24
+ include Vertica::BitHelper
25
+ end
data/vertica.gemspec ADDED
@@ -0,0 +1,64 @@
1
+ VERTICA_SPEC = Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.required_ruby_version = '>=1.8.4'
4
+ s.name = "vertica"
5
+ s.version = "0.7.4"
6
+ s.author = "Matt Bauer"
7
+ s.email = "bauer@pedalbrain.com"
8
+ s.summary = "A Ruby interface to Vertica"
9
+ s.files = ['vertica.gemspec',
10
+ 'LICENSE',
11
+ 'README.textile',
12
+ 'Rakefile',
13
+ 'lib/vertica.rb',
14
+ 'lib/vertica/notice.rb',
15
+ 'lib/vertica/bit_helper.rb',
16
+ 'lib/vertica/column.rb',
17
+ 'lib/vertica/connection.rb',
18
+ 'lib/vertica/messages/',
19
+ 'lib/vertica/notification.rb',
20
+ 'lib/vertica/result.rb',
21
+ 'lib/vertica/vertica_socket.rb',
22
+ 'lib/vertica/messages/authentication.rb',
23
+ 'lib/vertica/messages/backend_key_data.rb',
24
+ 'lib/vertica/messages/bind.rb',
25
+ 'lib/vertica/messages/bind_complete.rb',
26
+ 'lib/vertica/messages/cancel_request.rb',
27
+ 'lib/vertica/messages/close.rb',
28
+ 'lib/vertica/messages/close_complete.rb',
29
+ 'lib/vertica/messages/command_complete.rb',
30
+ 'lib/vertica/messages/data_row.rb',
31
+ 'lib/vertica/messages/describe.rb',
32
+ 'lib/vertica/messages/empty_query_response.rb',
33
+ 'lib/vertica/messages/error_response.rb',
34
+ 'lib/vertica/messages/execute.rb',
35
+ 'lib/vertica/messages/flush.rb',
36
+ 'lib/vertica/messages/message.rb',
37
+ 'lib/vertica/messages/no_data.rb',
38
+ 'lib/vertica/messages/notice_response.rb',
39
+ 'lib/vertica/messages/notification_response.rb',
40
+ 'lib/vertica/messages/parameter_description.rb',
41
+ 'lib/vertica/messages/parameter_status.rb',
42
+ 'lib/vertica/messages/parse.rb',
43
+ 'lib/vertica/messages/parse_complete.rb',
44
+ 'lib/vertica/messages/password.rb',
45
+ 'lib/vertica/messages/portal_suspended.rb',
46
+ 'lib/vertica/messages/query.rb',
47
+ 'lib/vertica/messages/ready_for_query.rb',
48
+ 'lib/vertica/messages/row_description.rb',
49
+ 'lib/vertica/messages/ssl_request.rb',
50
+ 'lib/vertica/messages/startup.rb',
51
+ 'lib/vertica/messages/sync.rb',
52
+ 'lib/vertica/messages/terminate.rb',
53
+ 'lib/vertica/messages/unknown.rb',
54
+ 'test/connection_test.rb',
55
+ 'test/create_schema.sql',
56
+ 'test/test_helper.rb']
57
+
58
+ s.test_files = ['test/test_helper.rb']
59
+
60
+ s.homepage = "http://github.com/mattbauer/vertica"
61
+
62
+ s.require_paths = ["lib"]
63
+ s.has_rdoc = true
64
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vertica
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 4
9
+ version: 0.7.4
10
+ platform: ruby
11
+ authors:
12
+ - Matt Bauer
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-17 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description:
22
+ email: bauer@pedalbrain.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - vertica.gemspec
31
+ - LICENSE
32
+ - README.textile
33
+ - Rakefile
34
+ - lib/vertica.rb
35
+ - lib/vertica/notice.rb
36
+ - lib/vertica/bit_helper.rb
37
+ - lib/vertica/column.rb
38
+ - lib/vertica/connection.rb
39
+ - lib/vertica/notification.rb
40
+ - lib/vertica/result.rb
41
+ - lib/vertica/vertica_socket.rb
42
+ - lib/vertica/messages/authentication.rb
43
+ - lib/vertica/messages/backend_key_data.rb
44
+ - lib/vertica/messages/bind.rb
45
+ - lib/vertica/messages/bind_complete.rb
46
+ - lib/vertica/messages/cancel_request.rb
47
+ - lib/vertica/messages/close.rb
48
+ - lib/vertica/messages/close_complete.rb
49
+ - lib/vertica/messages/command_complete.rb
50
+ - lib/vertica/messages/data_row.rb
51
+ - lib/vertica/messages/describe.rb
52
+ - lib/vertica/messages/empty_query_response.rb
53
+ - lib/vertica/messages/error_response.rb
54
+ - lib/vertica/messages/execute.rb
55
+ - lib/vertica/messages/flush.rb
56
+ - lib/vertica/messages/message.rb
57
+ - lib/vertica/messages/no_data.rb
58
+ - lib/vertica/messages/notice_response.rb
59
+ - lib/vertica/messages/notification_response.rb
60
+ - lib/vertica/messages/parameter_description.rb
61
+ - lib/vertica/messages/parameter_status.rb
62
+ - lib/vertica/messages/parse.rb
63
+ - lib/vertica/messages/parse_complete.rb
64
+ - lib/vertica/messages/password.rb
65
+ - lib/vertica/messages/portal_suspended.rb
66
+ - lib/vertica/messages/query.rb
67
+ - lib/vertica/messages/ready_for_query.rb
68
+ - lib/vertica/messages/row_description.rb
69
+ - lib/vertica/messages/ssl_request.rb
70
+ - lib/vertica/messages/startup.rb
71
+ - lib/vertica/messages/sync.rb
72
+ - lib/vertica/messages/terminate.rb
73
+ - lib/vertica/messages/unknown.rb
74
+ - test/connection_test.rb
75
+ - test/create_schema.sql
76
+ - test/test_helper.rb
77
+ has_rdoc: true
78
+ homepage: http://github.com/mattbauer/vertica
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options: []
83
+
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ segments:
92
+ - 1
93
+ - 8
94
+ - 4
95
+ version: 1.8.4
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project:
107
+ rubygems_version: 1.3.7
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: A Ruby interface to Vertica
111
+ test_files:
112
+ - test/test_helper.rb