cassandra-driver 3.0.0.beta.1-java → 3.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +106 -39
- data/lib/cassandra.rb +396 -148
- data/lib/cassandra/address_resolution.rb +1 -1
- data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
- data/lib/cassandra/address_resolution/policies/none.rb +1 -1
- data/lib/cassandra/aggregate.rb +21 -7
- data/lib/cassandra/argument.rb +2 -2
- data/lib/cassandra/attr_boolean.rb +33 -0
- data/lib/cassandra/auth.rb +6 -5
- data/lib/cassandra/auth/providers.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +5 -13
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +49 -9
- data/lib/cassandra/cluster/client.rb +835 -209
- data/lib/cassandra/cluster/connection_pool.rb +2 -2
- data/lib/cassandra/cluster/connector.rb +86 -27
- data/lib/cassandra/cluster/control_connection.rb +222 -95
- data/lib/cassandra/cluster/failed_connection.rb +1 -1
- data/lib/cassandra/cluster/metadata.rb +14 -8
- data/lib/cassandra/cluster/options.rb +68 -22
- data/lib/cassandra/cluster/registry.rb +81 -17
- data/lib/cassandra/cluster/schema.rb +70 -8
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
- data/lib/cassandra/cluster/schema/fetchers.rb +601 -241
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +39 -38
- data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +6 -8
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
- data/lib/cassandra/column.rb +4 -23
- data/lib/cassandra/column_container.rb +322 -0
- data/lib/cassandra/compression.rb +1 -1
- data/lib/cassandra/compression/compressors/lz4.rb +7 -8
- data/lib/cassandra/compression/compressors/snappy.rb +4 -3
- data/lib/cassandra/driver.rb +107 -46
- data/lib/cassandra/errors.rb +303 -52
- data/lib/cassandra/execution/info.rb +16 -5
- data/lib/cassandra/execution/options.rb +102 -55
- data/lib/cassandra/execution/trace.rb +16 -9
- data/lib/cassandra/executors.rb +1 -1
- data/lib/cassandra/function.rb +19 -13
- data/lib/cassandra/function_collection.rb +85 -0
- data/lib/cassandra/future.rb +101 -49
- data/lib/cassandra/host.rb +25 -5
- data/lib/cassandra/index.rb +118 -0
- data/lib/cassandra/keyspace.rb +169 -33
- data/lib/cassandra/listener.rb +1 -1
- data/lib/cassandra/load_balancing.rb +2 -2
- data/lib/cassandra/load_balancing/policies.rb +1 -1
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +39 -25
- data/lib/cassandra/load_balancing/policies/round_robin.rb +8 -1
- data/lib/cassandra/load_balancing/policies/token_aware.rb +22 -13
- data/lib/cassandra/load_balancing/policies/white_list.rb +18 -5
- data/lib/cassandra/materialized_view.rb +90 -0
- data/lib/cassandra/null_logger.rb +27 -6
- data/lib/cassandra/protocol.rb +1 -1
- data/lib/cassandra/protocol/coder.rb +81 -42
- data/lib/cassandra/protocol/cql_byte_buffer.rb +58 -44
- data/lib/cassandra/protocol/cql_protocol_handler.rb +57 -54
- data/lib/cassandra/protocol/request.rb +6 -7
- data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
- data/lib/cassandra/protocol/requests/batch_request.rb +17 -8
- data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
- data/lib/cassandra/protocol/requests/execute_request.rb +39 -20
- data/lib/cassandra/protocol/requests/options_request.rb +1 -1
- data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
- data/lib/cassandra/protocol/requests/query_request.rb +28 -23
- data/lib/cassandra/protocol/requests/register_request.rb +2 -2
- data/lib/cassandra/protocol/requests/startup_request.rb +8 -8
- data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
- data/lib/cassandra/protocol/response.rb +3 -4
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +4 -5
- data/lib/cassandra/protocol/responses/auth_success_response.rb +4 -5
- data/lib/cassandra/protocol/responses/authenticate_response.rb +4 -5
- data/lib/cassandra/protocol/responses/error_response.rb +104 -17
- data/lib/cassandra/protocol/responses/event_response.rb +3 -4
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +14 -9
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
- data/lib/cassandra/protocol/responses/ready_response.rb +6 -7
- data/lib/cassandra/protocol/responses/result_response.rb +11 -10
- data/lib/cassandra/protocol/responses/rows_result_response.rb +8 -7
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +8 -8
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +19 -13
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +5 -6
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +5 -6
- data/lib/cassandra/protocol/responses/supported_response.rb +4 -5
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +4 -5
- data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
- data/lib/cassandra/protocol/responses/void_result_response.rb +4 -5
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
- data/lib/cassandra/protocol/v1.rb +98 -37
- data/lib/cassandra/protocol/v3.rb +121 -50
- data/lib/cassandra/protocol/v4.rb +172 -68
- data/lib/cassandra/reconnection.rb +1 -1
- data/lib/cassandra/reconnection/policies.rb +1 -1
- data/lib/cassandra/reconnection/policies/constant.rb +2 -4
- data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
- data/lib/cassandra/result.rb +55 -20
- data/lib/cassandra/retry.rb +8 -8
- data/lib/cassandra/retry/policies.rb +1 -1
- data/lib/cassandra/retry/policies/default.rb +1 -1
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +4 -2
- data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
- data/lib/cassandra/session.rb +24 -16
- data/lib/cassandra/statement.rb +1 -1
- data/lib/cassandra/statements.rb +1 -1
- data/lib/cassandra/statements/batch.rb +16 -10
- data/lib/cassandra/statements/bound.rb +10 -3
- data/lib/cassandra/statements/prepared.rb +62 -18
- data/lib/cassandra/statements/simple.rb +23 -10
- data/lib/cassandra/statements/void.rb +1 -1
- data/lib/cassandra/table.rb +53 -185
- data/lib/cassandra/time.rb +11 -6
- data/lib/cassandra/time_uuid.rb +12 -14
- data/lib/cassandra/timestamp_generator.rb +37 -0
- data/lib/cassandra/timestamp_generator/simple.rb +38 -0
- data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
- data/lib/cassandra/tuple.rb +4 -4
- data/lib/cassandra/types.rb +109 -71
- data/lib/cassandra/udt.rb +66 -50
- data/lib/cassandra/util.rb +155 -15
- data/lib/cassandra/uuid.rb +20 -21
- data/lib/cassandra/uuid/generator.rb +7 -5
- data/lib/cassandra/version.rb +2 -2
- data/lib/cassandra_murmur3.jar +0 -0
- data/lib/datastax/cassandra.rb +1 -1
- metadata +27 -16
data/lib/cassandra/udt.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -38,7 +38,7 @@ module Cassandra
|
|
38
38
|
assign = !field.chomp!('=').nil?
|
39
39
|
|
40
40
|
return super if assign && args.empty?
|
41
|
-
return super unless @name_to_type.
|
41
|
+
return super unless @name_to_type.key?(field)
|
42
42
|
|
43
43
|
if assign
|
44
44
|
value = args.first
|
@@ -58,7 +58,7 @@ module Cassandra
|
|
58
58
|
field = method.to_s
|
59
59
|
field.chomp!('=')
|
60
60
|
|
61
|
-
return true if @name_to_type.
|
61
|
+
return true if @name_to_type.key?(field)
|
62
62
|
super
|
63
63
|
end
|
64
64
|
|
@@ -94,15 +94,15 @@ module Cassandra
|
|
94
94
|
when ::Integer
|
95
95
|
if field < 0 || field >= @fields.size
|
96
96
|
raise ::IndexError,
|
97
|
-
|
98
|
-
|
97
|
+
"field index #{field} is not present in UDT: " \
|
98
|
+
"#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
|
99
99
|
end
|
100
100
|
@values[@fields[field][0]]
|
101
101
|
when ::String
|
102
|
-
unless @name_to_type.
|
102
|
+
unless @name_to_type.key?(field)
|
103
103
|
raise ::KeyError,
|
104
|
-
|
105
|
-
|
104
|
+
"field #{field} is not defined in UDT: " \
|
105
|
+
"#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
|
106
106
|
end
|
107
107
|
@values[field]
|
108
108
|
else
|
@@ -127,16 +127,16 @@ module Cassandra
|
|
127
127
|
when ::Integer
|
128
128
|
if field < 0 || field >= @fields.size
|
129
129
|
raise ::IndexError,
|
130
|
-
|
131
|
-
|
130
|
+
"field index #{field} is not present in UDT: " \
|
131
|
+
"#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
|
132
132
|
end
|
133
133
|
Util.assert_type(@fields[field][1], value)
|
134
134
|
@values[@fields[field][0]] = value
|
135
135
|
when ::String
|
136
|
-
unless @name_to_type.
|
136
|
+
unless @name_to_type.key?(field)
|
137
137
|
raise ::KeyError,
|
138
|
-
|
139
|
-
|
138
|
+
"field #{field} is not defined in UDT: " \
|
139
|
+
"#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}"
|
140
140
|
end
|
141
141
|
Util.assert_type(@name_to_type[field], value)
|
142
142
|
@values[field] = value
|
@@ -165,14 +165,14 @@ module Cassandra
|
|
165
165
|
end
|
166
166
|
|
167
167
|
def inspect
|
168
|
-
"#<Cassandra::UDT:0x#{
|
168
|
+
"#<Cassandra::UDT:0x#{object_id.to_s(16)} #{self}>"
|
169
169
|
end
|
170
170
|
|
171
171
|
def eql?(other)
|
172
172
|
(other.is_a?(Strict) && @values.all? {|n, v| v == other[n]}) ||
|
173
|
-
|
173
|
+
(other.is_a?(UDT) && other == self)
|
174
174
|
end
|
175
|
-
alias
|
175
|
+
alias == eql?
|
176
176
|
end
|
177
177
|
|
178
178
|
include Enumerable
|
@@ -181,43 +181,67 @@ module Cassandra
|
|
181
181
|
# @param values [Hash<String, Object>, Array<Array<String, Object>>,
|
182
182
|
# *Object, *Array<String, Object>] - UDT field values
|
183
183
|
# @example Various ways of creating the same UDT instance
|
184
|
-
# Cassandra::UDT.new({'street' => '123 Main St.',
|
184
|
+
# Cassandra::UDT.new({'street' => '123 Main St.',
|
185
|
+
# 'city' => 'Whatever',
|
186
|
+
# 'state' => 'XZ',
|
187
|
+
# 'zip' => '10020'})
|
185
188
|
#
|
186
|
-
# Cassandra::UDT.new(street: '123 Main St.',
|
189
|
+
# Cassandra::UDT.new(street: '123 Main St.',
|
190
|
+
# city: 'Whatever',
|
191
|
+
# state: 'XZ',
|
192
|
+
# zip: '10020')
|
187
193
|
#
|
188
|
-
# Cassandra::UDT.new('street', '123 Main St.',
|
194
|
+
# Cassandra::UDT.new('street', '123 Main St.',
|
195
|
+
# 'city', 'Whatever',
|
196
|
+
# 'state', 'XZ',
|
197
|
+
# 'zip', '10020')
|
189
198
|
#
|
190
|
-
# Cassandra::UDT.new(:street, '123 Main St.',
|
199
|
+
# Cassandra::UDT.new(:street, '123 Main St.',
|
200
|
+
# :city, 'Whatever',
|
201
|
+
# :state, 'XZ',
|
202
|
+
# :zip, '10020')
|
191
203
|
#
|
192
|
-
# Cassandra::UDT.new(['street', '123 Main St.'],
|
204
|
+
# Cassandra::UDT.new(['street', '123 Main St.'],
|
205
|
+
# ['city', 'Whatever'],
|
206
|
+
# ['state', 'XZ'],
|
207
|
+
# ['zip', '10020'])
|
193
208
|
#
|
194
|
-
# Cassandra::UDT.new([:street, '123 Main St.'],
|
209
|
+
# Cassandra::UDT.new([:street, '123 Main St.'],
|
210
|
+
# [:city, 'Whatever'],
|
211
|
+
# [:state, 'XZ'],
|
212
|
+
# [:zip, '10020'])
|
195
213
|
#
|
196
|
-
# Cassandra::UDT.new([['street', '123 Main St.'],
|
214
|
+
# Cassandra::UDT.new([['street', '123 Main St.'],
|
215
|
+
# ['city', 'Whatever'],
|
216
|
+
# ['state', 'XZ'],
|
217
|
+
# ['zip', '10020']])
|
197
218
|
#
|
198
|
-
# Cassandra::UDT.new([[:street, '123 Main St.'],
|
219
|
+
# Cassandra::UDT.new([[:street, '123 Main St.'],
|
220
|
+
# [:city, 'Whatever'],
|
221
|
+
# [:state, 'XZ'],
|
222
|
+
# [:zip, '10020']])
|
199
223
|
def initialize(*values)
|
200
224
|
values = Array(values.first) if values.one?
|
201
225
|
|
202
226
|
Util.assert_not_empty(values,
|
203
|
-
|
204
|
-
|
227
|
+
'user-defined type must contain at least one value'
|
228
|
+
)
|
205
229
|
|
206
230
|
if values.first.is_a?(::Array)
|
207
231
|
@values = values.map do |pair|
|
208
232
|
Util.assert(pair.size == 2,
|
209
|
-
|
210
|
-
|
211
|
-
|
233
|
+
'values of a user-defined type must be an Array of name and ' \
|
234
|
+
"value pairs, #{pair.inspect} given"
|
235
|
+
)
|
212
236
|
name, value = pair
|
213
237
|
|
214
238
|
[String(name), value]
|
215
239
|
end
|
216
240
|
else
|
217
|
-
Util.assert(
|
218
|
-
|
219
|
-
|
220
|
-
|
241
|
+
Util.assert(values.size.even?,
|
242
|
+
'values of a user-defined type must be an Array of alternating ' \
|
243
|
+
"names and values pairs, #{values.inspect} given"
|
244
|
+
)
|
221
245
|
@values = values.each_slice(2).map do |(name, value)|
|
222
246
|
[String(name), value]
|
223
247
|
end
|
@@ -313,17 +337,13 @@ module Cassandra
|
|
313
337
|
def fetch(field)
|
314
338
|
case field
|
315
339
|
when ::Integer
|
316
|
-
if field >= 0 && field < @values.size
|
317
|
-
raise ::IndexError, "Field index #{field.inspect} is not present"
|
318
|
-
end
|
340
|
+
raise ::IndexError, "Field index #{field.inspect} is not present" if field >= 0 && field < @values.size
|
319
341
|
|
320
342
|
@values[field][1]
|
321
343
|
when ::String
|
322
344
|
index = @values.index {|(n, _)| field == n}
|
323
345
|
|
324
|
-
unless index
|
325
|
-
raise ::KeyError, "Unsupported field #{field.inspect}"
|
326
|
-
end
|
346
|
+
raise ::KeyError, "Unsupported field #{field.inspect}" unless index
|
327
347
|
|
328
348
|
@values[index][1]
|
329
349
|
else
|
@@ -348,7 +368,7 @@ module Cassandra
|
|
348
368
|
true
|
349
369
|
end
|
350
370
|
|
351
|
-
alias
|
371
|
+
alias include? has_field?
|
352
372
|
|
353
373
|
# Sets value of the field.
|
354
374
|
#
|
@@ -363,17 +383,13 @@ module Cassandra
|
|
363
383
|
def []=(field, value)
|
364
384
|
case field
|
365
385
|
when ::Integer
|
366
|
-
if field < 0 || field >= @values.size
|
367
|
-
raise ::IndexError, "Field index #{field.inspect} is not present"
|
368
|
-
end
|
386
|
+
raise ::IndexError, "Field index #{field.inspect} is not present" if field < 0 || field >= @values.size
|
369
387
|
|
370
388
|
@values[field][1] = value
|
371
389
|
when ::String
|
372
390
|
index = @values.index {|(n, _)| field == n}
|
373
391
|
|
374
|
-
unless index
|
375
|
-
raise ::KeyError, "Unsupported field #{field.inspect}"
|
376
|
-
end
|
392
|
+
raise ::KeyError, "Unsupported field #{field.inspect}" unless index
|
377
393
|
|
378
394
|
@values[index][1] = value
|
379
395
|
else
|
@@ -410,21 +426,21 @@ module Cassandra
|
|
410
426
|
|
411
427
|
# @private
|
412
428
|
def inspect
|
413
|
-
"#<Cassandra::UDT:0x#{
|
429
|
+
"#<Cassandra::UDT:0x#{object_id.to_s(16)} #{self}>"
|
414
430
|
end
|
415
431
|
|
416
432
|
# @private
|
417
433
|
def eql?(other)
|
418
434
|
other.is_a?(UDT) && @values.all? {|(n, v)| v == other[n]}
|
419
435
|
end
|
420
|
-
alias
|
436
|
+
alias == eql?
|
421
437
|
|
422
438
|
# @private
|
423
439
|
def hash
|
424
440
|
@values.inject(17) do |h, (n, v)|
|
425
441
|
h = 31 * h + n.hash
|
426
|
-
|
442
|
+
31 * h + v.hash
|
427
443
|
end
|
428
444
|
end
|
429
445
|
end
|
430
|
-
end
|
446
|
+
end
|
data/lib/cassandra/util.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -18,7 +18,9 @@
|
|
18
18
|
|
19
19
|
module Cassandra
|
20
20
|
# @private
|
21
|
-
module Util
|
21
|
+
module Util
|
22
|
+
module_function
|
23
|
+
|
22
24
|
def encode_hash(hash, io = StringIO.new)
|
23
25
|
first = true
|
24
26
|
|
@@ -111,7 +113,7 @@ module Cassandra
|
|
111
113
|
|
112
114
|
io.string
|
113
115
|
end
|
114
|
-
alias
|
116
|
+
alias encode encode_object
|
115
117
|
|
116
118
|
def encode_time(time, io = StringIO.new)
|
117
119
|
encode_string(time.to_s, io)
|
@@ -160,8 +162,13 @@ module Cassandra
|
|
160
162
|
end
|
161
163
|
|
162
164
|
def escape_name(name)
|
163
|
-
|
164
|
-
|
165
|
+
# If name only contains lower-case chars and it's not a reserved word, return it
|
166
|
+
# as-is. Otherwise, quote.
|
167
|
+
return name if name[LOWERCASE_REGEXP] == name && !RESERVED_WORDS.include?(name)
|
168
|
+
|
169
|
+
# Replace double-quotes within name with two double-quotes (if any) and surround the whole
|
170
|
+
# thing with double-quotes
|
171
|
+
DBL_QUOT + name.gsub('"', '""') + DBL_QUOT
|
165
172
|
end
|
166
173
|
|
167
174
|
def guess_type(object)
|
@@ -190,7 +197,8 @@ module Cassandra
|
|
190
197
|
when UDT
|
191
198
|
Types.udt('unknown', 'unknown', object.map {|k, v| [k, guess_type(v)]})
|
192
199
|
else
|
193
|
-
raise ::ArgumentError,
|
200
|
+
raise ::ArgumentError,
|
201
|
+
"Unable to guess the type of the argument: #{object.inspect}"
|
194
202
|
end
|
195
203
|
end
|
196
204
|
|
@@ -212,7 +220,8 @@ module Cassandra
|
|
212
220
|
def assert_instance_of_one_of(kinds, value, message = nil, &block)
|
213
221
|
unless kinds.any? {|kind| value.is_a?(kind)}
|
214
222
|
message = yield if block_given?
|
215
|
-
message ||= "value must be an instance of one of #{kinds.inspect},
|
223
|
+
message ||= "value must be an instance of one of #{kinds.inspect}, " \
|
224
|
+
"#{value.inspect} given"
|
216
225
|
|
217
226
|
raise ::ArgumentError, message
|
218
227
|
end
|
@@ -221,7 +230,8 @@ module Cassandra
|
|
221
230
|
def assert_responds_to(method, value, message = nil, &block)
|
222
231
|
unless value.respond_to?(method)
|
223
232
|
message = yield if block_given?
|
224
|
-
message ||= "value #{value.inspect} must respond to #{method.inspect},
|
233
|
+
message ||= "value #{value.inspect} must respond to #{method.inspect}, " \
|
234
|
+
"but doesn't"
|
225
235
|
|
226
236
|
raise ::ArgumentError, message
|
227
237
|
end
|
@@ -230,7 +240,8 @@ module Cassandra
|
|
230
240
|
def assert_responds_to_all(methods, value, message = nil, &block)
|
231
241
|
unless methods.all? {|method| value.respond_to?(method)}
|
232
242
|
message = yield if block_given?
|
233
|
-
message ||= "value #{value.inspect} must respond to all methods
|
243
|
+
message ||= "value #{value.inspect} must respond to all methods " \
|
244
|
+
"#{methods.inspect}, but doesn't"
|
234
245
|
|
235
246
|
raise ::ArgumentError, message
|
236
247
|
end
|
@@ -239,14 +250,14 @@ module Cassandra
|
|
239
250
|
def assert_not_empty(value, message = nil, &block)
|
240
251
|
if value.empty?
|
241
252
|
message = yield if block_given?
|
242
|
-
message ||=
|
253
|
+
message ||= 'value cannot be empty'
|
243
254
|
|
244
255
|
raise ::ArgumentError, message
|
245
256
|
end
|
246
257
|
end
|
247
258
|
|
248
259
|
def assert_file_exists(path, message = nil, &block)
|
249
|
-
unless ::File.
|
260
|
+
unless ::File.exist?(path)
|
250
261
|
message = yield if block_given?
|
251
262
|
message ||= "expected file at #{path.inspect} to exist, but it doesn't"
|
252
263
|
|
@@ -266,7 +277,8 @@ module Cassandra
|
|
266
277
|
def assert_size(size, value, message = nil, &block)
|
267
278
|
unless value.size == size
|
268
279
|
message = yield if block_given?
|
269
|
-
message ||= "value #{value.inspect} must have size equal to
|
280
|
+
message ||= "value #{value.inspect} must have size equal to " \
|
281
|
+
"#{size.inspect}, but doesn't"
|
270
282
|
|
271
283
|
raise ::ArgumentError, message
|
272
284
|
end
|
@@ -275,7 +287,7 @@ module Cassandra
|
|
275
287
|
def assert(condition, message = nil, &block)
|
276
288
|
unless condition
|
277
289
|
message = yield if block_given?
|
278
|
-
message ||=
|
290
|
+
message ||= 'assertion failed'
|
279
291
|
|
280
292
|
raise ::ArgumentError, message
|
281
293
|
end
|
@@ -311,14 +323,142 @@ module Cassandra
|
|
311
323
|
# @private
|
312
324
|
COLON = ': '.freeze
|
313
325
|
# @private
|
314
|
-
QUOT =
|
326
|
+
QUOT = "'".freeze
|
315
327
|
# @private
|
316
328
|
ESC_QUOT = "''".freeze
|
317
329
|
# @private
|
318
|
-
DBL_QUOT =
|
330
|
+
DBL_QUOT = '"'.freeze
|
319
331
|
# @private
|
320
332
|
PRN_OPN = '('.freeze
|
321
333
|
# @private
|
322
334
|
PRN_CLS = ')'.freeze
|
335
|
+
RESERVED_WORDS = Set.new(%w(
|
336
|
+
add
|
337
|
+
aggregate
|
338
|
+
all
|
339
|
+
allow
|
340
|
+
alter
|
341
|
+
and
|
342
|
+
apply
|
343
|
+
as
|
344
|
+
asc
|
345
|
+
ascii
|
346
|
+
authorize
|
347
|
+
batch
|
348
|
+
begin
|
349
|
+
bigint
|
350
|
+
blob
|
351
|
+
boolean
|
352
|
+
by
|
353
|
+
called
|
354
|
+
clustering
|
355
|
+
columnfamily
|
356
|
+
compact
|
357
|
+
contains
|
358
|
+
count
|
359
|
+
counter
|
360
|
+
create
|
361
|
+
custom
|
362
|
+
date
|
363
|
+
decimal
|
364
|
+
delete
|
365
|
+
desc
|
366
|
+
describe
|
367
|
+
distinct
|
368
|
+
double
|
369
|
+
drop
|
370
|
+
entries
|
371
|
+
execute
|
372
|
+
exists
|
373
|
+
filtering
|
374
|
+
finalfunc
|
375
|
+
float
|
376
|
+
from
|
377
|
+
frozen
|
378
|
+
full
|
379
|
+
function
|
380
|
+
functions
|
381
|
+
grant
|
382
|
+
if
|
383
|
+
in
|
384
|
+
index
|
385
|
+
inet
|
386
|
+
infinity
|
387
|
+
initcond
|
388
|
+
input
|
389
|
+
insert
|
390
|
+
int
|
391
|
+
into
|
392
|
+
is
|
393
|
+
json
|
394
|
+
key
|
395
|
+
keys
|
396
|
+
keyspace
|
397
|
+
keyspaces
|
398
|
+
language
|
399
|
+
limit
|
400
|
+
list
|
401
|
+
login
|
402
|
+
map
|
403
|
+
materialized
|
404
|
+
modify
|
405
|
+
nan
|
406
|
+
nologin
|
407
|
+
norecursive
|
408
|
+
nosuperuser
|
409
|
+
not
|
410
|
+
null
|
411
|
+
of
|
412
|
+
on
|
413
|
+
options
|
414
|
+
or
|
415
|
+
order
|
416
|
+
password
|
417
|
+
permission
|
418
|
+
permissions
|
419
|
+
primary
|
420
|
+
rename
|
421
|
+
replace
|
422
|
+
returns
|
423
|
+
revoke
|
424
|
+
role
|
425
|
+
roles
|
426
|
+
schema
|
427
|
+
select
|
428
|
+
set
|
429
|
+
sfunc
|
430
|
+
smallint
|
431
|
+
static
|
432
|
+
storage
|
433
|
+
stype
|
434
|
+
superuser
|
435
|
+
table
|
436
|
+
text
|
437
|
+
time
|
438
|
+
timestamp
|
439
|
+
timeuuid
|
440
|
+
tinyint
|
441
|
+
to
|
442
|
+
token
|
443
|
+
trigger
|
444
|
+
truncate
|
445
|
+
ttl
|
446
|
+
tuple
|
447
|
+
type
|
448
|
+
unlogged
|
449
|
+
update
|
450
|
+
use
|
451
|
+
user
|
452
|
+
users
|
453
|
+
using
|
454
|
+
uuid
|
455
|
+
values
|
456
|
+
varchar
|
457
|
+
varint
|
458
|
+
view
|
459
|
+
where
|
460
|
+
with
|
461
|
+
writetime
|
462
|
+
)).freeze
|
323
463
|
end
|
324
464
|
end
|