cassandra-driver 2.1.7-java → 3.0.0.beta.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +31 -53
  3. data/lib/cassandra.rb +22 -3
  4. data/lib/cassandra/aggregate.rb +109 -0
  5. data/lib/cassandra/argument.rb +51 -0
  6. data/lib/cassandra/auth/providers/password.rb +7 -4
  7. data/lib/cassandra/cluster.rb +14 -3
  8. data/lib/cassandra/cluster/client.rb +56 -34
  9. data/lib/cassandra/cluster/connector.rb +6 -6
  10. data/lib/cassandra/cluster/control_connection.rb +204 -251
  11. data/lib/cassandra/cluster/metadata.rb +2 -0
  12. data/lib/cassandra/cluster/schema.rb +131 -209
  13. data/lib/cassandra/cluster/schema/cql_type_parser.rb +104 -0
  14. data/lib/cassandra/cluster/schema/fetchers.rb +1174 -0
  15. data/lib/cassandra/cluster/schema/{type_parser.rb → fqcn_type_parser.rb} +7 -3
  16. data/lib/cassandra/column.rb +2 -2
  17. data/lib/cassandra/driver.rb +27 -9
  18. data/lib/cassandra/errors.rb +179 -25
  19. data/lib/cassandra/execution/info.rb +8 -1
  20. data/lib/cassandra/execution/options.rb +34 -0
  21. data/lib/cassandra/execution/trace.rb +42 -10
  22. data/lib/cassandra/function.rb +150 -0
  23. data/lib/cassandra/future.rb +66 -35
  24. data/lib/cassandra/host.rb +7 -4
  25. data/lib/cassandra/keyspace.rb +112 -13
  26. data/lib/cassandra/load_balancing.rb +1 -1
  27. data/lib/cassandra/protocol.rb +9 -3
  28. data/lib/cassandra/protocol/coder.rb +434 -155
  29. data/lib/cassandra/protocol/cql_byte_buffer.rb +43 -0
  30. data/lib/cassandra/protocol/cql_protocol_handler.rb +4 -1
  31. data/lib/cassandra/protocol/request.rb +4 -0
  32. data/lib/cassandra/protocol/requests/auth_response_request.rb +5 -1
  33. data/lib/cassandra/protocol/requests/batch_request.rb +7 -2
  34. data/lib/cassandra/protocol/requests/credentials_request.rb +5 -1
  35. data/lib/cassandra/protocol/requests/execute_request.rb +16 -10
  36. data/lib/cassandra/protocol/requests/prepare_request.rb +12 -3
  37. data/lib/cassandra/protocol/requests/query_request.rb +20 -11
  38. data/lib/cassandra/protocol/responses/already_exists_error_response.rb +4 -4
  39. data/lib/cassandra/protocol/responses/error_response.rb +14 -14
  40. data/lib/cassandra/protocol/responses/function_failure_error_response.rb +41 -0
  41. data/lib/cassandra/protocol/responses/prepared_result_response.rb +12 -9
  42. data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +5 -3
  43. data/lib/cassandra/protocol/responses/read_failure_error_response.rb +43 -0
  44. data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +4 -4
  45. data/lib/cassandra/protocol/responses/ready_response.rb +5 -1
  46. data/lib/cassandra/protocol/responses/result_response.rb +3 -3
  47. data/lib/cassandra/protocol/responses/rows_result_response.rb +2 -2
  48. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +25 -24
  49. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +20 -23
  50. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
  51. data/lib/cassandra/protocol/responses/unavailable_error_response.rb +4 -4
  52. data/lib/cassandra/protocol/responses/unprepared_error_response.rb +4 -4
  53. data/lib/cassandra/protocol/responses/write_failure_error_response.rb +45 -0
  54. data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +4 -4
  55. data/lib/cassandra/protocol/v1.rb +38 -13
  56. data/lib/cassandra/protocol/v3.rb +34 -29
  57. data/lib/cassandra/protocol/v4.rb +334 -0
  58. data/lib/cassandra/result.rb +10 -9
  59. data/lib/cassandra/retry.rb +17 -3
  60. data/lib/cassandra/retry/policies/default.rb +9 -3
  61. data/lib/cassandra/session.rb +15 -7
  62. data/lib/cassandra/statement.rb +5 -0
  63. data/lib/cassandra/statements/batch.rb +36 -12
  64. data/lib/cassandra/statements/bound.rb +2 -1
  65. data/lib/cassandra/statements/prepared.rb +106 -35
  66. data/lib/cassandra/statements/simple.rb +4 -2
  67. data/lib/cassandra/table.rb +70 -105
  68. data/lib/cassandra/time.rb +98 -0
  69. data/lib/cassandra/time_uuid.rb +1 -1
  70. data/lib/cassandra/tuple.rb +7 -0
  71. data/lib/cassandra/types.rb +472 -272
  72. data/lib/cassandra/udt.rb +10 -0
  73. data/lib/cassandra/util.rb +32 -1
  74. data/lib/cassandra/uuid.rb +6 -1
  75. data/lib/cassandra/uuid/generator.rb +7 -7
  76. data/lib/cassandra/version.rb +1 -1
  77. data/lib/cassandra_murmur3.jar +0 -0
  78. data/lib/datastax/cassandra.rb +5 -2
  79. metadata +27 -17
