vertica 0.12.0 → 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -20
  3. data/lib/vertica.rb +15 -8
  4. data/lib/vertica/column.rb +32 -13
  5. data/lib/vertica/connection.rb +143 -119
  6. data/lib/vertica/{messages/backend_messages → protocol/backend}/authentication.rb +1 -1
  7. data/lib/vertica/{messages/backend_messages → protocol/backend}/backend_key_data.rb +1 -1
  8. data/lib/vertica/{messages/backend_messages → protocol/backend}/bind_complete.rb +1 -1
  9. data/lib/vertica/{messages/backend_messages → protocol/backend}/close_complete.rb +1 -1
  10. data/lib/vertica/{messages/backend_messages → protocol/backend}/command_complete.rb +1 -1
  11. data/lib/vertica/{messages/backend_messages → protocol/backend}/copy_in_response.rb +2 -2
  12. data/lib/vertica/{messages/backend_messages → protocol/backend}/data_row.rb +1 -1
  13. data/lib/vertica/{messages/backend_messages → protocol/backend}/empty_query_response.rb +1 -1
  14. data/lib/vertica/{messages/backend_messages → protocol/backend}/error_response.rb +1 -1
  15. data/lib/vertica/{messages/backend_messages → protocol/backend}/no_data.rb +1 -1
  16. data/lib/vertica/{messages/backend_messages → protocol/backend}/notice_response.rb +6 -6
  17. data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_description.rb +2 -2
  18. data/lib/vertica/{messages/backend_messages → protocol/backend}/parameter_status.rb +3 -3
  19. data/lib/vertica/{messages/backend_messages → protocol/backend}/parse_complete.rb +1 -1
  20. data/lib/vertica/{messages/backend_messages → protocol/backend}/portal_suspended.rb +1 -1
  21. data/lib/vertica/{messages/backend_messages → protocol/backend}/ready_for_query.rb +2 -2
  22. data/lib/vertica/{messages/backend_messages → protocol/backend}/row_description.rb +9 -9
  23. data/lib/vertica/{messages/backend_messages → protocol/backend}/unknown.rb +1 -1
  24. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/bind.rb +2 -3
  25. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/cancel_request.rb +3 -4
  26. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/close.rb +3 -3
  27. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_data.rb +6 -6
  28. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_done.rb +1 -1
  29. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/copy_fail.rb +5 -5
  30. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/describe.rb +3 -3
  31. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/execute.rb +3 -3
  32. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/flush.rb +1 -1
  33. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/parse.rb +3 -3
  34. data/lib/vertica/protocol/frontend/password.rb +32 -0
  35. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/query.rb +3 -4
  36. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/ssl_request.rb +2 -2
  37. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/startup.rb +2 -3
  38. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/sync.rb +1 -1
  39. data/lib/vertica/{messages/frontend_messages → protocol/frontend}/terminate.rb +1 -1
  40. data/lib/vertica/protocol/message.rb +86 -0
  41. data/lib/vertica/query.rb +63 -44
  42. data/lib/vertica/result.rb +25 -47
  43. data/lib/vertica/row.rb +44 -0
  44. data/lib/vertica/row_description.rb +102 -0
  45. data/lib/vertica/version.rb +1 -1
  46. data/test/connection.yml.example +8 -8
  47. data/test/functional/functional_connection_test.rb +178 -0
  48. data/test/functional/{query_test.rb → functional_query_test.rb} +64 -67
  49. data/test/functional/functional_value_conversion_test.rb +117 -0
  50. data/test/test_helper.rb +1 -1
  51. data/test/unit/backend_message_test.rb +57 -57
  52. data/test/unit/column_test.rb +23 -23
  53. data/test/unit/frontend_message_test.rb +5 -5
  54. data/test/unit/quoting_test.rb +16 -5
  55. data/test/unit/result_test.rb +61 -0
  56. data/test/unit/row_description_test.rb +56 -0
  57. data/test/unit/row_test.rb +31 -0
  58. data/vertica.gemspec +1 -0
  59. metadata +67 -45
  60. data/lib/vertica/messages/frontend_messages/password.rb +0 -34
  61. data/lib/vertica/messages/message.rb +0 -79
  62. data/test/functional/connection_test.rb +0 -128
  63. data/test/functional/value_conversion_test.rb +0 -88
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Authentication < BackendMessage
4
4
  message_id 'R'
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class BackendKeyData < BackendMessage
4
4
  message_id 'K'
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class BindComplete < BackendMessage
4
4
  message_id '2'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class CloseComplete < BackendMessage
4
4
  message_id '3'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class CommandComplete < BackendMessage
4
4
  message_id 'C'
5
5
 
@@ -1,8 +1,8 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class CopyInResponse < BackendMessage
4
4
  message_id 'G'
5
-
5
+
6
6
  def initialize(data)
7
7
  values = data.unpack('Cn*')
