cassandra-driver 3.0.0.beta.1 → 3.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +90 -38
- data/ext/cassandra_murmur3/cassandra_murmur3.c +1 -1
- data/lib/cassandra.rb +327 -130
- 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/auth.rb +4 -4
- data/lib/cassandra/auth/providers.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +9 -5
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +38 -9
- data/lib/cassandra/cluster/client.rb +801 -205
- data/lib/cassandra/cluster/connection_pool.rb +2 -2
- data/lib/cassandra/cluster/connector.rb +74 -25
- data/lib/cassandra/cluster/control_connection.rb +217 -82
- data/lib/cassandra/cluster/failed_connection.rb +1 -1
- data/lib/cassandra/cluster/metadata.rb +12 -4
- data/lib/cassandra/cluster/options.rb +60 -11
- data/lib/cassandra/cluster/registry.rb +69 -16
- data/lib/cassandra/cluster/schema.rb +25 -7
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
- data/lib/cassandra/cluster/schema/fetchers.rb +263 -106
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +41 -36
- data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +3 -3
- 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 +3 -3
- data/lib/cassandra/compression.rb +1 -1
- data/lib/cassandra/compression/compressors/lz4.rb +4 -3
- data/lib/cassandra/compression/compressors/snappy.rb +4 -3
- data/lib/cassandra/driver.rb +103 -41
- data/lib/cassandra/errors.rb +265 -30
- data/lib/cassandra/execution/info.rb +16 -5
- data/lib/cassandra/execution/options.rb +99 -54
- 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 +106 -48
- data/lib/cassandra/host.rb +10 -4
- data/lib/cassandra/keyspace.rb +90 -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 +18 -18
- data/lib/cassandra/load_balancing/policies/round_robin.rb +1 -1
- data/lib/cassandra/load_balancing/policies/token_aware.rb +15 -13
- data/lib/cassandra/load_balancing/policies/white_list.rb +11 -5
- data/lib/cassandra/null_logger.rb +27 -6
- data/lib/cassandra/protocol.rb +1 -1
- data/lib/cassandra/protocol/coder.rb +78 -39
- data/lib/cassandra/protocol/cql_byte_buffer.rb +50 -33
- data/lib/cassandra/protocol/cql_protocol_handler.rb +44 -45
- data/lib/cassandra/protocol/request.rb +2 -2
- data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
- data/lib/cassandra/protocol/requests/batch_request.rb +16 -7
- data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
- data/lib/cassandra/protocol/requests/execute_request.rb +41 -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 +27 -22
- data/lib/cassandra/protocol/requests/register_request.rb +2 -2
- data/lib/cassandra/protocol/requests/startup_request.rb +6 -4
- data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
- data/lib/cassandra/protocol/response.rb +2 -2
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +1 -1
- data/lib/cassandra/protocol/responses/auth_success_response.rb +1 -1
- data/lib/cassandra/protocol/responses/authenticate_response.rb +1 -1
- data/lib/cassandra/protocol/responses/error_response.rb +101 -13
- data/lib/cassandra/protocol/responses/event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +11 -5
- 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 +3 -3
- data/lib/cassandra/protocol/responses/result_response.rb +4 -2
- data/lib/cassandra/protocol/responses/rows_result_response.rb +5 -3
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +5 -4
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +16 -9
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +2 -2
- data/lib/cassandra/protocol/responses/supported_response.rb +1 -1
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +1 -1
- 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 +1 -1
- 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 +101 -36
- data/lib/cassandra/protocol/v3.rb +124 -51
- 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 +53 -19
- 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 +7 -3
- data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
- data/lib/cassandra/session.rb +22 -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 +59 -15
- data/lib/cassandra/statements/simple.rb +23 -10
- data/lib/cassandra/statements/void.rb +1 -1
- data/lib/cassandra/table.rb +79 -30
- data/lib/cassandra/time.rb +11 -6
- data/lib/cassandra/time_uuid.rb +7 -7
- data/lib/cassandra/tuple.rb +16 -8
- data/lib/cassandra/types.rb +20 -9
- data/lib/cassandra/udt.rb +32 -36
- data/lib/cassandra/util.rb +20 -13
- data/lib/cassandra/uuid.rb +22 -15
- data/lib/cassandra/uuid/generator.rb +7 -5
- data/lib/cassandra/version.rb +2 -2
- data/lib/datastax/cassandra.rb +1 -1
- metadata +5 -3
@@ -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.
|
@@ -48,21 +48,27 @@ module Cassandra
|
|
48
48
|
#
|
49
49
|
# @raise [ArgumentError] if cql statement given is not a String
|
50
50
|
def initialize(cql, params = nil, type_hints = nil, idempotent = false)
|
51
|
-
Util.assert_instance_of(::String, cql)
|
51
|
+
Util.assert_instance_of(::String, cql) do
|
52
|
+
"cql must be a string, #{cql.inspect} given"
|
53
|
+
end
|
52
54
|
|
53
55
|
params ||= EMPTY_LIST
|
54
56
|
|
55
57
|
if params.is_a?(::Hash)
|
56
58
|
params_names = []
|
57
|
-
params = params.each_with_object([]) do |(name, value),
|
59
|
+
params = params.each_with_object([]) do |(name, value), collector|
|
58
60
|
params_names << name
|
59
|
-
|
61
|
+
collector << value
|
60
62
|
end
|
61
63
|
if type_hints && !type_hints.empty?
|
62
|
-
Util.assert_instance_of(::Hash, type_hints)
|
64
|
+
Util.assert_instance_of(::Hash, type_hints) do
|
65
|
+
'type_hints must be a Hash when using named params'
|
66
|
+
end
|
63
67
|
end
|
64
68
|
else
|
65
|
-
Util.assert_instance_of(::Array, params)
|
69
|
+
Util.assert_instance_of(::Array, params) do
|
70
|
+
"params must be an Array or a Hash, #{params.inspect} given"
|
71
|
+
end
|
66
72
|
params_names = EMPTY_LIST
|
67
73
|
end
|
68
74
|
|
@@ -71,19 +77,26 @@ module Cassandra
|
|
71
77
|
if type_hints.is_a?(::Hash)
|
72
78
|
type_hints = params_names.map {|name| type_hints[name] }
|
73
79
|
else
|
74
|
-
Util.assert_instance_of(::Array, type_hints)
|
80
|
+
Util.assert_instance_of(::Array, type_hints) do
|
81
|
+
"type_hints must be an Array or a Hash, #{type_hints.inspect} given"
|
82
|
+
end
|
75
83
|
end
|
76
84
|
|
77
85
|
@cql = cql
|
78
86
|
@params = params
|
79
|
-
@params_types = params.each_with_index.map
|
87
|
+
@params_types = params.each_with_index.map do |value, index|
|
88
|
+
(!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ?
|
89
|
+
type_hints[index] :
|
90
|
+
Util.guess_type(value)
|
91
|
+
end
|
80
92
|
@params_names = params_names
|
81
93
|
@idempotent = idempotent
|
82
94
|
end
|
83
95
|
|
84
96
|
# @return [String] a CLI-friendly simple statement representation
|
85
97
|
def inspect
|
86
|
-
"#<#{self.class.name}:0x#{
|
98
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect} " \
|
99
|
+
"@params=#{@params.inspect}>"
|
87
100
|
end
|
88
101
|
|
89
102
|
# @param other [Object, Cassandra::Statements::Simple] object to compare
|
@@ -94,7 +107,7 @@ module Cassandra
|
|
94
107
|
@params == other.params
|
95
108
|
end
|
96
109
|
|
97
|
-
alias
|
110
|
+
alias == eql?
|
98
111
|
end
|
99
112
|
end
|
100
113
|
end
|
data/lib/cassandra/table.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.
|
@@ -30,12 +30,23 @@ module Cassandra
|
|
30
30
|
:replicate_on_write, :compaction_strategy, :compact_storage,
|
31
31
|
:compression_parameters
|
32
32
|
|
33
|
-
def initialize(comment,
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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)
|
39
50
|
@comment = comment
|
40
51
|
@read_repair_chance = read_repair_chance
|
41
52
|
@local_read_repair_chance = local_read_repair_chance
|
@@ -71,22 +82,53 @@ module Cassandra
|
|
71
82
|
options = []
|
72
83
|
|
73
84
|
options << 'COMPACT STORAGE' if @compact_storage
|
74
|
-
|
85
|
+
unless @bloom_filter_fp_chance.nil?
|
86
|
+
options <<
|
87
|
+
"bloom_filter_fp_chance = #{Util.encode_object(@bloom_filter_fp_chance)}"
|
88
|
+
end
|
75
89
|
options << "caching = #{Util.encode_object(@caching)}" unless @caching.nil?
|
76
90
|
options << "comment = #{Util.encode_object(@comment)}" unless @comment.nil?
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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
|
90
132
|
|
91
133
|
options.join("\nAND ")
|
92
134
|
end
|
@@ -109,7 +151,7 @@ module Cassandra
|
|
109
151
|
@compression_parameters == other.compression_parameters &&
|
110
152
|
@compact_storage == other.compact_storage
|
111
153
|
end
|
112
|
-
alias
|
154
|
+
alias == eql?
|
113
155
|
end
|
114
156
|
|
115
157
|
# @private
|
@@ -133,7 +175,7 @@ module Cassandra
|
|
133
175
|
@klass == other.klass &&
|
134
176
|
@options == other.options
|
135
177
|
end
|
136
|
-
alias
|
178
|
+
alias == eql?
|
137
179
|
end
|
138
180
|
|
139
181
|
# @private
|
@@ -146,7 +188,13 @@ module Cassandra
|
|
146
188
|
attr_reader :partition_key
|
147
189
|
|
148
190
|
# @private
|
149
|
-
def initialize(keyspace,
|
191
|
+
def initialize(keyspace,
|
192
|
+
name,
|
193
|
+
partition_key,
|
194
|
+
clustering_columns,
|
195
|
+
columns,
|
196
|
+
options,
|
197
|
+
clustering_order)
|
150
198
|
@keyspace = keyspace
|
151
199
|
@name = name
|
152
200
|
@partition_key = partition_key
|
@@ -159,7 +207,7 @@ module Cassandra
|
|
159
207
|
# @param name [String] column name
|
160
208
|
# @return [Boolean] whether this table has a given column
|
161
209
|
def has_column?(name)
|
162
|
-
@columns.
|
210
|
+
@columns.key?(name)
|
163
211
|
end
|
164
212
|
|
165
213
|
# @param name [String] column name
|
@@ -182,7 +230,7 @@ module Cassandra
|
|
182
230
|
@columns.values
|
183
231
|
end
|
184
232
|
end
|
185
|
-
alias
|
233
|
+
alias columns each_column
|
186
234
|
|
187
235
|
# @return [String] a cql representation of this table
|
188
236
|
def to_cql
|
@@ -229,7 +277,7 @@ module Cassandra
|
|
229
277
|
cql << "\n)\nWITH "
|
230
278
|
|
231
279
|
if @clustering_order.any? {|o| o != :asc}
|
232
|
-
cql <<
|
280
|
+
cql << 'CLUSTERING ORDER BY ('
|
233
281
|
first = true
|
234
282
|
@clustering_columns.zip(@clustering_order) do |column, order|
|
235
283
|
if first
|
@@ -249,7 +297,8 @@ module Cassandra
|
|
249
297
|
|
250
298
|
# @private
|
251
299
|
def inspect
|
252
|
-
"#<#{self.class.name}:0x#{
|
300
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} " \
|
301
|
+
"@keyspace=#{@keyspace} @name=#{@name}>"
|
253
302
|
end
|
254
303
|
|
255
304
|
# @private
|
@@ -263,7 +312,7 @@ module Cassandra
|
|
263
312
|
@options == other.options &&
|
264
313
|
@clustering_order == other.clustering_order
|
265
314
|
end
|
266
|
-
alias
|
315
|
+
alias == eql?
|
267
316
|
|
268
317
|
private
|
269
318
|
|
@@ -282,7 +331,7 @@ module Cassandra
|
|
282
331
|
if is_frozen
|
283
332
|
"frozen <#{type}>"
|
284
333
|
else
|
285
|
-
|
334
|
+
type.to_s
|
286
335
|
end
|
287
336
|
end
|
288
337
|
end
|
data/lib/cassandra/time.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.
|
@@ -35,7 +35,7 @@ module Cassandra
|
|
35
35
|
# @private
|
36
36
|
def initialize(nanoseconds = 0)
|
37
37
|
if nanoseconds < 0 && nanoseconds > NANOSECONDS_IN_DAY - 1
|
38
|
-
raise ::ArgumentError,
|
38
|
+
raise ::ArgumentError, 'value must be between 0 and ' \
|
39
39
|
"#{NANOSECONDS_IN_DAY}, #{value.inspect} given"
|
40
40
|
end
|
41
41
|
|
@@ -57,18 +57,23 @@ module Cassandra
|
|
57
57
|
# @return [Integer] an integer between 0 and 60, the number of full seconds
|
58
58
|
# since the last full minutes that this time represents
|
59
59
|
def seconds
|
60
|
-
(@nanoseconds -
|
60
|
+
(@nanoseconds -
|
61
|
+
(hours * NANOSECONDS_IN_HOUR) -
|
62
|
+
(minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
|
61
63
|
end
|
62
64
|
|
63
65
|
# @return [Integer] an integer between 0 and 60, the number of full
|
64
66
|
# miliseconds since the last full second that this time represents
|
65
67
|
def miliseconds
|
66
|
-
(@nanoseconds -
|
68
|
+
(@nanoseconds -
|
69
|
+
(hours * NANOSECONDS_IN_HOUR) -
|
70
|
+
(minutes * NANOSECONDS_IN_MINUTE) -
|
71
|
+
(seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
|
67
72
|
end
|
68
73
|
|
69
74
|
# @return [String] a "%H:%M%S.%3N" formatted time string
|
70
75
|
def to_s
|
71
|
-
'%.2d:%.2d:%.2d.%.3d'
|
76
|
+
format('%.2d:%.2d:%.2d.%.3d', hours, minutes, seconds, miliseconds)
|
72
77
|
end
|
73
78
|
|
74
79
|
# @return [Integer] an integer between 0 and 86400000000000, the number of
|
@@ -81,7 +86,7 @@ module Cassandra
|
|
81
86
|
def eql?(other)
|
82
87
|
other.is_a?(Time) && other.to_nanoseconds == @nanoseconds
|
83
88
|
end
|
84
|
-
alias
|
89
|
+
alias == eql?
|
85
90
|
|
86
91
|
# @private
|
87
92
|
def <=>(other)
|
data/lib/cassandra/time_uuid.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.
|
@@ -28,8 +28,8 @@ module Cassandra
|
|
28
28
|
# @return [Time]
|
29
29
|
def to_time
|
30
30
|
t = time_bits - GREGORIAN_OFFSET
|
31
|
-
seconds = t/10_000_000
|
32
|
-
microseconds = (t - seconds * 10_000_000)/10.0
|
31
|
+
seconds = t / 10_000_000
|
32
|
+
microseconds = (t - seconds * 10_000_000) / 10.0
|
33
33
|
|
34
34
|
::Time.at(seconds, microseconds).utc
|
35
35
|
end
|
@@ -52,10 +52,10 @@ module Cassandra
|
|
52
52
|
# @return [Integer] `-1` when less than `other`, `0` when equal to `other`
|
53
53
|
# and `1` when greater than `other`
|
54
54
|
def <=>(other)
|
55
|
-
return nil unless other.
|
56
|
-
c =
|
55
|
+
return nil unless other.is_a?(Cassandra::Uuid)
|
56
|
+
c = value <=> other.value
|
57
57
|
return c if c == 0 || !other.is_a?(Cassandra::TimeUuid)
|
58
|
-
|
58
|
+
time_bits <=> other.time_bits
|
59
59
|
end
|
60
60
|
|
61
61
|
protected
|
@@ -77,4 +77,4 @@ module Cassandra
|
|
77
77
|
# @private
|
78
78
|
GREGORIAN_OFFSET = 122192928000000000
|
79
79
|
end
|
80
|
-
end
|
80
|
+
end
|
data/lib/cassandra/tuple.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.
|
@@ -40,12 +40,16 @@ module Cassandra
|
|
40
40
|
|
41
41
|
def fetch(i)
|
42
42
|
i = Integer(i)
|
43
|
-
|
43
|
+
if i < 0 || i >= @types.size
|
44
|
+
raise ::IndexError, "index #{i} is outside of tuple, size: #{@types.size}"
|
45
|
+
end
|
44
46
|
@values[i]
|
45
47
|
end
|
46
48
|
|
47
49
|
def []=(i, value)
|
48
|
-
|
50
|
+
if i < 0 || i >= @types.size
|
51
|
+
raise ::IndexError, "index #{i} is outside of tuple, size: #{@types.size}"
|
52
|
+
end
|
49
53
|
Util.assert_type(@types[i], value)
|
50
54
|
@values[i] = value
|
51
55
|
end
|
@@ -55,7 +59,7 @@ module Cassandra
|
|
55
59
|
end
|
56
60
|
|
57
61
|
def inspect
|
58
|
-
"#<Cassandra::Tuple:0x#{
|
62
|
+
"#<Cassandra::Tuple:0x#{object_id.to_s(16)} #{self}>"
|
59
63
|
end
|
60
64
|
end
|
61
65
|
|
@@ -86,7 +90,9 @@ module Cassandra
|
|
86
90
|
# @return [Object] value of the tuple at position `i`
|
87
91
|
def fetch(i)
|
88
92
|
i = Integer(i)
|
89
|
-
|
93
|
+
if i < 0 || i >= @values.size
|
94
|
+
raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}"
|
95
|
+
end
|
90
96
|
@values[i]
|
91
97
|
end
|
92
98
|
|
@@ -97,7 +103,9 @@ module Cassandra
|
|
97
103
|
# @return [Object] value of the tuple at position `i`
|
98
104
|
def []=(i, value)
|
99
105
|
i = Integer(i)
|
100
|
-
|
106
|
+
if i < 0 || i >= @values.size
|
107
|
+
raise ::IndexError, "index #{i} is outside of tuple, size: #{@values.size}"
|
108
|
+
end
|
101
109
|
@values[i] = value
|
102
110
|
end
|
103
111
|
|
@@ -114,14 +122,14 @@ module Cassandra
|
|
114
122
|
|
115
123
|
# @private
|
116
124
|
def inspect
|
117
|
-
"#<Cassandra::Tuple:0x#{
|
125
|
+
"#<Cassandra::Tuple:0x#{object_id.to_s(16)} #{self}>"
|
118
126
|
end
|
119
127
|
|
120
128
|
# @private
|
121
129
|
def eql?(other)
|
122
130
|
other == @values
|
123
131
|
end
|
124
|
-
alias
|
132
|
+
alias == eql?
|
125
133
|
|
126
134
|
# @private
|
127
135
|
def hash
|
data/lib/cassandra/types.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.
|
@@ -144,7 +144,10 @@ module Cassandra
|
|
144
144
|
end
|
145
145
|
|
146
146
|
def assert_boolean(value, message, &block)
|
147
|
-
Util.assert_instance_of_one_of([::TrueClass, ::FalseClass],
|
147
|
+
Util.assert_instance_of_one_of([::TrueClass, ::FalseClass],
|
148
|
+
value,
|
149
|
+
message,
|
150
|
+
&block)
|
148
151
|
end
|
149
152
|
|
150
153
|
def new_decimal(value)
|
@@ -193,7 +196,7 @@ module Cassandra
|
|
193
196
|
Util.assert_instance_of(::Time, value, message, &block)
|
194
197
|
end
|
195
198
|
|
196
|
-
def new_uuid(value
|
199
|
+
def new_uuid(value)
|
197
200
|
Cassandra::Uuid.new(value)
|
198
201
|
end
|
199
202
|
|
@@ -1042,7 +1045,9 @@ module Cassandra
|
|
1042
1045
|
#
|
1043
1046
|
# tuple(varchar, varchar, int).new('Jane', 'Smith', 38) # => (Jane, Smith, 38)
|
1044
1047
|
def new(*values)
|
1045
|
-
Util.assert(values.size <= @members.size)
|
1048
|
+
Util.assert(values.size <= @members.size) do
|
1049
|
+
"too many values: #{values.size} out of max #{@members.size}"
|
1050
|
+
end
|
1046
1051
|
values.each_with_index do |v, i|
|
1047
1052
|
Util.assert_type(@members[i], v)
|
1048
1053
|
end
|
@@ -1240,7 +1245,9 @@ module Cassandra
|
|
1240
1245
|
value = value.first if value.one?
|
1241
1246
|
value = Array(value) unless value.is_a?(::Hash)
|
1242
1247
|
|
1243
|
-
Util.assert(value.size <= @fields.size)
|
1248
|
+
Util.assert(value.size <= @fields.size) do
|
1249
|
+
"too many values: #{value.size} out of #{@fields.size}"
|
1250
|
+
end
|
1244
1251
|
|
1245
1252
|
case value
|
1246
1253
|
when ::Array
|
@@ -1282,7 +1289,8 @@ module Cassandra
|
|
1282
1289
|
# @return [String] `"keyspace.name"`
|
1283
1290
|
# @see Cassandra::Type#to_s
|
1284
1291
|
def to_s
|
1285
|
-
"#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}
|
1292
|
+
"#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} " \
|
1293
|
+
"{#{@fields.join(', ')}}"
|
1286
1294
|
end
|
1287
1295
|
|
1288
1296
|
def hash
|
@@ -1306,7 +1314,8 @@ module Cassandra
|
|
1306
1314
|
|
1307
1315
|
# Output this type in CQL
|
1308
1316
|
def to_cql
|
1309
|
-
cql = "CREATE TYPE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)}
|
1317
|
+
cql = "CREATE TYPE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} " \
|
1318
|
+
"(\n"
|
1310
1319
|
first = true
|
1311
1320
|
|
1312
1321
|
@fields.each do |field|
|
@@ -1355,7 +1364,8 @@ module Cassandra
|
|
1355
1364
|
# @param value [*Object] value to be coerced
|
1356
1365
|
# @return [Object] a value of this type
|
1357
1366
|
def new(*value)
|
1358
|
-
raise ::NotImplementedError,
|
1367
|
+
raise ::NotImplementedError,
|
1368
|
+
"unable to create a value for custom type: #{@name.inspect}"
|
1359
1369
|
end
|
1360
1370
|
|
1361
1371
|
# Asserts that a given value is of this type
|
@@ -1365,7 +1375,8 @@ module Cassandra
|
|
1365
1375
|
# @raise [ArgumentError] if the value is invalid
|
1366
1376
|
# @return [void]
|
1367
1377
|
def assert(value, message = nil, &block)
|
1368
|
-
raise ::NotImplementedError,
|
1378
|
+
raise ::NotImplementedError,
|
1379
|
+
"unable to assert a value for custom type: #{@name.inspect}"
|
1369
1380
|
end
|
1370
1381
|
|
1371
1382
|
# @return [String] a cassandra representation of this type
|