@@ -178,6 +178,16 @@ module Cassandra
178
178
  map
179
179
  end
180
180
 
181
+ def read_bytes_map
182
+ map = {}
183
+ map_size = read_unsigned_short
184
+ map_size.times do
185
+ key = read_string
186
+ map[key] = read_bytes
187
+ end
188
+ map
189
+ end
190
+
181
191
  def read_string_multimap
182
192
  map = {}
183
193
  map_size = read_unsigned_short
@@ -188,6 +198,30 @@ module Cassandra
188
198
  map
189
199
  end
190
200
 
201
+ def read_smallint
202
+ n = read_short
203
+ return n if n <= 0x7fff
204
+ n - 0xffff - 1
205
+ rescue RangeError => e
206
+ raise Errors::DecodingError, "Not enough bytes available to decode a smallint: #{e.message}", e.backtrace
207
+ end
208
+
209
+ def read_tinyint
210
+ n = read_byte
211
+ return n if n <= 0x7f
212
+ n - 0xff - 1
213
+ rescue RangeError => e
214
+ raise Errors::DecodingError, "Not enough bytes available to decode a tinyint: #{e.message}", e.backtrace
215
+ end
216
+
217
+ def append_tinyint(n)
218
+ append([n].pack(Formats::CHAR_FORMAT))
219
+ end
220
+
221
+ def append_smallint(n)
222
+ append_short(n)
223
+ end
224
+
191
225
  def append_int(n)
192
226
  append([n].pack(Formats::INT_FORMAT))
193
227
  end
@@ -256,6 +290,15 @@ module Cassandra
256
290
  self
257
291
  end
258
292
 
293
+ def append_bytes_map(map)
294
+ append_short(map.size)
295
+ map.each do |key, value|
296
+ append_string(key)
297
+ append_bytes(value)
298
+ end
299
+ self
300
+ end
301
+
259
302
  def append_timestamp(timestamp)
260
303
  append_long(timestamp.tv_sec * 1000000 + timestamp.tv_usec)
261
304
  end
@@ -49,7 +49,10 @@ module Cassandra
49
49
 
50
50
  @promises = Hash.new
51
51
 
52
- if protocol_version > 2
52
+ if protocol_version > 3
53
+ @frame_encoder = V4::Encoder.new(@compressor, protocol_version)
54
+ @frame_decoder = V4::Decoder.new(self, @compressor)
55
+ elsif protocol_version > 2
53
56
  @frame_encoder = V3::Encoder.new(@compressor, protocol_version)
54
57
  @frame_decoder = V3::Decoder.new(self, @compressor)
55
58
  else
@@ -33,6 +33,10 @@ module Cassandra
33
33
  def compressable?
34
34
  true
35
35
  end
36
+
37
+ def payload?
38
+ false
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -40,7 +40,11 @@ module Cassandra
40
40
  alias_method :==, :eql?
41
41
 
42
42
  def hash
43
- @token.hash
43
+ @h ||= begin
44
+ h = 17
45
+ h = 31 * h + @token.hash
46
+ h
47
+ end
44
48
  end
45
49
  end
46
50
  end
@@ -23,16 +23,21 @@ module Cassandra
23
23
  UNLOGGED_TYPE = 1
24
24
  COUNTER_TYPE = 2
25
25
 
26
- attr_reader :type, :timestamp
26
+ attr_reader :type, :timestamp, :payload
27
27
  attr_accessor :consistency, :retries
28
28
 