8
8
  @format = values[0]
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class DataRow < BackendMessage
4
4
  message_id 'D'
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class EmptyQueryResponse < BackendMessage
4
4
  message_id 'I'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class ErrorResponse < NoticeResponse
4
4
  message_id 'E'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class NoData < BackendMessage
4
4
  message_id 'n'
5
5
  end
@@ -1,8 +1,8 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class NoticeResponse < BackendMessage
4
4
  message_id 'N'
5
-
5
+
6
6
  FIELDS_DEFINITIONS = [
7
7
  { :type => 'q', :name => "Internal Query", :method => :internal_query },
8
8
  { :type => 'S', :name => "Severity", :method => :severity },
@@ -17,9 +17,9 @@ module Vertica
17
17
  { :type => 'F', :name => "File", :method => :file },
18
18
  { :type => 'L', :name => "Line", :method => :line }
19
19
  ]
20
-
20
+
21
21
  FIELDS = Hash[*FIELDS_DEFINITIONS.map { |f| [f[:type], f[:name]] }.flatten]
22
-
22
+
23
23
  attr_reader :values
24
24
 
25
25
  def initialize(data)
@@ -32,12 +32,12 @@ module Vertica
32
32
  end
33
33
 
34
34
  def error_message
35
- ordered_values = FIELDS_DEFINITIONS.map do |field|
35
+ ordered_values = FIELDS_DEFINITIONS.map do |field|
36
36
  "#{field[:name]}: #{@values[field[:name]]}" if @values[field[:name]]
37
37
  end
38
38
  ordered_values.compact.join(', ')
39
39
  end
40
-
40
+
41
41
  FIELDS_DEFINITIONS.each do |field_def|
42
42
  define_method(field_def[:method]) do
43
43
  @values[field_def[:name]]
@@ -1,10 +1,10 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class ParameterDescription < BackendMessage
4
4
  message_id 't'
5
5
 
6
6
  attr_reader :parameter_types
7
-
7
+
8
8
  def initialize(data)
9
9
  parameter_count = data.unpack('n').first
10
10
  parameter_type_ids = data.unpack("@2N#{parameter_count}")
@@ -1,10 +1,10 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class ParameterStatus < BackendMessage
4
4
  message_id 'S'
5
-
5
+
6
6
  attr_reader :name, :value
7
-
7
+
8
8
  def initialize(data)
9
9
  @name, @value = data.unpack('Z*Z*')
10
10
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class ParseComplete < BackendMessage
4
4
  message_id '1'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class PortalSuspended < BackendMessage
4
4
  message_id 's'
5
5
  end
