cassandra-driver 3.0.0.rc.1-java → 3.0.0.rc.2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/lib/cassandra.rb +74 -55
  4. data/lib/cassandra/attr_boolean.rb +33 -0
  5. data/lib/cassandra/auth.rb +2 -1
  6. data/lib/cassandra/auth/providers/password.rb +4 -16
  7. data/lib/cassandra/cluster/connector.rb +14 -4
  8. data/lib/cassandra/cluster/control_connection.rb +59 -67
  9. data/lib/cassandra/cluster/metadata.rb +1 -3
  10. data/lib/cassandra/cluster/options.rb +9 -10
  11. data/lib/cassandra/cluster/registry.rb +16 -5
  12. data/lib/cassandra/cluster/schema.rb +45 -1
  13. data/lib/cassandra/cluster/schema/fetchers.rb +475 -272
  14. data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +2 -6
  15. data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +5 -7
  16. data/lib/cassandra/column.rb +1 -20
  17. data/lib/cassandra/column_container.rb +322 -0
  18. data/lib/cassandra/compression/compressors/lz4.rb +3 -5
  19. data/lib/cassandra/driver.rb +1 -1
  20. data/lib/cassandra/errors.rb +38 -22
  21. data/lib/cassandra/execution/options.rb +4 -2
  22. data/lib/cassandra/future.rb +3 -9
  23. data/lib/cassandra/host.rb +16 -2
  24. data/lib/cassandra/index.rb +104 -0
  25. data/lib/cassandra/keyspace.rb +88 -9
  26. data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +6 -10
  27. data/lib/cassandra/materialized_view.rb +90 -0
  28. data/lib/cassandra/protocol/coder.rb +3 -3
  29. data/lib/cassandra/protocol/cql_byte_buffer.rb +12 -11
  30. data/lib/cassandra/protocol/cql_protocol_handler.rb +12 -8
  31. data/lib/cassandra/protocol/request.rb +4 -5
  32. data/lib/cassandra/protocol/requests/execute_request.rb +3 -5
  33. data/lib/cassandra/protocol/requests/query_request.rb +1 -1
  34. data/lib/cassandra/protocol/requests/startup_request.rb +6 -8
  35. data/lib/cassandra/protocol/response.rb +1 -2
  36. data/lib/cassandra/protocol/responses/auth_challenge_response.rb +3 -4
  37. data/lib/cassandra/protocol/responses/auth_success_response.rb +3 -4
  38. data/lib/cassandra/protocol/responses/authenticate_response.rb +3 -4
  39. data/lib/cassandra/protocol/responses/error_response.rb +3 -4
  40. data/lib/cassandra/protocol/responses/event_response.rb +2 -3
  41. data/lib/cassandra/protocol/responses/prepared_result_response.rb +3 -4
  42. data/lib/cassandra/protocol/responses/ready_response.rb +3 -4
  43. data/lib/cassandra/protocol/responses/result_response.rb +7 -8
  44. data/lib/cassandra/protocol/responses/rows_result_response.rb +3 -4
  45. data/lib/cassandra/protocol/responses/schema_change_event_response.rb +3 -4
  46. data/lib/cassandra/protocol/responses/schema_change_result_response.rb +3 -4
  47. data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +3 -4
  48. data/lib/cassandra/protocol/responses/status_change_event_response.rb +3 -4
  49. data/lib/cassandra/protocol/responses/supported_response.rb +3 -4
  50. data/lib/cassandra/protocol/responses/topology_change_event_response.rb +3 -4
  51. data/lib/cassandra/protocol/responses/void_result_response.rb +3 -4
  52. data/lib/cassandra/protocol/v1.rb +1 -5
  53. data/lib/cassandra/protocol/v3.rb +1 -3
  54. data/lib/cassandra/result.rb +2 -1
  55. data/lib/cassandra/retry/policies/downgrading_consistency.rb +1 -3
  56. data/lib/cassandra/statements/prepared.rb +3 -3
  57. data/lib/cassandra/table.rb +39 -220
  58. data/lib/cassandra/time_uuid.rb +5 -7
  59. data/lib/cassandra/tuple.rb +4 -12
  60. data/lib/cassandra/types.rb +92 -65
  61. data/lib/cassandra/udt.rb +34 -14
  62. data/lib/cassandra/uuid.rb +10 -18
  63. data/lib/cassandra/version.rb +1 -1
  64. data/lib/cassandra_murmur3.jar +0 -0
  65. metadata +8 -2