29
- def initialize(type, consistency, trace=false, serial_consistency = nil, timestamp = nil)
29
+ def initialize(type, consistency, trace=false, serial_consistency = nil, timestamp = nil, payload = nil)
30
30
  super(0x0D, trace)
31
31
  @type = type
32
32
  @parts = []
33
33
  @consistency = consistency
34
34
  @serial_consistency = serial_consistency
35
35
  @timestamp = timestamp
36
+ @payload = payload
37
+ end
38
+
39
+ def payload?
40
+ !!@payload
36
41
  end
37
42
 
38
43
  def clear
@@ -40,7 +40,11 @@ module Cassandra
40
40
  alias_method :==, :eql?
41
41
 
42
42
  def hash
43
- @h ||= @credentials.hash
43
+ @h ||= begin
44
+ h = 17
45
+ h = 31 * h + @credentials.hash
46
+ h
47
+ end
44
48
  end
45
49
  end
46
50
  end
@@ -19,10 +19,10 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class ExecuteRequest < Request
22
- attr_reader :metadata, :values, :request_metadata, :serial_consistency, :page_size, :paging_state, :timestamp
22
+ attr_reader :metadata, :values, :request_metadata, :serial_consistency, :page_size, :paging_state, :timestamp, :payload
23
23
  attr_accessor :consistency, :retries, :id
24
24
 
25
- def initialize(id, metadata, values, request_metadata, consistency, serial_consistency=nil, page_size=nil, paging_state=nil, trace=false, timestamp = nil)
25
+ def initialize(id, metadata, values, request_metadata, consistency, serial_consistency=nil, page_size=nil, paging_state=nil, trace=false, timestamp = nil, payload = nil)
26
26
  raise ArgumentError, "Metadata for #{metadata.size} columns, but #{values.size} values given" if metadata.size != values.size
27
27
  raise ArgumentError, %(No such consistency: #{consistency.inspect}) if consistency.nil? || !CONSISTENCIES.include?(consistency)
28
28
  raise ArgumentError, %(No such consistency: #{serial_consistency.inspect}) unless serial_consistency.nil? || CONSISTENCIES.include?(serial_consistency)
@@ -37,6 +37,11 @@ module Cassandra
37
37
  @page_size = page_size
38
38
  @paging_state = paging_state
39
39
  @timestamp = timestamp
40
+ @payload = payload
41
+ end
42
+
43
+ def payload?
44
+ !!@payload
40
45
  end
41
46
 
42
47
  def write(buffer, protocol_version, encoder)
@@ -81,14 +86,15 @@ module Cassandra
81
86
 
82
87
  def hash
83
88
  @h ||= begin
84
- h = 0
85
- h = ((h & 33554431) * 31) ^ @id.hash
86
- h = ((h & 33554431) * 31) ^ @metadata.hash
87
- h = ((h & 33554431) * 31) ^ @values.hash
88
- h = ((h & 33554431) * 31) ^ @consistency.hash
89
- h = ((h & 33554431) * 31) ^ @serial_consistency.hash
90
- h = ((h & 33554431) * 31) ^ @page_size.hash
91
- h = ((h & 33554431) * 31) ^ @paging_state.hash
89
+ h = 17
90
+ h = 31 * h + @id.hash
91
+ h = 31 * h + @metadata.hash
92
+ h = 31 * h + @values.hash
93
+ h = 31 * h + @consistency.hash
94
+ h = 31 * h + @serial_consistency.hash
95
+ h = 31 * h + @page_size.hash
96
+ h = 31 * h + @paging_state.hash
97
+ h = 31 * h + @timestamp.hash
92
98
  h
93
99
  end
94
100
  end
@@ -19,14 +19,19 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class PrepareRequest < Request
22
- attr_reader :cql
22
+ attr_reader :cql, :payload
23
23
  attr_accessor :consistency, :retries
24
24
 
25
- def initialize(cql, trace=false)
25
+ def initialize(cql, trace=false, payload = nil)
26
26
  raise ArgumentError, 'No CQL given!' unless cql
27
27
  super(9, trace)
28
28
  @cql = cql
29
29
  @consistency = :one
30
+ @payload = payload
31
+ end
32
+
33
+ def payload?
34
+ !!@payload
30
35
  end
31
36
 
32
37
  def write(buffer, protocol_version, encoder)
@@ -43,7 +48,11 @@ module Cassandra
43
48
  alias_method :==, :eql?
44
49
 
45
50
  def hash
46
- @h ||= @cql.hash
51
+ @h ||= begin
52
+ h = 17
53
+ h = 31 * h + @cql.hash
54
+ h
55
+ end
47
56
  end
48
57
  end
49
58
  end
@@ -19,10 +19,10 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class QueryRequest < Request
22
- attr_reader :cql, :values, :type_hints, :serial_consistency, :page_size, :paging_state, :timestamp
22
+ attr_reader :cql, :values, :type_hints, :serial_consistency, :page_size, :paging_state, :timestamp, :payload
23
23
  attr_accessor :consistency, :retries
24
24
 
25
- def initialize(cql, values, type_hints, consistency, serial_consistency = nil, page_size = nil, paging_state = nil, trace = false, names = EMPTY_LIST, timestamp = nil)
25
+ def initialize(cql, values, type_hints, consistency, serial_consistency = nil, page_size = nil, paging_state = nil, trace = false, names = EMPTY_LIST, timestamp = nil, payload = nil)
26
26
  super(7, trace)
27
27
  @cql = cql
28
28
  @values = values
@@ -33,6 +33,11 @@ module Cassandra
33
33
  @paging_state = paging_state
34
34
  @names = names
35
35
  @timestamp = timestamp
36
+ @payload = payload
37
+ end
38
+
39
+ def payload?
40
+ !!@payload
36
41
  end
37
42
 
38
43
  def write(buffer, protocol_version, encoder)
@@ -83,15 +88,19 @@ module Cassandra
83
88
  alias_method :==, :eql?
84
89
 
85
90
  def hash
86
- h = 0xcbf29ce484222325
87
- h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @cql.hash))
88
- h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @values.hash))
89
- h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @type_hints.hash))
90
- h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @consistency.hash))
91
- h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @serial_consistency.hash))
92
- h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @page_size.hash))
93
- h = 0xffffffffffffffff & (0x100000001b3 * (h ^ @paging_state.hash))
94
- h
91
+ @h ||= begin
92
+ h = 17
93
+ h = 31 * h + @cql.hash
94
+ h = 31 * h + @values.hash
95
+ h = 31 * h + @type_hints.hash
96
+ h = 31 * h + @consistency.hash
97
+ h = 31 * h + @serial_consistency.hash
98
+ h = 31 * h + @page_size.hash
99
+ h = 31 * h + @paging_state.hash
100
+ h = 31 * h + @names.hash
101
+ h = 31 * h + @timestamp.hash
102
+ h
103
+ end
95
104
  end