@@ -1,7 +1,7 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class ReadyForQuery < BackendMessage
4
-
4
+
5
5
  STATUSES = {
6
6
  'I' => :no_transaction,
7
7
  'T' => :in_transaction,
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class RowDescription < BackendMessage
4
4
  message_id 'T'
5
5
 
@@ -12,15 +12,15 @@ module Vertica
12
12
  field_count.times do |field_index|
13
13
  field_info = data.unpack("@#{pos}Z*NnNnNn")
14
14
  @fields << {
15
- :name => field_info[0].force_encoding('UTF-8'),
16
- :table_oid => field_info[1],
17
- :attribute_number => field_info[2],
18
- :data_type_oid => field_info[3],
19
- :data_type_size => field_info[4],
20
- :type_modifier => field_info[5],
21
- :format_code => field_info[6],
15
+ :name => field_info[0].force_encoding('UTF-8'),
16
+ :table_oid => field_info[1],
17
+ :attribute_number => field_info[2],
18
+ :data_type_oid => field_info[3],
19
+ :data_type_size => field_info[4],
20
+ :data_type_modifier => field_info[5],
21
+ :format_code => field_info[6],
22
22
  }
23
-
23
+
24
24
  pos += 19 + field_info[0].size
25
25
  end
26
26
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Unknown < BackendMessage
4
4
  attr_reader :message_id
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Bind < FrontendMessage
4
4
  message_id 'B'
5
5
 
@@ -9,11 +9,10 @@ module Vertica
9
9
  @parameter_values = parameter_values
10
10
  end
11
11
 
12
- def to_bytes
12
+ def message_body
13
13
  bytes = [@portal_name, @prepared_statement_name, 0, @parameter_values.length].pack('Z*Z*nn')
14
14
  bytes << @parameter_values.map { |val| val.nil? ? [-1].pack('N') : [val.length, val].pack('Na*') }.join('')
15
15
  bytes << [0].pack('n')
16
- message_string bytes
17
16
  end
18
17
  end
19
18
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class CancelRequest < FrontendMessage
4
4
  message_id nil
5
5
 
@@ -8,10 +8,9 @@ module Vertica
8
8
  @backend_key = backend_key
9
9
  end
10
10
 
11
- def to_bytes
12
- message_string [80877102, @backend_pid, @backend_key].pack('N3')
11
+ def message_body
12
+ [80877102, @backend_pid, @backend_key].pack('N3')
13
13
  end
14
-
15
14
  end
16
15
  end
17
16
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Close < FrontendMessage
4
4
  message_id 'C'
5
5
 
@@ -12,8 +12,8 @@ module Vertica
12
12
  end
13
13
  end
14
14
 
15
- def to_bytes
16
- message_string [@close_type, @close_name].pack('AZ*')
15
+ def message_body
16
+ [@close_type, @close_name].pack('AZ*')
17
17
  end
18
18
  end
19
19
  end
@@ -1,15 +1,15 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class CopyData < FrontendMessage
4
4
  message_id 'd'
5
-
5
+
6
6
  def initialize(data)
7
7
  @data = data
8
8
  end
9
-
10
- def to_bytes
11
- message_string [@data].pack('a*')
12
- end
9
+
10
+ def message_body
11
+ @data
12
+ end
13
13
  end
14
14
  end
15
15
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class CopyDone < FrontendMessage
4
4
  message_id 'c'
5
5
  end
@@ -1,14 +1,14 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class CopyFail < FrontendMessage
4
4
  message_id 'f'
5
-
5
+
6
6
  def initialize(error_message)
7
7
  @error_message = error_message
8
8
  end
9
-
10
- def to_bytes
11
- message_string [@error_message].pack('Z*')
9
+
10
+ def message_body
11
+ [@error_message].pack('Z*')
12
12
  end
13
13
  end
14
14
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Describe < FrontendMessage
4
4
  message_id 'D'
5
5
 
@@ -12,8 +12,8 @@ module Vertica
12
12
  end
13
13
  end
14
14
 
15
- def to_bytes
16
- message_string [@describe_type, @describe_name].pack('AZ*')
15
+ def message_body
16
+ [@describe_type, @describe_name].pack('AZ*')
17
17
  end
18
18
  end
19
19
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Execute < FrontendMessage
4
4
  message_id 'E'
5
5
 
@@ -8,8 +8,8 @@ module Vertica
8
8
  @max_rows = max_rows
9
9
  end
10
10
 
11
- def to_bytes
12
- message_string [@portal_name, @max_rows].pack('Z*N')
11
+ def message_body
12
+ [@portal_name, @max_rows].pack('Z*N')
13
13
  end
14
14
  end
15
15
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Flush < FrontendMessage
4
4
  message_id 'H'
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class Parse < FrontendMessage
4
4
  message_id 'P'
5
5
 
@@ -9,8 +9,8 @@ module Vertica
9
9
  @param_types = param_types
10
10
  end
11
11
 
12
- def to_bytes
13
- message_string([@name, @query, @param_types.length, *@param_types].pack('Z*Z*nN*'))
12
+ def message_body
13
+ [@name, @query, @param_types.length, *@param_types].pack('Z*Z*nN*')
14
14
  end
15
15
  end
16
16
  end
@@ -0,0 +1,32 @@
1
+ module Vertica
2
+ module Protocol
3
+ class Password < FrontendMessage
4
+ message_id 'p'
5
+
6
+ def initialize(password, auth_method: Vertica::Protocol::Authentication::CLEARTEXT_PASSWORD, salt: nil, user: nil)
7
+ @password = password
8
+ @auth_method, @salt, @user = auth_method, salt, user
9
+ end
10
+
11
+ def encoded_password
12
+ case @auth_method
13
+ when Vertica::Protocol::Authentication::CLEARTEXT_PASSWORD
14
+ @password
15
+ when Vertica::Protocol::Authentication::CRYPT_PASSWORD
16
+ @password.crypt(@salt)
17
+ when Vertica::Protocol::Authentication::MD5_PASSWORD
18
+ require 'digest/md5'
19
+ @password = Digest::MD5.hexdigest("#{@password}#{@user}")
20
+ @password = Digest::MD5.hexdigest("#{@password}#{@salt}")
21
+ @password = "md5#{@password}"
22
+ else
23
+ raise ArgumentError.new("unsupported authentication method: #{@auth_method}")
24
+ end
25
+ end
26
+
27
+ def message_body
28
+ [encoded_password].pack('Z*')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -1,6 +1,5 @@
1
1
  module Vertica
2
- module Messages
3
-
2
+ module Protocol
4
3
  class Query < FrontendMessage
5
4
  message_id 'Q'
6
5
 
@@ -8,8 +7,8 @@ module Vertica
8
7
  @query_string = query_string
9
8
  end
10
9
 
11
- def to_bytes
12
- message_string [@query_string].pack('Z*')
10
+ def message_body
11
+ [@query_string].pack('Z*')
13
12
  end
14
13
  end
15
14
  end
@@ -1,10 +1,10 @@
1
1
  module Vertica
2
- module Messages
2
+ module Protocol
3
3
  class SslRequest < FrontendMessage
4
4
  message_id nil
5
5
 
6
6
  def to_bytes
7
- message_string [80877103].pack('N')
7
+ [80877103].pack('N')
8
8
  end
9
9
  end
10
10
  end