vertica 0.12.0 → 1.0.0.rc1
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.
- checksums.yaml +4 -4
- data/README.md +18 -20
- data/lib/vertica.rb +15 -8
- data/lib/vertica/column.rb +32 -13
- data/lib/vertica/connection.rb +143 -119
- data/lib/vertica/{messages/backend_messages → protocol/backend}/authentication.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/backend_key_data.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/bind_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/close_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/command_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/copy_in_response.rb +2 -2
- data/lib/vertica/{messages/backend_messages → protocol/backend}/data_row.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/empty_query_response.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/error_response.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/no_data.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/notice_response.rb +6 -6
- data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_description.rb +2 -2
- data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_status.rb +3 -3
- data/lib/vertica/{messages/backend_messages → protocol/backend}/parse_complete.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/portal_suspended.rb +1 -1
- data/lib/vertica/{messages/backend_messages → protocol/backend}/ready_for_query.rb +2 -2
- data/lib/vertica/{messages/backend_messages → protocol/backend}/row_description.rb +9 -9
- data/lib/vertica/{messages/backend_messages → protocol/backend}/unknown.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/bind.rb +2 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/cancel_request.rb +3 -4
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/close.rb +3 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_data.rb +6 -6
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_done.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_fail.rb +5 -5
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/describe.rb +3 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/execute.rb +3 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/flush.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/parse.rb +3 -3
- data/lib/vertica/protocol/frontend/password.rb +32 -0
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/query.rb +3 -4
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/ssl_request.rb +2 -2
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/startup.rb +2 -3
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/sync.rb +1 -1
- data/lib/vertica/{messages/frontend_messages → protocol/frontend}/terminate.rb +1 -1
- data/lib/vertica/protocol/message.rb +86 -0
- data/lib/vertica/query.rb +63 -44
- data/lib/vertica/result.rb +25 -47
- data/lib/vertica/row.rb +44 -0
- data/lib/vertica/row_description.rb +102 -0
- data/lib/vertica/version.rb +1 -1
- data/test/connection.yml.example +8 -8
- data/test/functional/functional_connection_test.rb +178 -0
- data/test/functional/{query_test.rb → functional_query_test.rb} +64 -67
- data/test/functional/functional_value_conversion_test.rb +117 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/backend_message_test.rb +57 -57
- data/test/unit/column_test.rb +23 -23
- data/test/unit/frontend_message_test.rb +5 -5
- data/test/unit/quoting_test.rb +16 -5
- data/test/unit/result_test.rb +61 -0
- data/test/unit/row_description_test.rb +56 -0
- data/test/unit/row_test.rb +31 -0
- data/vertica.gemspec +1 -0
- metadata +67 -45
- data/lib/vertica/messages/frontend_messages/password.rb +0 -34
- data/lib/vertica/messages/message.rb +0 -79
- data/test/functional/connection_test.rb +0 -128
- data/test/functional/value_conversion_test.rb +0 -88
data/lib/vertica/version.rb
CHANGED
data/test/connection.yml.example
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
host: 127.0.0.1
|
2
|
-
port: 5433
|
3
|
-
|
4
|
-
password: dbadmin
|
5
|
-
database: ci
|
6
|
-
# ssl: true
|
7
|
-
# search_path:
|
8
|
-
# role:
|
1
|
+
:host: 127.0.0.1
|
2
|
+
:port: 5433
|
3
|
+
:username: dbadmin
|
4
|
+
:password: dbadmin
|
5
|
+
:database: ci
|
6
|
+
# :ssl: true
|
7
|
+
# :search_path:
|
8
|
+
# :role:
|
@@ -0,0 +1,178 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class FunctionalConnectionTest < Minitest::Test
|
4
|
+
def test_opening_and_closing_connection
|
5
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
6
|
+
assert_valid_open_connection(connection)
|
7
|
+
|
8
|
+
connection.close
|
9
|
+
assert_valid_closed_connection(connection)
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_connection_with_ssl
|
13
|
+
connection = Vertica::Connection.new(ssl: true, **TEST_CONNECTION_HASH)
|
14
|
+
assert_valid_open_connection(connection)
|
15
|
+
assert connection.ssl?
|
16
|
+
|
17
|
+
connection.close
|
18
|
+
assert_valid_closed_connection(connection)
|
19
|
+
assert !connection.ssl?
|
20
|
+
|
21
|
+
rescue Vertica::Error::SSLNotSupported
|
22
|
+
puts "\nThe test server doesn't support SSL, so SSL connections could not be tested."
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_interruptable_connection
|
26
|
+
connection = Vertica::Connection.new(interruptable: true, **TEST_CONNECTION_HASH)
|
27
|
+
assert connection.interruptable?, "The connection should be interruptable!"
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_interrupt_on_non_interruptable_connection
|
31
|
+
connection = Vertica::Connection.new(interruptable: false, **TEST_CONNECTION_HASH)
|
32
|
+
assert_raises(Vertica::Error::InterruptImpossible) { connection.interrupt }
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_new_with_error_response
|
36
|
+
assert_raises(Vertica::Error::ConnectionError) do
|
37
|
+
Vertica::Connection.new(TEST_CONNECTION_HASH.merge(database: 'nonexistant_db'))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_initialize_connection_with_search_path
|
42
|
+
connection = Vertica::Connection.new(search_path: 'public', **TEST_CONNECTION_HASH)
|
43
|
+
assert_equal "public, v_catalog, v_monitor, v_internal", connection_setting(connection, 'search_path')
|
44
|
+
|
45
|
+
connection = Vertica::Connection.new(search_path: ['v_catalog', 'v_monitor', 'v_internal'], **TEST_CONNECTION_HASH)
|
46
|
+
assert_equal "v_catalog, v_monitor, v_internal", connection_setting(connection, 'search_path')
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_initialize_connection_with_role
|
50
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
51
|
+
available_roles = connection.query('show available roles').fetch(0, 'setting').split(', ')
|
52
|
+
|
53
|
+
connection = Vertica::Connection.new(role: :none, **TEST_CONNECTION_HASH)
|
54
|
+
enabled_roles = connection.query('show enabled roles').fetch(0, 'setting').split(', ')
|
55
|
+
assert_equal [], enabled_roles
|
56
|
+
|
57
|
+
connection = Vertica::Connection.new(role: :all, **TEST_CONNECTION_HASH)
|
58
|
+
enabled_roles = connection.query('show enabled roles').fetch(0, 'setting').split(', ')
|
59
|
+
assert_equal available_roles, enabled_roles
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_initialize_connection_with_timezone
|
63
|
+
connection = Vertica::Connection.new(timezone: 'America/Toronto', **TEST_CONNECTION_HASH)
|
64
|
+
assert_equal 'America/Toronto', connection_setting(connection, 'timezone')
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_connection_inspect_should_not_print_password
|
68
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
69
|
+
inspected_string = connection.inspect
|
70
|
+
assert inspected_string !~ /:password=>#{TEST_CONNECTION_HASH[:password]}/
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_connection_timed_out_error
|
74
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
75
|
+
connection.options[:read_timeout] = 0.01
|
76
|
+
assert_raises(Vertica::Error::TimedOutError) {connection.query("SELECT SLEEP(1)")}
|
77
|
+
assert connection.closed?
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_automatically_reconnects
|
81
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
82
|
+
connection.close
|
83
|
+
assert_equal 1, connection.query("SELECT 1").the_value
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_socket_connection_error
|
87
|
+
TCPSocket.expects(:new).raises(Errno::ECONNREFUSED)
|
88
|
+
|
89
|
+
assert_raises(Vertica::Error::ConnectionError) { Vertica::Connection.new(TEST_CONNECTION_HASH) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_socket_read_error_during_initialization
|
93
|
+
TCPSocket.any_instance.expects(:read_nonblock).raises(Errno::ETIMEDOUT)
|
94
|
+
|
95
|
+
assert_raises(Vertica::Error::ConnectionError) { Vertica::Connection.new(TEST_CONNECTION_HASH) }
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_socket_write_error_during_query
|
99
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
100
|
+
|
101
|
+
TCPSocket.any_instance.expects(:write_nonblock).raises(Errno::ETIMEDOUT)
|
102
|
+
|
103
|
+
assert_raises(Vertica::Error::ConnectionError) { connection.query('select 1') }
|
104
|
+
assert connection.closed?
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_socket_read_error_during_query
|
108
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
109
|
+
|
110
|
+
TCPSocket.any_instance.expects(:read_nonblock).raises(Errno::ETIMEDOUT)
|
111
|
+
|
112
|
+
assert_raises(Vertica::Error::ConnectionError) { connection.query('select 1') }
|
113
|
+
assert connection.closed?
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_concurrent_access
|
117
|
+
connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
118
|
+
t = Thread.new { connection.query("SELECT sleep(1)") }
|
119
|
+
sleep(0.1)
|
120
|
+
|
121
|
+
assert connection.busy?, "The connection should be busy while executing a query"
|
122
|
+
assert_raises(Vertica::Error::SynchronizeError) { connection.query('SELECT 1') }
|
123
|
+
|
124
|
+
t.join
|
125
|
+
assert connection.ready_for_query?, "The connection should be available again."
|
126
|
+
connection.close
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_autocommit_enabled
|
130
|
+
connection = Vertica::Connection.new(autocommit: true, **TEST_CONNECTION_HASH)
|
131
|
+
connection.query("DROP TABLE IF EXISTS test_ruby_vertica_autocommit_table CASCADE;")
|
132
|
+
connection.query("CREATE TABLE test_ruby_vertica_autocommit_table (id int, name varchar(100))")
|
133
|
+
connection.query("CREATE PROJECTION IF NOT EXISTS test_ruby_vertica_autoccommit_table_p (id, name) AS SELECT * FROM test_ruby_vertica_autocommit_table SEGMENTED BY HASH(id) ALL NODES OFFSET 1")
|
134
|
+
connection.query("INSERT INTO test_ruby_vertica_autocommit_table VALUES (1, 'willem')")
|
135
|
+
|
136
|
+
# The inserted record should be visible during the session in which the record was inserted.
|
137
|
+
assert_equal 1, connection.query('SELECT COUNT(*) FROM test_ruby_vertica_autocommit_table').value
|
138
|
+
|
139
|
+
connection.close
|
140
|
+
|
141
|
+
# The inserted record should be persisted even after starting a new session, even without calling commit.
|
142
|
+
connection = Vertica::Connection.new(autocommit: true, **TEST_CONNECTION_HASH)
|
143
|
+
assert_equal 1, connection.query('SELECT COUNT(*) FROM test_ruby_vertica_autocommit_table').value
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_user_instead_of_username_for_backwards_compatibility
|
147
|
+
hash = TEST_CONNECTION_HASH.clone
|
148
|
+
hash[:user] = hash.delete(:username)
|
149
|
+
|
150
|
+
connection = Vertica::Connection.new(hash)
|
151
|
+
assert_valid_open_connection(connection)
|
152
|
+
end
|
153
|
+
|
154
|
+
private
|
155
|
+
|
156
|
+
def connection_setting(connection, setting)
|
157
|
+
connection.query("SHOW ALL").detect { |row| row['name'] == setting }.fetch('setting')
|
158
|
+
end
|
159
|
+
|
160
|
+
def assert_valid_open_connection(connection)
|
161
|
+
assert connection.opened?
|
162
|
+
refute connection.closed?
|
163
|
+
|
164
|
+
# connection variables
|
165
|
+
assert connection.transaction_status
|
166
|
+
|
167
|
+
# parameters
|
168
|
+
assert connection.parameters.kind_of?(Hash)
|
169
|
+
assert connection.parameters.include?('server_version')
|
170
|
+
end
|
171
|
+
|
172
|
+
def assert_valid_closed_connection(connection)
|
173
|
+
refute connection.opened?
|
174
|
+
assert connection.closed?
|
175
|
+
assert_equal({}, connection.parameters)
|
176
|
+
assert_nil connection.transaction_status
|
177
|
+
end
|
178
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'zlib'
|
3
3
|
|
4
|
-
class
|
4
|
+
class FunctionalQueryTest < Minitest::Test
|
5
5
|
def setup
|
6
6
|
@connection = Vertica::Connection.new(TEST_CONNECTION_HASH)
|
7
7
|
@connection.query("DROP TABLE IF EXISTS test_ruby_vertica_table CASCADE;")
|
@@ -19,90 +19,87 @@ class QueryTest < Minitest::Test
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
22
|
+
def test_select_query_with_buffered_results
|
23
23
|
r = @connection.query("SELECT * FROM test_ruby_vertica_table")
|
24
|
-
assert_equal 1, r.
|
25
|
-
assert_equal 2, r.
|
26
|
-
assert_equal :integer, r.columns[0].data_type
|
27
|
-
assert_equal :id, r.columns[0].name
|
28
|
-
assert_equal :varchar, r.columns[1].data_type
|
29
|
-
assert_equal :name, r.columns[1].name
|
30
|
-
|
31
|
-
assert_equal [{:id => 1, :name => "matt"}], r.rows
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_select_query_with_results_as_array
|
35
|
-
@connection.row_style = :array
|
36
|
-
r = @connection.query("SELECT * FROM test_ruby_vertica_table")
|
37
|
-
assert_equal 1, r.row_count
|
38
|
-
assert_equal 2, r.columns.length
|
24
|
+
assert_equal 1, r.size
|
25
|
+
assert_equal 2, r.row_description.length
|
39
26
|
assert_equal :integer, r.columns[0].data_type
|
40
|
-
assert_equal
|
27
|
+
assert_equal 'id', r.columns[0].name
|
41
28
|
assert_equal :varchar, r.columns[1].data_type
|
42
|
-
assert_equal
|
29
|
+
assert_equal 'name', r.columns[1].name
|
43
30
|
|
44
|
-
assert_equal
|
31
|
+
assert_equal 1, r[0][:id]
|
32
|
+
assert_equal 'matt', r[0][:name]
|
45
33
|
end
|
46
34
|
|
47
35
|
def test_select_query_with_streaming_results
|
48
|
-
|
49
|
-
@connection.query("SELECT 1 AS a, 2 AS b UNION ALL SELECT 3, 4"
|
50
|
-
|
36
|
+
rows = []
|
37
|
+
result = @connection.query("SELECT 1 AS a, 2 AS b UNION ALL SELECT 3, 4") do |row|
|
38
|
+
assert_kind_of Vertica::Row, row
|
39
|
+
rows << row
|
51
40
|
end
|
52
41
|
|
53
|
-
|
54
|
-
assert_equal
|
55
|
-
|
56
|
-
assert_equal
|
57
|
-
assert_equal
|
42
|
+
# For unbuffered result, we return the kind of command that was executed
|
43
|
+
assert_equal "SELECT", result
|
44
|
+
|
45
|
+
assert_equal 2, rows.length
|
46
|
+
assert_equal 1, rows[0].fetch(:a)
|
47
|
+
assert_equal 2, rows[0].fetch(:b)
|
48
|
+
assert_equal 3, rows[1].fetch(:a)
|
49
|
+
assert_equal 4, rows[1].fetch(:b)
|
58
50
|
end
|
59
51
|
|
60
52
|
def test_select_query_with_zero_streaming_results
|
61
|
-
|
62
|
-
@connection.query("SELECT 'impossible' WHERE 1=2"
|
63
|
-
|
53
|
+
rows = []
|
54
|
+
result = @connection.query("SELECT 'impossible' WHERE 1=2") do |row|
|
55
|
+
rows << row
|
64
56
|
end
|
65
57
|
|
66
|
-
assert_equal
|
58
|
+
assert_equal "SELECT", result
|
59
|
+
assert_equal 0, rows.length
|
67
60
|
end
|
68
61
|
|
69
62
|
def test_select_query_with_no_results
|
70
63
|
r = @connection.query("SELECT * FROM test_ruby_vertica_table WHERE 1 != 1")
|
71
|
-
assert_equal
|
64
|
+
assert_equal "SELECT", r.tag
|
65
|
+
assert_equal 0, r.size
|
72
66
|
assert_equal 2, r.columns.length
|
73
67
|
assert_equal :integer, r.columns[0].data_type
|
74
|
-
assert_equal
|
68
|
+
assert_equal 'id', r.columns[0].name
|
75
69
|
assert_equal :varchar, r.columns[1].data_type
|
76
|
-
assert_equal
|
77
|
-
|
70
|
+
assert_equal 'name', r.columns[1].name
|
71
|
+
assert_empty r.rows
|
78
72
|
end
|
79
73
|
|
80
74
|
def test_insert
|
81
75
|
r = @connection.query("INSERT INTO test_ruby_vertica_table VALUES (2, 'stefanie')")
|
82
|
-
assert_equal
|
76
|
+
assert_equal "INSERT", r.tag
|
77
|
+
assert_equal 1, r.size
|
83
78
|
assert_equal 1, r.columns.length
|
84
79
|
assert_equal :integer, r.columns[0].data_type
|
85
|
-
assert_equal
|
86
|
-
assert_equal
|
80
|
+
assert_equal 'OUTPUT', r.columns[0].name
|
81
|
+
assert_equal 1, r.value
|
87
82
|
end
|
88
83
|
|
89
84
|
|
90
85
|
def test_delete_of_no_rows
|
91
86
|
r = @connection.query("DELETE FROM test_ruby_vertica_table WHERE 1 != 1")
|
92
|
-
assert_equal
|
87
|
+
assert_equal "DELETE", r.tag
|
88
|
+
assert_equal 1, r.size
|
93
89
|
assert_equal 1, r.columns.length
|
94
90
|
assert_equal :integer, r.columns[0].data_type
|
95
|
-
assert_equal
|
96
|
-
assert_equal
|
91
|
+
assert_equal 'OUTPUT', r.columns[0].name
|
92
|
+
assert_equal 0, r.value
|
97
93
|
end
|
98
94
|
|
99
95
|
def test_delete_of_a_row
|
100
96
|
r = @connection.query("DELETE FROM test_ruby_vertica_table WHERE id = 1")
|
101
|
-
assert_equal
|
97
|
+
assert_equal "DELETE", r.tag
|
98
|
+
assert_equal 1, r.size
|
102
99
|
assert_equal 1, r.columns.length
|
103
100
|
assert_equal :integer, r.columns[0].data_type
|
104
|
-
assert_equal
|
105
|
-
assert_equal
|
101
|
+
assert_equal 'OUTPUT', r.columns[0].name
|
102
|
+
assert_equal 1, r.value
|
106
103
|
end
|
107
104
|
|
108
105
|
def test_empty_query
|
@@ -120,13 +117,13 @@ class QueryTest < Minitest::Test
|
|
120
117
|
def test_cleanup_after_select
|
121
118
|
3.times do
|
122
119
|
r = @connection.query("SELECT * FROM test_ruby_vertica_table")
|
123
|
-
assert_equal 1, r.
|
120
|
+
assert_equal 1, r.size
|
124
121
|
assert_equal 2, r.columns.length
|
125
122
|
assert_equal :integer, r.columns[0].data_type
|
126
|
-
assert_equal
|
123
|
+
assert_equal 'id', r.columns[0].name
|
127
124
|
assert_equal :varchar, r.columns[1].data_type
|
128
|
-
assert_equal
|
129
|
-
assert_equal [{
|
125
|
+
assert_equal 'name', r.columns[1].name
|
126
|
+
assert_equal [{'id' => 1, 'name' => "matt"}], r.map(&:to_h)
|
130
127
|
end
|
131
128
|
end
|
132
129
|
|
@@ -150,48 +147,48 @@ class QueryTest < Minitest::Test
|
|
150
147
|
end
|
151
148
|
|
152
149
|
def test_copy_in_alot_of_data_with_customer_handler
|
153
|
-
@connection.copy
|
150
|
+
@connection.copy("COPY test_ruby_vertica_table FROM STDIN") do |data|
|
154
151
|
data.write "11|#{"a" * 1_000_000}\n"
|
155
152
|
end
|
156
153
|
|
157
|
-
result = @connection.query("SELECT id FROM test_ruby_vertica_table ORDER BY id"
|
154
|
+
result = @connection.query("SELECT id FROM test_ruby_vertica_table ORDER BY id")
|
158
155
|
assert_equal 2, result.length
|
159
156
|
end
|
160
157
|
|
161
158
|
def test_copy_in_with_customer_handler
|
162
|
-
@connection.copy
|
159
|
+
@connection.copy("COPY test_ruby_vertica_table FROM STDIN") do |data|
|
163
160
|
data.write "11|Stuff\r\n"
|
164
161
|
data << "12|More stuff\n13|Fin" << "al stuff\n"
|
165
162
|
end
|
166
163
|
|
167
|
-
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id"
|
164
|
+
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id")
|
168
165
|
assert_equal 4, result.length
|
169
|
-
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.
|
166
|
+
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.map(&:to_a)
|
170
167
|
end
|
171
168
|
|
172
169
|
def test_copy_in_with_gzip
|
173
|
-
@connection.copy
|
170
|
+
@connection.copy("COPY test_ruby_vertica_table FROM STDIN GZIP") do |data|
|
174
171
|
gz = Zlib::GzipWriter.new(data)
|
175
172
|
gz << "11|Stuff\n12|More stuff\n13|Final stuff\n"
|
176
173
|
gz.close
|
177
174
|
end
|
178
175
|
|
179
|
-
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id"
|
176
|
+
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id")
|
180
177
|
assert_equal 4, result.length
|
181
|
-
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.
|
178
|
+
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.map(&:to_a)
|
182
179
|
end
|
183
180
|
|
184
181
|
def test_copy_with_ruby_exception
|
185
182
|
2.times do
|
186
183
|
begin
|
187
|
-
@connection.copy
|
184
|
+
@connection.copy("COPY test_ruby_vertica_table FROM STDIN") do |data|
|
188
185
|
data.write "11|#{"a" * 10}\n"
|
189
186
|
raise "some error"
|
190
187
|
end
|
191
188
|
rescue Vertica::Error::CopyFromStdinFailed
|
192
189
|
end
|
193
190
|
|
194
|
-
result = @connection.query("SELECT id FROM test_ruby_vertica_table ORDER BY id"
|
191
|
+
result = @connection.query("SELECT id FROM test_ruby_vertica_table ORDER BY id")
|
195
192
|
assert_equal 1, result.length
|
196
193
|
end
|
197
194
|
end
|
@@ -199,31 +196,31 @@ class QueryTest < Minitest::Test
|
|
199
196
|
def test_copy_with_backend_exception
|
200
197
|
2.times do
|
201
198
|
begin
|
202
|
-
@connection.copy
|
199
|
+
@connection.copy("COPY test_ruby_vertica_table FROM STDIN ABORT ON ERROR") do |data|
|
203
200
|
data.write "11|#{"a" * 10}|11\n" # write invalid data
|
204
201
|
end
|
205
202
|
rescue Vertica::Error::CopyRejected
|
206
203
|
end
|
207
204
|
|
208
|
-
result = @connection.query("SELECT id FROM test_ruby_vertica_table ORDER BY id"
|
205
|
+
result = @connection.query("SELECT id FROM test_ruby_vertica_table ORDER BY id")
|
209
206
|
assert_equal 1, result.length
|
210
207
|
end
|
211
208
|
end
|
212
209
|
|
213
210
|
def test_copy_in_with_file
|
214
211
|
filename = File.expand_path('../../resources/test_ruby_vertica_table.csv', __FILE__)
|
215
|
-
@connection.copy
|
216
|
-
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id"
|
212
|
+
@connection.copy("COPY test_ruby_vertica_table FROM STDIN", source: filename)
|
213
|
+
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id")
|
217
214
|
assert_equal 4, result.length
|
218
|
-
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.
|
215
|
+
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.map(&:to_a)
|
219
216
|
end
|
220
217
|
|
221
218
|
def test_copy_in_with_io
|
222
219
|
io = StringIO.new("11|Stuff\r\n12|More stuff\n13|Final stuff\n")
|
223
|
-
@connection.copy
|
224
|
-
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id"
|
220
|
+
@connection.copy("COPY test_ruby_vertica_table FROM STDIN", source: io)
|
221
|
+
result = @connection.query("SELECT * FROM test_ruby_vertica_table ORDER BY id")
|
225
222
|
assert_equal 4, result.length
|
226
|
-
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.
|
223
|
+
assert_equal [[1, "matt"], [11, "Stuff"], [12, "More stuff"], [13, "Final stuff"]], result.map(&:to_a)
|
227
224
|
end
|
228
225
|
|
229
226
|
def test_notice_handler
|