96
105
  end
97
106
  end
@@ -21,15 +21,15 @@ module Cassandra
21
21
  class AlreadyExistsErrorResponse < ErrorResponse
22
22
  attr_reader :keyspace, :table
23
23
 
24
- def initialize(code, message, keyspace, table)
25
- super(code, message)
24
+ def initialize(custom_payload, warnings, code, message, keyspace, table)
25
+ super(custom_payload, warnings, code, message)
26
26
 
27
27
  @keyspace = keyspace
28
28
  @table = table
29
29
  end
30
30
 
31
- def to_error(statement = nil)
32
- Errors::AlreadyExistsError.new(@message, statement, @keyspace, @table)
31
+ def to_error(keyspace, statement, options, hosts, consistency, retries)
32
+ Errors::AlreadyExistsError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries, @keyspace, @table)
33
33
  end
34
34
 
35
35
  def to_s
@@ -19,10 +19,10 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class ErrorResponse < Response
22
- attr_reader :code, :message
22
+ attr_reader :code, :message, :custom_payload, :warnings
23
23
 
24
24
  def initialize(*args)
25
- @code, @message = args
25
+ @custom_payload, @warnings, @code, @message = args
26
26
  end
27
27
 
28
28
  def to_s
@@ -30,20 +30,20 @@ module Cassandra
30
30
  %(ERROR 0x#{hex_code} "#@message")
31
31
  end
32
32
 
33
- def to_error(statement = nil)
33
+ def to_error(keyspace, statement, options, hosts, consistency, retries)
34
34
  case @code
35
- when 0x0000 then Errors::ServerError.new(@message)
36
- when 0x000A then Errors::ProtocolError.new(@message)
37
- when 0x0100 then Errors::AuthenticationError.new(@message)
38
- when 0x1001 then Errors::OverloadedError.new(@message, statement)
39
- when 0x1002 then Errors::IsBootstrappingError.new(@message, statement)
40
- when 0x1003 then Errors::TruncateError.new(@message, statement)
41
- when 0x2000 then Errors::SyntaxError.new(@message, statement)
42
- when 0x2100 then Errors::UnauthorizedError.new(@message, statement)
43
- when 0x2200 then Errors::InvalidError.new(@message, statement)
44
- when 0x2300 then Errors::ConfigurationError.new(@message, statement)
35
+ when 0x0000 then Errors::ServerError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
36
+ when 0x000A then Errors::ProtocolError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
37
+ when 0x0100 then Errors::AuthenticationError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
38
+ when 0x1001 then Errors::OverloadedError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
39
+ when 0x1002 then Errors::IsBootstrappingError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
40
+ when 0x1003 then Errors::TruncateError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
41
+ when 0x2000 then Errors::SyntaxError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
42
+ when 0x2100 then Errors::UnauthorizedError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
43
+ when 0x2200 then Errors::InvalidError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
44
+ when 0x2300 then Errors::ConfigurationError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
45
45
  else
46
- Errors::ServerError.new(@message)
46
+ Errors::ServerError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries)
47
47
  end