@@ -19,6 +19,9 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class SetKeyspaceResultResponse < ResultResponse
22
+ # @private
23
+ RESULT_TYPES[0x03] = self
24
+
22
25
  attr_reader :keyspace
23
26
 
24
27
  def initialize(custom_payload, warnings, keyspace, trace_id)
@@ -29,10 +32,6 @@ module Cassandra
29
32
  def to_s
30
33
  %(RESULT SET_KEYSPACE "#{@keyspace}")
31
34
  end
32
-
33
- private
34
-
35
- RESULT_TYPES[0x03] = self
36
35
  end
37
36
  end
38
37
  end
@@ -21,6 +21,9 @@ module Cassandra
21
21
  class StatusChangeEventResponse < EventResponse
22
22
  TYPE = 'STATUS_CHANGE'.freeze
23
23
 
24
+ # @private
25
+ EVENT_TYPES[TYPE] = self
26
+
24
27
  attr_reader :type, :change, :address, :port
25
28
 
26
29
  def initialize(*args)
@@ -31,10 +34,6 @@ module Cassandra
31
34
  def to_s
32
35
  %(EVENT #{@type} #{@change} #{@address}:#{@port})
33
36
  end
34
-
35
- private
36
-
37
- EVENT_TYPES[TYPE] = self
38
37
  end
39
38
  end
40
39
  end
@@ -19,6 +19,9 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class SupportedResponse < Response
22
+ # @private
23
+ RESPONSE_TYPES[0x06] = self
24
+
22
25
  attr_reader :options
23
26
 
24
27
  def initialize(options)
@@ -28,10 +31,6 @@ module Cassandra
28
31
  def to_s
29
32
  %(SUPPORTED #{options})
30
33
  end
31
-
32
- private
33
-
34
- RESPONSE_TYPES[0x06] = self
35
34
  end
36
35
  end
37
36
  end
@@ -21,14 +21,13 @@ module Cassandra
21
21
  class TopologyChangeEventResponse < StatusChangeEventResponse
22
22
  TYPE = 'TOPOLOGY_CHANGE'.freeze
23
23
 
24
+ # @private
25
+ EVENT_TYPES[TYPE] = self
26
+
24
27
  def initialize(*args)
25
28
  super
26
29
  @type = TYPE
27
30
  end
28
-
29
- private
30
-
31
- EVENT_TYPES[TYPE] = self
32
31
  end
33
32
  end
34
33
  end
@@ -19,6 +19,9 @@
19
19
  module Cassandra
20
20
  module Protocol
21
21
  class VoidResultResponse < ResultResponse
22
+ # @private
23
+ RESULT_TYPES[0x01] = self
24
+
22
25
  def to_s
23
26
  %(RESULT VOID)
24
27
  end
@@ -26,10 +29,6 @@ module Cassandra
26
29
  def void?
27
30
  true
28
31
  end
29
-
30
- private
31
-
32
- RESULT_TYPES[0x01] = self
33
32
  end
34
33
  end
35
34
  end
@@ -155,8 +155,6 @@ module Cassandra
155
155
  end
156
156
  end
157
157
 
158
- private
159
-
160
158
  CODE_ERROR = 0x00
161
159
  CODE_READY = 0x02
162
160
  CODE_AUTHENTICATE = 0x03
@@ -258,9 +256,7 @@ module Cassandra
258
256
  id = buffer.read_short_bytes
259
257
  params_metadata = Coder.read_metadata_v1(buffer).first
260
258
  result_metadata = nil
261
- if protocol_version > 1
262
- result_metadata = Coder.read_metadata_v1(buffer).first
263
- end
259
+ result_metadata = Coder.read_metadata_v1(buffer).first if protocol_version > 1
264
260
 
265
261
  PreparedResultResponse.new(nil,
266
262
  nil,
@@ -290,9 +290,7 @@ module Cassandra
290
290
  id = buffer.read_short_bytes
291
291
  params_metadata = Coder.read_metadata_v3(buffer).first
292
292
  result_metadata = nil
293
- if protocol_version > 1
294
- result_metadata = Coder.read_metadata_v3(buffer).first
295
- end
293
+ result_metadata = Coder.read_metadata_v3(buffer).first if protocol_version > 1
296
294
 
297
295
  PreparedResultResponse.new(nil,
298
296
  nil,
@@ -96,7 +96,8 @@ module Cassandra
96
96
  # undefined and will likely cause a server process of the coordinator of
97
97
  # such request to abort.
98
98
  #
99
- # @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L482-L487 Paging State description in Cassandra Native Protocol v2 specification
99
+ # @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L482-L487 Paging State
100
+ # description in Cassandra Native Protocol v2 specification
100
101
  def paging_state
101
102
  end
102
103
  end
@@ -24,9 +24,7 @@ module Cassandra
24
24
 
25
25
  def read_timeout(statement, consistency, required, received, retrieved, retries)
26
26
  return reraise if retries > 0 || SERIAL_CONSISTENCIES.include?(consistency)
27
- if received < required
28
- return max_likely_to_work(consistency, required, received)
29
- end
27
+ return max_likely_to_work(consistency, required, received) if received < required
30
28
 
31
29
  retrieved ? reraise : try_again(consistency)
32
30
  end
@@ -189,9 +189,9 @@ module Cassandra
189
189
  buffer.discard(4) # discard size
190
190
  else
191
191
  buf = Protocol::CqlByteBuffer.new
192
- partition_key.each do |i|
193
- value = values[i]
194
- metadata = params_metadata[i]
192
+ partition_key.each do |ind|
193
+ value = values[ind]
194
+ metadata = params_metadata[ind]
195
195
  name = metadata[2]
196
196
  type = metadata[3]
197
197
 
@@ -20,232 +20,65 @@ module Cassandra
20
20
  # Represents a cassandra table
21
21
  # @see Cassandra::Keyspace#each_table
22
22
  # @see Cassandra::Keyspace#table
23
- class Table
24
- # @private
25
- class Options
26
- attr_reader :comment, :read_repair_chance, :local_read_repair_chance,
27
- :gc_grace_seconds, :caching, :bloom_filter_fp_chance,
28
- :populate_io_cache_on_flush, :memtable_flush_period_in_ms,
29
- :default_time_to_live, :speculative_retry, :index_interval,
30
- :replicate_on_write, :compaction_strategy, :compact_storage,
31
- :compression_parameters
32
-
33
- def initialize(comment,
34
- read_repair_chance,
35
- local_read_repair_chance,
36
- gc_grace_seconds,
37
- caching,
38
- bloom_filter_fp_chance,
39
- populate_io_cache_on_flush,
40
- memtable_flush_period_in_ms,
41
- default_time_to_live,
42
- speculative_retry,
43
- index_interval,
44
- replicate_on_write,
45
- min_index_interval,
46
- max_index_interval,
47
- compaction_strategy,
48
- compression_parameters,
49
- compact_storage)
50
- @comment = comment
51
- @read_repair_chance = read_repair_chance
52
- @local_read_repair_chance = local_read_repair_chance
53
- @gc_grace_seconds = gc_grace_seconds
54
- @caching = caching
55
- @bloom_filter_fp_chance = bloom_filter_fp_chance
56
- @populate_io_cache_on_flush = populate_io_cache_on_flush
57
- @memtable_flush_period_in_ms = memtable_flush_period_in_ms
58
- @default_time_to_live = default_time_to_live
59
- @speculative_retry = speculative_retry
60
- @index_interval = index_interval
61
- @replicate_on_write = replicate_on_write
62
- @min_index_interval = min_index_interval
63
- @max_index_interval = max_index_interval
64
- @compaction_strategy = compaction_strategy
65
- @compression_parameters = compression_parameters
66
- @compact_storage = compact_storage
67
- end
68
-
69
- def replicate_on_write?
70
- @replicate_on_write
71
- end
72
-
73
- def populate_io_cache_on_flush?
74
- @populate_io_cache_on_flush
75
- end
76
-
77
- def compact_storage?
78
- @compact_storage
79
- end
80
-
81
- def to_cql
82
- options = []
83
-
84
- options << 'COMPACT STORAGE' if @compact_storage
85
- unless @bloom_filter_fp_chance.nil?
86
- options <<
87
- "bloom_filter_fp_chance = #{Util.encode_object(@bloom_filter_fp_chance)}"
88
- end
89
- options << "caching = #{Util.encode_object(@caching)}" unless @caching.nil?
90
- options << "comment = #{Util.encode_object(@comment)}" unless @comment.nil?
91
- unless @compaction_strategy.nil?
92
- options << "compaction = #{@compaction_strategy.to_cql}"
93
- end
94
- unless @compression_parameters.nil?
95
- options << "compression = #{Util.encode_object(@compression_parameters)}"
96
- end
97
- unless @local_read_repair_chance.nil?
98
- options << 'dclocal_read_repair_chance = ' \
99
- "#{Util.encode_object(@local_read_repair_chance)}"
100
- end
101
- unless @default_time_to_live.nil?
102
- options << "default_time_to_live = #{Util.encode_object(@default_time_to_live)}"
103
- end
104
- unless @gc_grace_seconds.nil?
105
- options << "gc_grace_seconds = #{Util.encode_object(@gc_grace_seconds)}"
106
- end
107
- unless @index_interval.nil?
108
- options << "index_interval = #{Util.encode_object(@index_interval)}"
109
- end
110
- unless @max_index_interval.nil?
111
- options << "max_index_interval = #{Util.encode_object(@max_index_interval)}"
112
- end
113
- unless @memtable_flush_period_in_ms.nil?
114
- options << 'memtable_flush_period_in_ms = ' \
115
- "#{Util.encode_object(@memtable_flush_period_in_ms)}"
116
- end
117
- unless @min_index_interval.nil?
118
- options << "min_index_interval = #{Util.encode_object(@min_index_interval)}"
119
- end
120
- unless @populate_io_cache_on_flush.nil?
121
- options << "populate_io_cache_on_flush = '#{@populate_io_cache_on_flush}'"
122
- end
123
- unless @read_repair_chance.nil?
124
- options << "read_repair_chance = #{Util.encode_object(@read_repair_chance)}"
125
- end
126
- unless @replicate_on_write.nil?
127
- options << "replicate_on_write = '#{@replicate_on_write}'"
128
- end
129
- unless @speculative_retry.nil?
130
- options << "speculative_retry = #{Util.encode_object(@speculative_retry)}"
131
- end
132
-
133
- options.join("\nAND ")
134
- end
135
-
136
- def eql?(other)
137
- other.is_a?(Options) &&
138
- @comment == other.comment &&
139
- @read_repair_chance == other.read_repair_chance &&
140
- @local_read_repair_chance == other.local_read_repair_chance &&
141
- @gc_grace_seconds == other.gc_grace_seconds &&
142
- @caching == other.caching &&
143
- @bloom_filter_fp_chance == other.bloom_filter_fp_chance &&
144
- @populate_io_cache_on_flush == other.populate_io_cache_on_flush &&
145
- @memtable_flush_period_in_ms == other.memtable_flush_period_in_ms &&
146
- @default_time_to_live == other.default_time_to_live &&
147
- @speculative_retry == other.speculative_retry &&
148
- @index_interval == other.index_interval &&
149
- @replicate_on_write == other.replicate_on_write &&
150
- @compaction_strategy == other.compaction_strategy &&
151
- @compression_parameters == other.compression_parameters &&
152
- @compact_storage == other.compact_storage
153
- end
154
- alias == eql?
155
- end
156
-
157
- # @private
158
- class Compaction
159
- attr_reader :klass, :options
160
-
161
- def initialize(klass, options)
162
- @klass = klass
163
- @options = options
164
- end
165
-
166
- def to_cql
167
- compaction = {'class' => @klass}
168
- compaction.merge!(@options)
169
-
170
- Util.encode_hash(compaction)
171
- end
172
-
173
- def eql?(other)
174
- other.is_a?(Compaction) &&
175
- @klass == other.klass &&
176
- @options == other.options
177
- end
178
- alias == eql?
179
- end
180
-
181
- # @private
182
- attr_reader :keyspace
183
- # @return [String] table name
184
- attr_reader :name
185
- # @private
186
- attr_reader :options
187
- # @private
188
- attr_reader :partition_key
23
+ class Table < ColumnContainer
24
+ # @return [Array<Symbol>] an array of order values (`:asc` or `:desc`) that apply to the
25
+ # `clustering_columns` array.
26
+ attr_reader :clustering_order
189
27
 
190
28
  # @private
191
29
  def initialize(keyspace,
192
30
  name,
193
31
  partition_key,
194
32
  clustering_columns,
195
- columns,
33
+ other_columns,
196
34
  options,
197
- clustering_order)
198
- @keyspace = keyspace
199
- @name = name
200
- @partition_key = partition_key
201
- @clustering_columns = clustering_columns
202
- @columns = columns
203
- @options = options
204
- @clustering_order = clustering_order
35
+ clustering_order,
36
+ id)
37
+ super(keyspace, name, partition_key, clustering_columns, other_columns, options, id)
38
+ @clustering_order = clustering_order.freeze
39
+ @indexes = []
40
+ @indexes_hash = {}
205
41
  end
206
42
 
207
- # @param name [String] column name
208
- # @return [Boolean] whether this table has a given column
209
- def has_column?(name)
210
- @columns.key?(name)
43
+ # @param name [String] index name
44
+ # @return [Boolean] whether this table has a given index
45
+ def has_index?(name)
46
+ @indexes_hash.key?(name)
211
47
  end
212
48
 
213
- # @param name [String] column name
214
- # @return [Cassandra::Column, nil] a column or nil
215
- def column(name)
216
- @columns[name]
49
+ # @param name [String] index name
50
+ # @return [Cassandra::Index, nil] an index or nil
51
+ def index(name)
52
+ @indexes_hash[name]
217
53
  end
218
54
 
219
- # Yield or enumerate each column defined in this table
220
- # @overload each_column
221
- # @yieldparam column [Cassandra::Column] current column
55
+ # Yield or enumerate each index bound to this table
56
+ # @overload each_index
57
+ # @yieldparam index [Cassandra::Index] current index
222
58
  # @return [Cassandra::Table] self
223
- # @overload each_column
224
- # @return [Array<Cassandra::Column>] a list of columns
225
- def each_column(&block)
59
+ # @overload each_index
60
+ # @return [Array<Cassandra::Index>] a list of indexes
61
+ def each_index(&block)
226
62
  if block_given?
227
- @columns.each_value(&block)
63
+ @indexes.each(&block)
228
64
  self
229
65
  else
230
- @columns.values
66
+ @indexes.freeze
231
67
  end
232
68
  end
233
- alias columns each_column
69
+ alias indexes each_index
234
70
 
235
71
  # @return [String] a cql representation of this table
236
72
  def to_cql
237
- cql = "CREATE TABLE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} (\n"
238
- primary_key = nil
239
- if @partition_key.one? && @clustering_columns.empty?
240
- primary_key = @partition_key.first.name
241
- end
73
+ cql = "CREATE TABLE #{Util.escape_name(@keyspace.name)}.#{Util.escape_name(@name)} (\n"
74
+ primary_key = @partition_key.first.name if @partition_key.one? && @clustering_columns.empty?
242
75
 
243
76
  first = true
244
- @columns.each do |(_, column)|
77
+ @columns.each do |column|
245
78
  if first
246
79
  first = false
247
80
  else
248
- cql << ",\n" unless first
81
+ cql << ",\n"
249
82
  end
250
83
  cql << " #{column.name} #{type_to_cql(column.type, column.frozen?)}"
251
84
  cql << ' PRIMARY KEY' if primary_key && column.name == primary_key
@@ -296,21 +129,17 @@ module Cassandra
296
129
  end
297
130
 
298
131
  # @private
299
- def inspect
300
- "#<#{self.class.name}:0x#{object_id.to_s(16)} " \
301
- "@keyspace=#{@keyspace} @name=#{@name}>"
132
+ def add_index(index)
133
+ @indexes << index
134
+ @indexes_hash[index.name] = index
302
135
  end
303
136
 
304
137
  # @private
305
138
  def eql?(other)
306
139
  other.is_a?(Table) &&
307
- @keyspace == other.keyspace &&
308
- @name == other.name &&
309
- @partition_key == other.partition_key &&
310
- @clustering_columns == other.clustering_columns &&
311
- @columns == other.raw_columns &&
312
- @options == other.options &&
313
- @clustering_order == other.clustering_order
140
+ super.eql?(other) &&
141
+ @clustering_order == other.clustering_order &&
142
+ @indexes == other.indexes
314
143
  end
315
144
  alias == eql?
316
145
 
@@ -322,7 +151,7 @@ module Cassandra
322
151
  when :tuple
323
152
  "frozen <#{type}>"
324
153
  when :udt
325
- if @keyspace == type.keyspace
154
+ if @keyspace.name == type.keyspace
326
155
  "frozen <#{Util.escape_name(type.name)}>"
327
156
  else
328
157
  "frozen <#{Util.escape_name(type.keyspace)}.#{Util.escape_name(type.name)}>"
@@ -335,15 +164,5 @@ module Cassandra
335
164
  end
336
165
  end
337
166
  end
338
-
339
- attr_reader :clustering_columns, :clustering_order
340
- protected :clustering_columns, :clustering_order
341
-
342
- protected
343
-
344
- # @private
345
- def raw_columns
346
- @columns
347
- end
348
167
  end
349
168
  end