48
48
  end
49
49
 
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ #--
4
+ # Copyright 2013-2015 DataStax, Inc.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #++
18
+
19
+ module Cassandra
20
+ module Protocol
21
+ class FunctionFailureErrorResponse < ErrorResponse
22
+ attr_reader :keyspace, :name, :signature
23
+
24
+ def initialize(custom_payload, warnings, code, message, keyspace, name, signature)
25
+ super(custom_payload, warnings, code, message)
26
+
27
+ @keyspace = keyspace
28
+ @name = name
29
+ @signature = signature
30
+ end
31
+
32
+ def to_error(keyspace, statement, options, hosts, consistency, retries)
33
+ Errors::FunctionCallError.new(@message, @custom_payload, @warnings, keyspace, statement, options, hosts, consistency, retries, @keyspace, @name, @signature)
34
+ end
35
+
36
+ def to_s
37
+ "#{super} #{@keyspace} #{@name} #{@signature}"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -19,11 +19,14 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class PreparedResultResponse < ResultResponse
22
- attr_reader :id, :metadata, :result_metadata
23
-
24
- def initialize(id, metadata, result_metadata, trace_id)
25
- super(trace_id)
26
- @id, @metadata, @result_metadata = id, metadata, result_metadata
22
+ attr_reader :id, :metadata, :result_metadata, :pk_idx
23
+
24
+ def initialize(custom_payload, warnings, id, metadata, result_metadata, pk_idx, trace_id)
25
+ super(custom_payload, warnings, trace_id)
26
+ @id = id
27
+ @metadata = metadata
28
+ @result_metadata = result_metadata
29
+ @pk_idx = pk_idx
27
30
  end
28
31
 
29
32
  def eql?(other)
@@ -33,10 +36,10 @@ module Cassandra
33
36
 
34
37
  def hash
35
38
  @h ||= begin
36
- h = 0
37
- h = ((h & 0x01ffffff) * 31) ^ @id.hash
38
- h = ((h & 0x01ffffff) * 31) ^ @metadata.hash
39
- h = ((h & 0x01ffffff) * 31) ^ @trace_id.hash
39
+ h = 17
40
+ h = 31 * h + @id.hash
41
+ h = 31 * h + @metadata.hash
42
+ h = 31 * h + @trace_id.hash
40
43
  h
41
44
  end
42
45
  end
@@ -19,8 +19,8 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class RawRowsResultResponse < RowsResultResponse
22
- def initialize(protocol_version, raw_rows, paging_state, trace_id)
23
- super(nil, nil, paging_state, trace_id)
22
+ def initialize(custom_payload, warnings, protocol_version, raw_rows, paging_state, trace_id)
23
+ super(custom_payload, warnings, nil, nil, paging_state, trace_id)
24
24
  @protocol_version = protocol_version
25
25
  @raw_rows = raw_rows
26
26
  end
@@ -28,7 +28,9 @@ module Cassandra
28
28
  def materialize(metadata)
29
29
  @metadata = metadata
30
30
 
31
- if @protocol_version == 3
31
+ if @protocol_version == 4
32
+ @rows = Coder.read_values_v4(@raw_rows, @metadata)
33
+ elsif @protocol_version == 3
32
34
  @rows = Coder.read_values_v3(@raw_rows, @metadata)
33
35
  else
34
36
  @rows = Coder.read_values_v1(@raw_rows, @metadata)