cassandra-driver 2.1.7-java → 3.0.0.beta.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +31 -53
- data/lib/cassandra.rb +22 -3
- data/lib/cassandra/aggregate.rb +109 -0
- data/lib/cassandra/argument.rb +51 -0
- data/lib/cassandra/auth/providers/password.rb +7 -4
- data/lib/cassandra/cluster.rb +14 -3
- data/lib/cassandra/cluster/client.rb +56 -34
- data/lib/cassandra/cluster/connector.rb +6 -6
- data/lib/cassandra/cluster/control_connection.rb +204 -251
- data/lib/cassandra/cluster/metadata.rb +2 -0
- data/lib/cassandra/cluster/schema.rb +131 -209
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +104 -0
- data/lib/cassandra/cluster/schema/fetchers.rb +1174 -0
- data/lib/cassandra/cluster/schema/{type_parser.rb → fqcn_type_parser.rb} +7 -3
- data/lib/cassandra/column.rb +2 -2
- data/lib/cassandra/driver.rb +27 -9
- data/lib/cassandra/errors.rb +179 -25
- data/lib/cassandra/execution/info.rb +8 -1
- data/lib/cassandra/execution/options.rb +34 -0
- data/lib/cassandra/execution/trace.rb +42 -10
- data/lib/cassandra/function.rb +150 -0
- data/lib/cassandra/future.rb +66 -35
- data/lib/cassandra/host.rb +7 -4
- data/lib/cassandra/keyspace.rb +112 -13
- data/lib/cassandra/load_balancing.rb +1 -1
- data/lib/cassandra/protocol.rb +9 -3
- data/lib/cassandra/protocol/coder.rb +434 -155
- data/lib/cassandra/protocol/cql_byte_buffer.rb +43 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +4 -1
- data/lib/cassandra/protocol/request.rb +4 -0
- data/lib/cassandra/protocol/requests/auth_response_request.rb +5 -1
- data/lib/cassandra/protocol/requests/batch_request.rb +7 -2
- data/lib/cassandra/protocol/requests/credentials_request.rb +5 -1
- data/lib/cassandra/protocol/requests/execute_request.rb +16 -10
- data/lib/cassandra/protocol/requests/prepare_request.rb +12 -3
- data/lib/cassandra/protocol/requests/query_request.rb +20 -11
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +4 -4
- data/lib/cassandra/protocol/responses/error_response.rb +14 -14
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +41 -0
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +12 -9
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +5 -3
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +43 -0
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +4 -4
- data/lib/cassandra/protocol/responses/ready_response.rb +5 -1
- data/lib/cassandra/protocol/responses/result_response.rb +3 -3
- data/lib/cassandra/protocol/responses/rows_result_response.rb +2 -2
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +25 -24
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +20 -23
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
- data/lib/cassandra/protocol/responses/unavailable_error_response.rb +4 -4
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +4 -4
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +45 -0
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +4 -4
- data/lib/cassandra/protocol/v1.rb +38 -13
- data/lib/cassandra/protocol/v3.rb +34 -29
- data/lib/cassandra/protocol/v4.rb +334 -0
- data/lib/cassandra/result.rb +10 -9
- data/lib/cassandra/retry.rb +17 -3
- data/lib/cassandra/retry/policies/default.rb +9 -3
- data/lib/cassandra/session.rb +15 -7
- data/lib/cassandra/statement.rb +5 -0
- data/lib/cassandra/statements/batch.rb +36 -12
- data/lib/cassandra/statements/bound.rb +2 -1
- data/lib/cassandra/statements/prepared.rb +106 -35
- data/lib/cassandra/statements/simple.rb +4 -2
- data/lib/cassandra/table.rb +70 -105
- data/lib/cassandra/time.rb +98 -0
- data/lib/cassandra/time_uuid.rb +1 -1
- data/lib/cassandra/tuple.rb +7 -0
- data/lib/cassandra/types.rb +472 -272
- data/lib/cassandra/udt.rb +10 -0
- data/lib/cassandra/util.rb +32 -1
- data/lib/cassandra/uuid.rb +6 -1
- data/lib/cassandra/uuid/generator.rb +7 -7
- data/lib/cassandra/version.rb +1 -1
- data/lib/cassandra_murmur3.jar +0 -0
- data/lib/datastax/cassandra.rb +5 -2
- metadata +27 -17
@@ -37,6 +37,8 @@ module Cassandra
|
|
37
37
|
# for the query
|
38
38
|
# @param type_hints [Array, Hash] (nil) positional or named types
|
39
39
|
# to override type guessing for the query
|
40
|
+
# @param idempotent [Boolean] (false) whether this statement can be
|
41
|
+
# safely retries on timeouts
|
40
42
|
#
|
41
43
|
# @note Positional arguments for simple statements are only supported
|
42
44
|
# starting with Apache Cassandra 2.0 and above.
|
@@ -45,12 +47,11 @@ module Cassandra
|
|
45
47
|
# starting with Apache Cassandra 2.1 and above.
|
46
48
|
#
|
47
49
|
# @raise [ArgumentError] if cql statement given is not a String
|
48
|
-
def initialize(cql, params = nil, type_hints = nil)
|
50
|
+
def initialize(cql, params = nil, type_hints = nil, idempotent = false)
|
49
51
|
Util.assert_instance_of(::String, cql) { "cql must be a string, #{cql.inspect} given" }
|
50
52
|
|
51
53
|
params ||= EMPTY_LIST
|
52
54
|
|
53
|
-
|
54
55
|
if params.is_a?(::Hash)
|
55
56
|
params_names = []
|
56
57
|
params = params.each_with_object([]) do |(name, value), params|
|
@@ -77,6 +78,7 @@ module Cassandra
|
|
77
78
|
@params = params
|
78
79
|
@params_types = params.each_with_index.map {|value, index| (!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ? type_hints[index] : Util.guess_type(value)}
|
79
80
|
@params_names = params_names
|
81
|
+
@idempotent = idempotent
|
80
82
|
end
|
81
83
|
|
82
84
|
# @return [String] a CLI-friendly simple statement representation
|
data/lib/cassandra/table.rb
CHANGED
@@ -30,23 +30,29 @@ module Cassandra
|
|
30
30
|
:replicate_on_write, :compaction_strategy, :compact_storage,
|
31
31
|
:compression_parameters
|
32
32
|
|
33
|
-
def initialize(
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@
|
33
|
+
def initialize(comment, read_repair_chance, local_read_repair_chance,
|
34
|
+
gc_grace_seconds, caching, bloom_filter_fp_chance,
|
35
|
+
populate_io_cache_on_flush, memtable_flush_period_in_ms,
|
36
|
+
default_time_to_live, speculative_retry, index_interval,
|
37
|
+
replicate_on_write, min_index_interval, max_index_interval,
|
38
|
+
compaction_strategy, compression_parameters, compact_storage)
|
39
|
+
@comment = comment
|
40
|
+
@read_repair_chance = read_repair_chance
|
41
|
+
@local_read_repair_chance = local_read_repair_chance
|
42
|
+
@gc_grace_seconds = gc_grace_seconds
|
43
|
+
@caching = caching
|
44
|
+
@bloom_filter_fp_chance = bloom_filter_fp_chance
|
45
|
+
@populate_io_cache_on_flush = populate_io_cache_on_flush
|
46
|
+
@memtable_flush_period_in_ms = memtable_flush_period_in_ms
|
47
|
+
@default_time_to_live = default_time_to_live
|
48
|
+
@speculative_retry = speculative_retry
|
49
|
+
@index_interval = index_interval
|
50
|
+
@replicate_on_write = replicate_on_write
|
51
|
+
@min_index_interval = min_index_interval
|
52
|
+
@max_index_interval = max_index_interval
|
46
53
|
@compaction_strategy = compaction_strategy
|
47
54
|
@compression_parameters = compression_parameters
|
48
55
|
@compact_storage = compact_storage
|
49
|
-
@cassandra_version = cassandra_version
|
50
56
|
end
|
51
57
|
|
52
58
|
def replicate_on_write?
|
@@ -65,19 +71,22 @@ module Cassandra
|
|
65
71
|
options = []
|
66
72
|
|
67
73
|
options << 'COMPACT STORAGE' if @compact_storage
|
68
|
-
options << "bloom_filter_fp_chance = #{@bloom_filter_fp_chance}"
|
69
|
-
options << "caching =
|
70
|
-
options << "comment =
|
71
|
-
options << "compaction = #{@compaction_strategy.to_cql}"
|
72
|
-
options << "compression = #{Util.
|
73
|
-
options << "dclocal_read_repair_chance = #{@local_read_repair_chance}"
|
74
|
-
options << "default_time_to_live = #{@default_time_to_live}"
|
75
|
-
options << "gc_grace_seconds = #{@gc_grace_seconds}"
|
76
|
-
options << "index_interval = #{@index_interval}"
|
77
|
-
options << "
|
78
|
-
options << "
|
79
|
-
options << "
|
80
|
-
options << "
|
74
|
+
options << "bloom_filter_fp_chance = #{Util.encode_object(@bloom_filter_fp_chance)}" unless @bloom_filter_fp_chance.nil?
|
75
|
+
options << "caching = #{Util.encode_object(@caching)}" unless @caching.nil?
|
76
|
+
options << "comment = #{Util.encode_object(@comment)}" unless @comment.nil?
|
77
|
+
options << "compaction = #{@compaction_strategy.to_cql}" unless @compaction_strategy.nil?
|
78
|
+
options << "compression = #{Util.encode_object(@compression_parameters)}" unless @compression_parameters.nil?
|
79
|
+
options << "dclocal_read_repair_chance = #{Util.encode_object(@local_read_repair_chance)}" unless @local_read_repair_chance.nil?
|
80
|
+
options << "default_time_to_live = #{Util.encode_object(@default_time_to_live)}" unless @default_time_to_live.nil?
|
81
|
+
options << "gc_grace_seconds = #{Util.encode_object(@gc_grace_seconds)}" unless @gc_grace_seconds.nil?
|
82
|
+
options << "index_interval = #{Util.encode_object(@index_interval)}" unless @index_interval.nil?
|
83
|
+
options << "max_index_interval = #{Util.encode_object(@max_index_interval)}" unless @max_index_interval.nil?
|
84
|
+
options << "memtable_flush_period_in_ms = #{Util.encode_object(@memtable_flush_period_in_ms)}" unless @memtable_flush_period_in_ms.nil?
|
85
|
+
options << "min_index_interval = #{Util.encode_object(@min_index_interval)}" unless @min_index_interval.nil?
|
86
|
+
options << "populate_io_cache_on_flush = '#{@populate_io_cache_on_flush}'" unless @populate_io_cache_on_flush.nil?
|
87
|
+
options << "read_repair_chance = #{Util.encode_object(@read_repair_chance)}" unless @read_repair_chance.nil?
|
88
|
+
options << "replicate_on_write = '#{@replicate_on_write}'" unless @replicate_on_write.nil?
|
89
|
+
options << "speculative_retry = #{Util.encode_object(@speculative_retry)}" unless @speculative_retry.nil?
|
81
90
|
|
82
91
|
options.join("\nAND ")
|
83
92
|
end
|
@@ -98,13 +107,9 @@ module Cassandra
|
|
98
107
|
@replicate_on_write == other.replicate_on_write &&
|
99
108
|
@compaction_strategy == other.compaction_strategy &&
|
100
109
|
@compression_parameters == other.compression_parameters &&
|
101
|
-
@compact_storage == other.compact_storage
|
102
|
-
@cassandra_version == other.cassandra_version
|
110
|
+
@compact_storage == other.compact_storage
|
103
111
|
end
|
104
112
|
alias :== :eql?
|
105
|
-
|
106
|
-
attr_reader :cassandra_version
|
107
|
-
protected :cassandra_version
|
108
113
|
end
|
109
114
|
|
110
115
|
# @private
|
@@ -137,9 +142,11 @@ module Cassandra
|
|
137
142
|
attr_reader :name
|
138
143
|
# @private
|
139
144
|
attr_reader :options
|
145
|
+
# @private
|
146
|
+
attr_reader :partition_key
|
140
147
|
|
141
148
|
# @private
|
142
|
-
def initialize(keyspace, name, partition_key, clustering_columns, columns, options, clustering_order
|
149
|
+
def initialize(keyspace, name, partition_key, clustering_columns, columns, options, clustering_order)
|
143
150
|
@keyspace = keyspace
|
144
151
|
@name = name
|
145
152
|
@partition_key = partition_key
|
@@ -147,7 +154,6 @@ module Cassandra
|
|
147
154
|
@columns = columns
|
148
155
|
@options = options
|
149
156
|
@clustering_order = clustering_order
|
150
|
-
@release_version = release_version
|
151
157
|
end
|
152
158
|
|
153
159
|
# @param name [String] column name
|
@@ -180,7 +186,12 @@ module Cassandra
|
|
180
186
|
|
181
187
|
# @return [String] a cql representation of this table
|
182
188
|
def to_cql
|
183
|
-
cql
|
189
|
+
cql = "CREATE TABLE #{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} (\n"
|
190
|
+
primary_key = nil
|
191
|
+
if @partition_key.one? && @clustering_columns.empty?
|
192
|
+
primary_key = @partition_key.first.name
|
193
|
+
end
|
194
|
+
|
184
195
|
first = true
|
185
196
|
@columns.each do |(_, column)|
|
186
197
|
if first
|
@@ -189,27 +200,31 @@ module Cassandra
|
|
189
200
|
cql << ",\n" unless first
|
190
201
|
end
|
191
202
|
cql << " #{column.name} #{type_to_cql(column.type, column.frozen?)}"
|
203
|
+
cql << ' PRIMARY KEY' if primary_key && column.name == primary_key
|
192
204
|
end
|
193
|
-
|
194
|
-
|
195
|
-
cql <<
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
205
|
+
|
206
|
+
unless primary_key
|
207
|
+
cql << ",\n PRIMARY KEY ("
|
208
|
+
if @partition_key.one?
|
209
|
+
cql << @partition_key.first.name
|
210
|
+
else
|
211
|
+
cql << '('
|
212
|
+
first = true
|
213
|
+
@partition_key.each do |column|
|
214
|
+
if first
|
215
|
+
first = false
|
216
|
+
else
|
217
|
+
cql << ', '
|
218
|
+
end
|
219
|
+
cql << column.name
|
204
220
|
end
|
205
|
-
cql <<
|
221
|
+
cql << ')'
|
222
|
+
end
|
223
|
+
@clustering_columns.each do |column|
|
224
|
+
cql << ", #{column.name}"
|
206
225
|
end
|
207
226
|
cql << ')'
|
208
227
|
end
|
209
|
-
@clustering_columns.each do |column|
|
210
|
-
cql << ", #{column.name}"
|
211
|
-
end
|
212
|
-
cql << ')'
|
213
228
|
|
214
229
|
cql << "\n)\nWITH "
|
215
230
|
|
@@ -232,12 +247,12 @@ module Cassandra
|
|
232
247
|
cql << ';'
|
233
248
|
end
|
234
249
|
|
235
|
-
# @
|
250
|
+
# @private
|
236
251
|
def inspect
|
237
252
|
"#<#{self.class.name}:0x#{self.object_id.to_s(16)} @keyspace=#{@keyspace} @name=#{@name}>"
|
238
253
|
end
|
239
254
|
|
240
|
-
# @
|
255
|
+
# @private
|
241
256
|
def eql?(other)
|
242
257
|
other.is_a?(Table) &&
|
243
258
|
@keyspace == other.keyspace &&
|
@@ -250,53 +265,6 @@ module Cassandra
|
|
250
265
|
end
|
251
266
|
alias :== :eql?
|
252
267
|
|
253
|
-
# @private
|
254
|
-
def create_partition_key(values)
|
255
|
-
partition_key = @partition_key
|
256
|
-
return nil if partition_key.size > values.size
|
257
|
-
|
258
|
-
if partition_key.one?
|
259
|
-
column = partition_key.first
|
260
|
-
column_name = column.name
|
261
|
-
return nil unless values.has_key?(column_name)
|
262
|
-
|
263
|
-
buffer = Protocol::CqlByteBuffer.new
|
264
|
-
|
265
|
-
if @release_version > '2.1'
|
266
|
-
Protocol::Coder.write_value_v3(buffer, values[column_name], column.type)
|
267
|
-
else
|
268
|
-
Protocol::Coder.write_value_v1(buffer, values[column_name], column.type)
|
269
|
-
end
|
270
|
-
|
271
|
-
buffer.discard(4)
|
272
|
-
else
|
273
|
-
buf = nil
|
274
|
-
buffer = nil
|
275
|
-
|
276
|
-
partition_key.each do |column|
|
277
|
-
column_name = column.name
|
278
|
-
return nil unless values.has_key?(column_name)
|
279
|
-
|
280
|
-
buf ||= Protocol::CqlByteBuffer.new
|
281
|
-
buffer ||= Protocol::CqlByteBuffer.new
|
282
|
-
|
283
|
-
if @release_version > '2.1'
|
284
|
-
Protocol::Coder.write_value_v3(buf, values[column_name], column.type)
|
285
|
-
else
|
286
|
-
Protocol::Coder.write_value_v1(buf, values[column_name], column.type)
|
287
|
-
end
|
288
|
-
|
289
|
-
buf.discard(4) # discard size
|
290
|
-
|
291
|
-
size = buf.length
|
292
|
-
buffer.append_short(size)
|
293
|
-
buffer << buf.read(size) << NULL_BYTE
|
294
|
-
end
|
295
|
-
end
|
296
|
-
|
297
|
-
buffer.to_str
|
298
|
-
end
|
299
|
-
|
300
268
|
private
|
301
269
|
|
302
270
|
# @private
|
@@ -319,11 +287,8 @@ module Cassandra
|
|
319
287
|
end
|
320
288
|
end
|
321
289
|
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
attr_reader :partition_key, :clustering_columns, :clustering_order
|
326
|
-
protected :partition_key, :clustering_columns, :clustering_order
|
290
|
+
attr_reader :clustering_columns, :clustering_order
|
291
|
+
protected :clustering_columns, :clustering_order
|
327
292
|
|
328
293
|
protected
|
329
294
|
|
@@ -0,0 +1,98 @@
|
|
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
|
+
# Represents a Cassandra time type.
|
21
|
+
class Time
|
22
|
+
# @private
|
23
|
+
NANOSECONDS_IN_MILISECOND = 1_000_000
|
24
|
+
# @private
|
25
|
+
NANOSECONDS_IN_SECOND = NANOSECONDS_IN_MILISECOND * 1000
|
26
|
+
# @private
|
27
|
+
NANOSECONDS_IN_MINUTE = NANOSECONDS_IN_SECOND * 60
|
28
|
+
# @private
|
29
|
+
NANOSECONDS_IN_HOUR = NANOSECONDS_IN_MINUTE * 60
|
30
|
+
# @private
|
31
|
+
NANOSECONDS_IN_DAY = NANOSECONDS_IN_HOUR * 24
|
32
|
+
|
33
|
+
include ::Comparable
|
34
|
+
|
35
|
+
# @private
|
36
|
+
def initialize(nanoseconds = 0)
|
37
|
+
if nanoseconds < 0 && nanoseconds > NANOSECONDS_IN_DAY - 1
|
38
|
+
raise ::ArgumentError, "value must be between 0 and " \
|
39
|
+
"#{NANOSECONDS_IN_DAY}, #{value.inspect} given"
|
40
|
+
end
|
41
|
+
|
42
|
+
@nanoseconds = nanoseconds
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Integer] an integer between 0 and 24, the number of full hours
|
46
|
+
# since midnight that this time represents
|
47
|
+
def hours
|
48
|
+
@nanoseconds / NANOSECONDS_IN_HOUR
|
49
|
+
end
|
50
|
+
|
51
|
+
# @return [Integer] an integer between 0 and 60, the number of full minutes
|
52
|
+
# since the last full hour that this time represents
|
53
|
+
def minutes
|
54
|
+
(@nanoseconds - (hours * NANOSECONDS_IN_HOUR)) / NANOSECONDS_IN_MINUTE
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [Integer] an integer between 0 and 60, the number of full seconds
|
58
|
+
# since the last full minutes that this time represents
|
59
|
+
def seconds
|
60
|
+
(@nanoseconds - (hours * NANOSECONDS_IN_HOUR) - (minutes * NANOSECONDS_IN_MINUTE)) / NANOSECONDS_IN_SECOND
|
61
|
+
end
|
62
|
+
|
63
|
+
# @return [Integer] an integer between 0 and 60, the number of full
|
64
|
+
# miliseconds since the last full second that this time represents
|
65
|
+
def miliseconds
|
66
|
+
(@nanoseconds - (hours * NANOSECONDS_IN_HOUR) - (minutes * NANOSECONDS_IN_MINUTE) - (seconds * NANOSECONDS_IN_SECOND)) / NANOSECONDS_IN_MILISECOND
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [String] a "%H:%M%S.%3N" formatted time string
|
70
|
+
def to_s
|
71
|
+
'%.2d:%.2d:%.2d.%.3d' % [hours, minutes, seconds, miliseconds]
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Integer] an integer between 0 and 86400000000000, the number of
|
75
|
+
# nanoseconds since midnight that this time represents
|
76
|
+
def to_nanoseconds
|
77
|
+
@nanoseconds
|
78
|
+
end
|
79
|
+
|
80
|
+
# @private
|
81
|
+
def eql?(other)
|
82
|
+
other.is_a?(Time) && other.to_nanoseconds == @nanoseconds
|
83
|
+
end
|
84
|
+
alias :== :eql?
|
85
|
+
|
86
|
+
# @private
|
87
|
+
def <=>(other)
|
88
|
+
other <=> nanoseconds
|
89
|
+
end
|
90
|
+
|
91
|
+
# @private
|
92
|
+
def hash
|
93
|
+
# Modeled after http://developer.android.com/reference/java/lang/Object.html#writing_hashCode, but
|
94
|
+
# simplified since only one field participates in the hash.
|
95
|
+
@hash ||= 31 * 17 + @nanoseconds.hash
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/cassandra/time_uuid.rb
CHANGED
data/lib/cassandra/tuple.rb
CHANGED
@@ -112,13 +112,20 @@ module Cassandra
|
|
112
112
|
"(#{@values.map(&:to_s).join(', ')})"
|
113
113
|
end
|
114
114
|
|
115
|
+
# @private
|
115
116
|
def inspect
|
116
117
|
"#<Cassandra::Tuple:0x#{self.object_id.to_s(16)} #{to_s}>"
|
117
118
|
end
|
118
119
|
|
120
|
+
# @private
|
119
121
|
def eql?(other)
|
120
122
|
other == @values
|
121
123
|
end
|
122
124
|
alias :== :eql?
|
125
|
+
|
126
|
+
# @private
|
127
|
+
def hash
|
128
|
+
@values.inject(17) {|h, v| 31 * h + v.hash}
|
129
|
+
end
|
123
130
|
end
|
124
131
|
end
|
data/lib/cassandra/types.rb
CHANGED
@@ -21,7 +21,10 @@ module Cassandra
|
|
21
21
|
# @abstract This class exists for documentation purposes only
|
22
22
|
class Type
|
23
23
|
# @return [Symbol] shorthand type name
|
24
|
-
|
24
|
+
attr_reader :kind
|
25
|
+
|
26
|
+
def initialize(kind)
|
27
|
+
@kind = kind
|
25
28
|
end
|
26
29
|
|
27
30
|
# Coerces a given value to this type
|
@@ -48,12 +51,6 @@ module Cassandra
|
|
48
51
|
module Types; extend self
|
49
52
|
# @private
|
50
53
|
class Simple < Type
|
51
|
-
attr_reader :kind
|
52
|
-
|
53
|
-
def initialize(kind)
|
54
|
-
@kind = kind
|
55
|
-
end
|
56
|
-
|
57
54
|
def new(value)
|
58
55
|
__send__(:"new_#{@kind}", value)
|
59
56
|
end
|
@@ -67,6 +64,10 @@ module Cassandra
|
|
67
64
|
@kind.to_s
|
68
65
|
end
|
69
66
|
|
67
|
+
def hash
|
68
|
+
@hash ||= 31 * 17 + @kind.hash
|
69
|
+
end
|
70
|
+
|
70
71
|
def eql?(other)
|
71
72
|
other.is_a?(Simple) && @kind == other.kind
|
72
73
|
end
|
@@ -86,96 +87,96 @@ module Cassandra
|
|
86
87
|
String(value)
|
87
88
|
end
|
88
89
|
|
89
|
-
def assert_text(
|
90
|
-
Util.assert_instance_of(::String,
|
90
|
+
def assert_text(value, message, &block)
|
91
|
+
Util.assert_instance_of(::String, value, message, &block)
|
91
92
|
end
|
92
93
|
|
93
94
|
def new_blob(value)
|
94
95
|
String(value)
|
95
96
|
end
|
96
97
|
|
97
|
-
def assert_blob(
|
98
|
-
Util.assert_instance_of(::String,
|
98
|
+
def assert_blob(value, message, &block)
|
99
|
+
Util.assert_instance_of(::String, value, message, &block)
|
99
100
|
end
|
100
101
|
|
101
102
|
def new_ascii(value)
|
102
103
|
String(value)
|
103
104
|
end
|
104
105
|
|
105
|
-
def assert_ascii(
|
106
|
-
Util.assert_instance_of(::String,
|
106
|
+
def assert_ascii(value, message, &block)
|
107
|
+
Util.assert_instance_of(::String, value, message, &block)
|
107
108
|
end
|
108
109
|
|
109
110
|
def new_bigint(value)
|
110
111
|
Integer(value)
|
111
112
|
end
|
112
113
|
|
113
|
-
def assert_bigint(
|
114
|
-
Util.assert_instance_of(::Integer,
|
114
|
+
def assert_bigint(value, message, &block)
|
115
|
+
Util.assert_instance_of(::Integer, value, message, &block)
|
115
116
|
end
|
116
117
|
|
117
118
|
def new_counter(value)
|
118
119
|
Integer(value)
|
119
120
|
end
|
120
121
|
|
121
|
-
def assert_counter(
|
122
|
-
Util.assert_instance_of(::Integer,
|
122
|
+
def assert_counter(value, message, &block)
|
123
|
+
Util.assert_instance_of(::Integer, value, message, &block)
|
123
124
|
end
|
124
125
|
|
125
126
|
def new_int(value)
|
126
127
|
Integer(value)
|
127
128
|
end
|
128
129
|
|
129
|
-
def assert_int(
|
130
|
-
Util.assert_instance_of(::Integer,
|
130
|
+
def assert_int(value, message, &block)
|
131
|
+
Util.assert_instance_of(::Integer, value, message, &block)
|
131
132
|
end
|
132
133
|
|
133
134
|
def new_varint(value)
|
134
135
|
Integer(value)
|
135
136
|
end
|
136
137
|
|
137
|
-
def assert_varint(
|
138
|
-
Util.assert_instance_of(::Integer,
|
138
|
+
def assert_varint(value, message, &block)
|
139
|
+
Util.assert_instance_of(::Integer, value, message, &block)
|
139
140
|
end
|
140
141
|
|
141
142
|
def new_boolean(value)
|
142
143
|
!!value
|
143
144
|
end
|
144
145
|
|
145
|
-
def assert_boolean(
|
146
|
-
Util.assert_instance_of_one_of([::TrueClass, ::FalseClass],
|
146
|
+
def assert_boolean(value, message, &block)
|
147
|
+
Util.assert_instance_of_one_of([::TrueClass, ::FalseClass], value, message, &block)
|
147
148
|
end
|
148
149
|
|
149
150
|
def new_decimal(value)
|
150
151
|
::BigDecimal.new(value)
|
151
152
|
end
|
152
153
|
|
153
|
-
def assert_decimal(
|
154
|
-
Util.assert_instance_of(::BigDecimal,
|
154
|
+
def assert_decimal(value, message, &block)
|
155
|
+
Util.assert_instance_of(::BigDecimal, value, message, &block)
|
155
156
|
end
|
156
157
|
|
157
158
|
def new_double(value)
|
158
159
|
Float(value)
|
159
160
|
end
|
160
161
|
|
161
|
-
def assert_double(
|
162
|
-
Util.assert_instance_of(::Float,
|
162
|
+
def assert_double(value, message, &block)
|
163
|
+
Util.assert_instance_of(::Float, value, message, &block)
|
163
164
|
end
|
164
165
|
|
165
166
|
def new_float(value)
|
166
167
|
Float(value)
|
167
168
|
end
|
168
169
|
|
169
|
-
def assert_float(
|
170
|
-
Util.assert_instance_of(::Float,
|
170
|
+
def assert_float(value, message, &block)
|
171
|
+
Util.assert_instance_of(::Float, value, message, &block)
|
171
172
|
end
|
172
173
|
|
173
174
|
def new_inet(value)
|
174
175
|
::IPAddr.new(value)
|
175
176
|
end
|
176
177
|
|
177
|
-
def assert_inet(
|
178
|
-
Util.assert_instance_of(::IPAddr,
|
178
|
+
def assert_inet(value, message, &block)
|
179
|
+
Util.assert_instance_of(::IPAddr, value, message, &block)
|
179
180
|
end
|
180
181
|
|
181
182
|
def new_timestamp(value)
|
@@ -188,122 +189,72 @@ module Cassandra
|
|
188
189
|
end
|
189
190
|
end
|
190
191
|
|
191
|
-
def assert_timestamp(
|
192
|
-
Util.assert_instance_of(::Time,
|
192
|
+
def assert_timestamp(value, message, &block)
|
193
|
+
Util.assert_instance_of(::Time, value, message, &block)
|
193
194
|
end
|
194
195
|
|
195
|
-
def new_uuid(
|
196
|
+
def new_uuid(value, message, &block)
|
196
197
|
Cassandra::Uuid.new(value)
|
197
198
|
end
|
198
199
|
|
199
|
-
def assert_uuid(
|
200
|
-
Util.assert_instance_of(Cassandra::Uuid,
|
200
|
+
def assert_uuid(value, message, &block)
|
201
|
+
Util.assert_instance_of(Cassandra::Uuid, value, message, &block)
|
201
202
|
end
|
202
203
|
|
203
204
|
def new_timeuuid(value)
|
204
205
|
Cassandra::TimeUuid.new(value)
|
205
206
|
end
|
206
207
|
|
207
|
-
def assert_timeuuid(
|
208
|
-
Util.assert_instance_of(Cassandra::TimeUuid,
|
208
|
+
def assert_timeuuid(value, message, &block)
|
209
|
+
Util.assert_instance_of(Cassandra::TimeUuid, value, message, &block)
|
209
210
|
end
|
210
|
-
end
|
211
211
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
# # @return [String] value
|
222
|
-
# # @see Cassandra::Type#new
|
223
|
-
# def new(value)
|
224
|
-
# end
|
225
|
-
#
|
226
|
-
# # Asserts that a given value is a String
|
227
|
-
# # @param value [Object] value to be validated
|
228
|
-
# # @param message [String] error message to use when assertion
|
229
|
-
# # fails
|
230
|
-
# # @yieldreturn [String] error message to use when assertion fails
|
231
|
-
# # @raise [ArgumentError] if the value is not a String
|
232
|
-
# # @return [void]
|
233
|
-
# # @see Cassandra::Type#assert
|
234
|
-
# def assert(value, message = nil, &block)
|
235
|
-
# end
|
236
|
-
#
|
237
|
-
# # @return [String] `"varchar"`
|
238
|
-
# # @see Cassandra::Type#to_s
|
239
|
-
# def to_s
|
240
|
-
# end
|
241
|
-
# end
|
242
|
-
const_set('Varchar', Simple.new(:varchar))
|
212
|
+
def new_date(value)
|
213
|
+
case value
|
214
|
+
when ::Date
|
215
|
+
value
|
216
|
+
else
|
217
|
+
return value.to_date if value.respond_to?(:to_date)
|
218
|
+
raise ::ArgumentError, "cannot convert #{value.inspect} to date"
|
219
|
+
end
|
220
|
+
end
|
243
221
|
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
# # @see Cassandra::Type#kind
|
248
|
-
# def kind
|
249
|
-
# end
|
250
|
-
#
|
251
|
-
# # Coerces the value to String
|
252
|
-
# # @param value [Object] original value
|
253
|
-
# # @return [String] value
|
254
|
-
# # @see Cassandra::Type#new
|
255
|
-
# def new(value)
|
256
|
-
# end
|
257
|
-
#
|
258
|
-
# # Asserts that a given value is a String
|
259
|
-
# # @param value [Object] value to be validated
|
260
|
-
# # @param message [String] error message to use when assertion
|
261
|
-
# # fails
|
262
|
-
# # @yieldreturn [String] error message to use when assertion fails
|
263
|
-
# # @raise [ArgumentError] if the value is not a String
|
264
|
-
# # @return [void]
|
265
|
-
# # @see Cassandra::Type#assert
|
266
|
-
# def assert(value, message = nil, &block)
|
267
|
-
# end
|
268
|
-
#
|
269
|
-
# # @return [String] `"text"`
|
270
|
-
# # @see Cassandra::Type#to_s
|
271
|
-
# def to_s
|
272
|
-
# end
|
273
|
-
# end
|
274
|
-
const_set('Text', Simple.new(:text))
|
222
|
+
def assert_date(value, message, &block)
|
223
|
+
Util.assert_instance_of(::Date, value, message, &block)
|
224
|
+
end
|
275
225
|
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
226
|
+
def new_smallint(value)
|
227
|
+
Integer(value)
|
228
|
+
end
|
229
|
+
|
230
|
+
def assert_smallint(value, message, &block)
|
231
|
+
Util.assert_instance_of(::Integer, value, message, &block)
|
232
|
+
Util.assert(value <= 32767 && value >= -32768, message, &block)
|
233
|
+
end
|
234
|
+
|
235
|
+
def new_time(value)
|
236
|
+
case value
|
237
|
+
when ::Integer
|
238
|
+
Time.new(value)
|
239
|
+
else
|
240
|
+
return Time.new(value.to_nanoseconds) if value.respond_to?(:to_nanoseconds)
|
241
|
+
raise ::ArgumentError, "cannot convert #{value.inspect} to time"
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def assert_time(value, message, &block)
|
246
|
+
Util.assert_instance_of(Cassandra::Time, value, message, &block)
|
247
|
+
end
|
248
|
+
|
249
|
+
def new_tinyint(value)
|
250
|
+
Integer(value)
|
251
|
+
end
|
252
|
+
|
253
|
+
def assert_tinyint(value, message, &block)
|
254
|
+
Util.assert_instance_of(::Integer, value, message, &block)
|
255
|
+
Util.assert(value <= 127 && value >= -128, message, &block)
|
256
|
+
end
|
257
|
+
end
|
307
258
|
|
308
259
|
# @!parse
|
309
260
|
# class Ascii < Type
|
@@ -370,72 +321,72 @@ module Cassandra
|
|
370
321
|
const_set('Bigint', Simple.new(:bigint))
|
371
322
|
|
372
323
|
# @!parse
|
373
|
-
# class
|
374
|
-
# # @return [Symbol] `:
|
324
|
+
# class Blob < Type
|
325
|
+
# # @return [Symbol] `:blob`
|
375
326
|
# # @see Cassandra::Type#kind
|
376
327
|
# def kind
|
377
328
|
# end
|
378
329
|
#
|
379
|
-
# # Coerces the value to
|
330
|
+
# # Coerces the value to String
|
380
331
|
# # @param value [Object] original value
|
381
|
-
# # @return [
|
332
|
+
# # @return [String] value
|
382
333
|
# # @see Cassandra::Type#new
|
383
334
|
# def new(value)
|
384
335
|
# end
|
385
336
|
#
|
386
|
-
# # Asserts that a given value is
|
337
|
+
# # Asserts that a given value is a String
|
387
338
|
# # @param value [Object] value to be validated
|
388
339
|
# # @param message [String] error message to use when assertion
|
389
340
|
# # fails
|
390
341
|
# # @yieldreturn [String] error message to use when assertion fails
|
391
|
-
# # @raise [ArgumentError] if the value is not
|
342
|
+
# # @raise [ArgumentError] if the value is not a String
|
392
343
|
# # @return [void]
|
393
344
|
# # @see Cassandra::Type#assert
|
394
345
|
# def assert(value, message = nil, &block)
|
395
346
|
# end
|
396
347
|
#
|
397
|
-
# # @return [String] `"
|
348
|
+
# # @return [String] `"blob"`
|
398
349
|
# # @see Cassandra::Type#to_s
|
399
350
|
# def to_s
|
400
351
|
# end
|
401
352
|
# end
|
402
|
-
const_set('
|
353
|
+
const_set('Blob', Simple.new(:blob))
|
403
354
|
|
404
355
|
# @!parse
|
405
|
-
# class
|
406
|
-
# # @return [Symbol] `:
|
356
|
+
# class Boolean < Type
|
357
|
+
# # @return [Symbol] `:boolean`
|
407
358
|
# # @see Cassandra::Type#kind
|
408
359
|
# def kind
|
409
360
|
# end
|
410
361
|
#
|
411
|
-
# # Coerces the value to
|
362
|
+
# # Coerces the value to `true` or `false`
|
412
363
|
# # @param value [Object] original value
|
413
|
-
# # @return [
|
364
|
+
# # @return [Boolean] value
|
414
365
|
# # @see Cassandra::Type#new
|
415
366
|
# def new(value)
|
416
367
|
# end
|
417
368
|
#
|
418
|
-
# # Asserts that a given value is
|
369
|
+
# # Asserts that a given value is a `true` or `false`
|
419
370
|
# # @param value [Object] value to be validated
|
420
371
|
# # @param message [String] error message to use when assertion
|
421
372
|
# # fails
|
422
373
|
# # @yieldreturn [String] error message to use when assertion fails
|
423
|
-
# # @raise [ArgumentError] if the value is not
|
374
|
+
# # @raise [ArgumentError] if the value is not `true` or `false`
|
424
375
|
# # @return [void]
|
425
376
|
# # @see Cassandra::Type#assert
|
426
377
|
# def assert(value, message = nil, &block)
|
427
378
|
# end
|
428
379
|
#
|
429
|
-
# # @return [String] `"
|
380
|
+
# # @return [String] `"boolean"`
|
430
381
|
# # @see Cassandra::Type#to_s
|
431
382
|
# def to_s
|
432
383
|
# end
|
433
384
|
# end
|
434
|
-
const_set('
|
385
|
+
const_set('Boolean', Simple.new(:boolean))
|
435
386
|
|
436
387
|
# @!parse
|
437
|
-
# class
|
438
|
-
# # @return [Symbol] `:
|
388
|
+
# class Counter < Type
|
389
|
+
# # @return [Symbol] `:counter`
|
439
390
|
# # @see Cassandra::Type#kind
|
440
391
|
# def kind
|
441
392
|
# end
|
@@ -458,44 +409,44 @@ module Cassandra
|
|
458
409
|
# def assert(value, message = nil, &block)
|
459
410
|
# end
|
460
411
|
#
|
461
|
-
# # @return [String] `"
|
412
|
+
# # @return [String] `"counter"`
|
462
413
|
# # @see Cassandra::Type#to_s
|
463
414
|
# def to_s
|
464
415
|
# end
|
465
416
|
# end
|
466
|
-
const_set('
|
417
|
+
const_set('Counter', Simple.new(:counter))
|
467
418
|
|
468
419
|
# @!parse
|
469
|
-
# class
|
470
|
-
# # @return [Symbol] `:
|
420
|
+
# class Date < Type
|
421
|
+
# # @return [Symbol] `:date`
|
471
422
|
# # @see Cassandra::Type#kind
|
472
423
|
# def kind
|
473
424
|
# end
|
474
425
|
#
|
475
|
-
# # Coerces the value to
|
426
|
+
# # Coerces the value to Date
|
476
427
|
# # @param value [Object] original value
|
477
|
-
# # @return [
|
428
|
+
# # @return [Date] value
|
478
429
|
# # @see Cassandra::Type#new
|
479
430
|
# def new(value)
|
480
431
|
# end
|
481
432
|
#
|
482
|
-
# # Asserts that a given value is a
|
433
|
+
# # Asserts that a given value is a Date
|
483
434
|
# # @param value [Object] value to be validated
|
484
435
|
# # @param message [String] error message to use when assertion
|
485
436
|
# # fails
|
486
437
|
# # @yieldreturn [String] error message to use when assertion fails
|
487
|
-
# # @raise [ArgumentError] if the value is not
|
438
|
+
# # @raise [ArgumentError] if the value is not a Date
|
488
439
|
# # @return [void]
|
489
440
|
# # @see Cassandra::Type#assert
|
490
441
|
# def assert(value, message = nil, &block)
|
491
442
|
# end
|
492
443
|
#
|
493
|
-
# # @return [String] `"
|
444
|
+
# # @return [String] `"date"`
|
494
445
|
# # @see Cassandra::Type#to_s
|
495
446
|
# def to_s
|
496
447
|
# end
|
497
448
|
# end
|
498
|
-
const_set('
|
449
|
+
const_set('Date', Simple.new(:date))
|
499
450
|
|
500
451
|
# @!parse
|
501
452
|
# class Decimal < Type
|
@@ -626,100 +577,36 @@ module Cassandra
|
|
626
577
|
const_set('Inet', Simple.new(:inet))
|
627
578
|
|
628
579
|
# @!parse
|
629
|
-
# class
|
630
|
-
# # @return [Symbol] `:
|
631
|
-
# # @see Cassandra::Type#kind
|
632
|
-
# def kind
|
633
|
-
# end
|
634
|
-
#
|
635
|
-
# # Coerces the value to Time
|
636
|
-
# # @param value [Object] original value
|
637
|
-
# # @return [Time] value
|
638
|
-
# # @see Cassandra::Type#new
|
639
|
-
# def new(value)
|
640
|
-
# end
|
641
|
-
#
|
642
|
-
# # Asserts that a given value is a Time
|
643
|
-
# # @param value [Object] value to be validated
|
644
|
-
# # @param message [String] error message to use when assertion
|
645
|
-
# # fails
|
646
|
-
# # @yieldreturn [String] error message to use when assertion fails
|
647
|
-
# # @raise [ArgumentError] if the value is not a Time
|
648
|
-
# # @return [void]
|
649
|
-
# # @see Cassandra::Type#assert
|
650
|
-
# def assert(value, message = nil, &block)
|
651
|
-
# end
|
652
|
-
#
|
653
|
-
# # @return [String] `"timestamp"`
|
654
|
-
# # @see Cassandra::Type#to_s
|
655
|
-
# def to_s
|
656
|
-
# end
|
657
|
-
# end
|
658
|
-
const_set('Timestamp', Simple.new(:timestamp))
|
659
|
-
|
660
|
-
# @!parse
|
661
|
-
# class Uuid < Type
|
662
|
-
# # @return [Symbol] `:uuid`
|
663
|
-
# # @see Cassandra::Type#kind
|
664
|
-
# def kind
|
665
|
-
# end
|
666
|
-
#
|
667
|
-
# # Coerces the value to Cassandra::Uuid
|
668
|
-
# # @param value [Object] original value
|
669
|
-
# # @return [Cassandra::Uuid] value
|
670
|
-
# # @see Cassandra::Type#new
|
671
|
-
# def new(value)
|
672
|
-
# end
|
673
|
-
#
|
674
|
-
# # Asserts that a given value is a Cassandra::Uuid
|
675
|
-
# # @param value [Object] value to be validated
|
676
|
-
# # @param message [String] error message to use when assertion
|
677
|
-
# # fails
|
678
|
-
# # @yieldreturn [String] error message to use when assertion fails
|
679
|
-
# # @raise [ArgumentError] if the value is not a Cassandra::Uuid
|
680
|
-
# # @return [void]
|
681
|
-
# # @see Cassandra::Type#assert
|
682
|
-
# def assert(value, message = nil, &block)
|
683
|
-
# end
|
684
|
-
#
|
685
|
-
# # @return [String] `"uuid"`
|
686
|
-
# # @see Cassandra::Type#to_s
|
687
|
-
# def to_s
|
688
|
-
# end
|
689
|
-
# end
|
690
|
-
const_set('Uuid', Simple.new(:uuid))
|
691
|
-
|
692
|
-
# @!parse
|
693
|
-
# class Timeuuid < Type
|
694
|
-
# # @return [Symbol] `:timeuuid`
|
580
|
+
# class Int < Type
|
581
|
+
# # @return [Symbol] `:int`
|
695
582
|
# # @see Cassandra::Type#kind
|
696
583
|
# def kind
|
697
584
|
# end
|
698
585
|
#
|
699
|
-
# # Coerces the value to
|
586
|
+
# # Coerces the value to Integer
|
700
587
|
# # @param value [Object] original value
|
701
|
-
# # @return [
|
588
|
+
# # @return [Integer] value
|
702
589
|
# # @see Cassandra::Type#new
|
703
590
|
# def new(value)
|
704
591
|
# end
|
705
592
|
#
|
706
|
-
# # Asserts that a given value is
|
593
|
+
# # Asserts that a given value is an Integer
|
707
594
|
# # @param value [Object] value to be validated
|
708
595
|
# # @param message [String] error message to use when assertion
|
709
596
|
# # fails
|
710
597
|
# # @yieldreturn [String] error message to use when assertion fails
|
711
|
-
# # @raise [ArgumentError] if the value is not
|
598
|
+
# # @raise [ArgumentError] if the value is not an Integer
|
712
599
|
# # @return [void]
|
713
600
|
# # @see Cassandra::Type#assert
|
714
601
|
# def assert(value, message = nil, &block)
|
715
602
|
# end
|
716
603
|
#
|
717
|
-
# # @return [String] `"
|
604
|
+
# # @return [String] `"int"`
|
718
605
|
# # @see Cassandra::Type#to_s
|
719
606
|
# def to_s
|
720
607
|
# end
|
721
608
|
# end
|
722
|
-
const_set('
|
609
|
+
const_set('Int', Simple.new(:int))
|
723
610
|
|
724
611
|
class List < Type
|
725
612
|
# @private
|
@@ -727,15 +614,10 @@ module Cassandra
|
|
727
614
|
|
728
615
|
# @private
|
729
616
|
def initialize(value_type)
|
617
|
+
super(:list)
|
730
618
|
@value_type = value_type
|
731
619
|
end
|
732
620
|
|
733
|
-
# @return [Symbol] `:list`
|
734
|
-
# @see Cassandra::Type#kind
|
735
|
-
def kind
|
736
|
-
:list
|
737
|
-
end
|
738
|
-
|
739
621
|
# Coerces the value to Array
|
740
622
|
# @param value [Object] original value
|
741
623
|
# @return [Array] value
|
@@ -770,6 +652,15 @@ module Cassandra
|
|
770
652
|
"list<#{@value_type.to_s}>"
|
771
653
|
end
|
772
654
|
|
655
|
+
def hash
|
656
|
+
@hash ||= begin
|
657
|
+
h = 17
|
658
|
+
h = 31 * h + @kind.hash
|
659
|
+
h = 31 * h + @value_type.hash
|
660
|
+
h
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
773
664
|
def eql?(other)
|
774
665
|
other.is_a?(List) && @value_type == other.value_type
|
775
666
|
end
|
@@ -782,16 +673,11 @@ module Cassandra
|
|
782
673
|
|
783
674
|
# @private
|
784
675
|
def initialize(key_type, value_type)
|
676
|
+
super(:map)
|
785
677
|
@key_type = key_type
|
786
678
|
@value_type = value_type
|
787
679
|
end
|
788
680
|
|
789
|
-
# @return [Symbol] `:map`
|
790
|
-
# @see Cassandra::Type#kind
|
791
|
-
def kind
|
792
|
-
:map
|
793
|
-
end
|
794
|
-
|
795
681
|
# Coerces the value to Hash
|
796
682
|
# @param value [Object] original value
|
797
683
|
# @return [Hash] value
|
@@ -841,6 +727,16 @@ module Cassandra
|
|
841
727
|
"map<#{@key_type.to_s}, #{@value_type.to_s}>"
|
842
728
|
end
|
843
729
|
|
730
|
+
def hash
|
731
|
+
@hash ||= begin
|
732
|
+
h = 17
|
733
|
+
h = 31 * h + @kind.hash
|
734
|
+
h = 31 * h + @key_type.hash
|
735
|
+
h = 31 * h + @value_type.hash
|
736
|
+
h
|
737
|
+
end
|
738
|
+
end
|
739
|
+
|
844
740
|
def eql?(other)
|
845
741
|
other.is_a?(Map) &&
|
846
742
|
@key_type == other.key_type &&
|
@@ -855,15 +751,10 @@ module Cassandra
|
|
855
751
|
|
856
752
|
# @private
|
857
753
|
def initialize(value_type)
|
754
|
+
super(:set)
|
858
755
|
@value_type = value_type
|
859
756
|
end
|
860
757
|
|
861
|
-
# @return [Symbol] `:set`
|
862
|
-
# @see Cassandra::Type#kind
|
863
|
-
def kind
|
864
|
-
:set
|
865
|
-
end
|
866
|
-
|
867
758
|
# Coerces the value to Set
|
868
759
|
# @param value [Object] original value
|
869
760
|
# @return [Set] value
|
@@ -925,27 +816,223 @@ module Cassandra
|
|
925
816
|
"set<#{@value_type.to_s}>"
|
926
817
|
end
|
927
818
|
|
819
|
+
def hash
|
820
|
+
@hash ||= begin
|
821
|
+
h = 17
|
822
|
+
h = 31 * h + @kind.hash
|
823
|
+
h = 31 * h + @value_type.hash
|
824
|
+
h
|
825
|
+
end
|
826
|
+
end
|
827
|
+
|
928
828
|
def eql?(other)
|
929
829
|
other.is_a?(Set) && @value_type == other.value_type
|
930
830
|
end
|
931
831
|
alias :== :eql?
|
932
832
|
end
|
933
833
|
|
834
|
+
# @!parse
|
835
|
+
# class Smallint < Type
|
836
|
+
# # @return [Symbol] `:smallint`
|
837
|
+
# # @see Cassandra::Type#kind
|
838
|
+
# def kind
|
839
|
+
# end
|
840
|
+
#
|
841
|
+
# # Coerces the value to an Integer
|
842
|
+
# # @param value [Object] original value
|
843
|
+
# # @return [Integer] value
|
844
|
+
# # @see Cassandra::Type#new
|
845
|
+
# def new(value)
|
846
|
+
# end
|
847
|
+
#
|
848
|
+
# # Asserts that a given value is an Integer
|
849
|
+
# # @param value [Object] value to be validated
|
850
|
+
# # @param message [String] error message to use when assertion
|
851
|
+
# # fails
|
852
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
853
|
+
# # @raise [ArgumentError] if the value is not an Integer
|
854
|
+
# # @return [void]
|
855
|
+
# # @see Cassandra::Type#assert
|
856
|
+
# def assert(value, message = nil, &block)
|
857
|
+
# end
|
858
|
+
#
|
859
|
+
# # @return [String] `"smallint"`
|
860
|
+
# # @see Cassandra::Type#to_s
|
861
|
+
# def to_s
|
862
|
+
# end
|
863
|
+
# end
|
864
|
+
const_set('Smallint', Simple.new(:smallint))
|
865
|
+
|
866
|
+
# @!parse
|
867
|
+
# class Text < Type
|
868
|
+
# # @return [Symbol] `:text`
|
869
|
+
# # @see Cassandra::Type#kind
|
870
|
+
# def kind
|
871
|
+
# end
|
872
|
+
#
|
873
|
+
# # Coerces the value to String
|
874
|
+
# # @param value [Object] original value
|
875
|
+
# # @return [String] value
|
876
|
+
# # @see Cassandra::Type#new
|
877
|
+
# def new(value)
|
878
|
+
# end
|
879
|
+
#
|
880
|
+
# # Asserts that a given value is a String
|
881
|
+
# # @param value [Object] value to be validated
|
882
|
+
# # @param message [String] error message to use when assertion
|
883
|
+
# # fails
|
884
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
885
|
+
# # @raise [ArgumentError] if the value is not a String
|
886
|
+
# # @return [void]
|
887
|
+
# # @see Cassandra::Type#assert
|
888
|
+
# def assert(value, message = nil, &block)
|
889
|
+
# end
|
890
|
+
#
|
891
|
+
# # @return [String] `"text"`
|
892
|
+
# # @see Cassandra::Type#to_s
|
893
|
+
# def to_s
|
894
|
+
# end
|
895
|
+
# end
|
896
|
+
const_set('Text', Simple.new(:text))
|
897
|
+
|
898
|
+
# @!parse
|
899
|
+
# class Time < Type
|
900
|
+
# # @return [Symbol] `:time`
|
901
|
+
# # @see Cassandra::Type#kind
|
902
|
+
# def kind
|
903
|
+
# end
|
904
|
+
#
|
905
|
+
# # Coerces the value to Time
|
906
|
+
# # @param value [Object] original value
|
907
|
+
# # @return [Time] value
|
908
|
+
# # @see Cassandra::Type#new
|
909
|
+
# def new(value)
|
910
|
+
# end
|
911
|
+
#
|
912
|
+
# # Asserts that a given value is a Time
|
913
|
+
# # @param value [Object] value to be validated
|
914
|
+
# # @param message [String] error message to use when assertion
|
915
|
+
# # fails
|
916
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
917
|
+
# # @raise [ArgumentError] if the value is not a String
|
918
|
+
# # @return [void]
|
919
|
+
# # @see Cassandra::Type#assert
|
920
|
+
# def assert(value, message = nil, &block)
|
921
|
+
# end
|
922
|
+
#
|
923
|
+
# # @return [String] `"time"`
|
924
|
+
# # @see Cassandra::Type#to_s
|
925
|
+
# def to_s
|
926
|
+
# end
|
927
|
+
# end
|
928
|
+
const_set('Time', Simple.new(:time))
|
929
|
+
|
930
|
+
# @!parse
|
931
|
+
# class Timestamp < Type
|
932
|
+
# # @return [Symbol] `:timestamp`
|
933
|
+
# # @see Cassandra::Type#kind
|
934
|
+
# def kind
|
935
|
+
# end
|
936
|
+
#
|
937
|
+
# # Coerces the value to Time
|
938
|
+
# # @param value [Object] original value
|
939
|
+
# # @return [Time] value
|
940
|
+
# # @see Cassandra::Type#new
|
941
|
+
# def new(value)
|
942
|
+
# end
|
943
|
+
#
|
944
|
+
# # Asserts that a given value is a Time
|
945
|
+
# # @param value [Object] value to be validated
|
946
|
+
# # @param message [String] error message to use when assertion
|
947
|
+
# # fails
|
948
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
949
|
+
# # @raise [ArgumentError] if the value is not a Time
|
950
|
+
# # @return [void]
|
951
|
+
# # @see Cassandra::Type#assert
|
952
|
+
# def assert(value, message = nil, &block)
|
953
|
+
# end
|
954
|
+
#
|
955
|
+
# # @return [String] `"timestamp"`
|
956
|
+
# # @see Cassandra::Type#to_s
|
957
|
+
# def to_s
|
958
|
+
# end
|
959
|
+
# end
|
960
|
+
const_set('Timestamp', Simple.new(:timestamp))
|
961
|
+
|
962
|
+
# @!parse
|
963
|
+
# class Timeuuid < Type
|
964
|
+
# # @return [Symbol] `:timeuuid`
|
965
|
+
# # @see Cassandra::Type#kind
|
966
|
+
# def kind
|
967
|
+
# end
|
968
|
+
#
|
969
|
+
# # Coerces the value to Cassandra::Timeuuid
|
970
|
+
# # @param value [Object] original value
|
971
|
+
# # @return [Cassandra::Timeuuid] value
|
972
|
+
# # @see Cassandra::Type#new
|
973
|
+
# def new(value)
|
974
|
+
# end
|
975
|
+
#
|
976
|
+
# # Asserts that a given value is a Cassandra::Timeuuid
|
977
|
+
# # @param value [Object] value to be validated
|
978
|
+
# # @param message [String] error message to use when assertion
|
979
|
+
# # fails
|
980
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
981
|
+
# # @raise [ArgumentError] if the value is not a Cassandra::Timeuuid
|
982
|
+
# # @return [void]
|
983
|
+
# # @see Cassandra::Type#assert
|
984
|
+
# def assert(value, message = nil, &block)
|
985
|
+
# end
|
986
|
+
#
|
987
|
+
# # @return [String] `"timeuuid"`
|
988
|
+
# # @see Cassandra::Type#to_s
|
989
|
+
# def to_s
|
990
|
+
# end
|
991
|
+
# end
|
992
|
+
const_set('Timeuuid', Simple.new(:timeuuid))
|
993
|
+
|
994
|
+
# @!parse
|
995
|
+
# class Tinyint < Type
|
996
|
+
# # @return [Symbol] `:tinyint`
|
997
|
+
# # @see Cassandra::Type#kind
|
998
|
+
# def kind
|
999
|
+
# end
|
1000
|
+
#
|
1001
|
+
# # Coerces the value to Integer
|
1002
|
+
# # @param value [Object] original value
|
1003
|
+
# # @return [Integer] value
|
1004
|
+
# # @see Cassandra::Type#new
|
1005
|
+
# def new(value)
|
1006
|
+
# end
|
1007
|
+
#
|
1008
|
+
# # Asserts that a given value is an Integer
|
1009
|
+
# # @param value [Object] value to be validated
|
1010
|
+
# # @param message [String] error message to use when assertion
|
1011
|
+
# # fails
|
1012
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
1013
|
+
# # @raise [ArgumentError] if the value is not an Integer
|
1014
|
+
# # @return [void]
|
1015
|
+
# # @see Cassandra::Type#assert
|
1016
|
+
# def assert(value, message = nil, &block)
|
1017
|
+
# end
|
1018
|
+
#
|
1019
|
+
# # @return [String] `"tinyint"`
|
1020
|
+
# # @see Cassandra::Type#to_s
|
1021
|
+
# def to_s
|
1022
|
+
# end
|
1023
|
+
# end
|
1024
|
+
const_set('Tinyint', Simple.new(:tinyint))
|
1025
|
+
|
934
1026
|
class Tuple < Type
|
935
1027
|
# @private
|
936
1028
|
attr_reader :members
|
937
1029
|
|
938
1030
|
# @private
|
939
1031
|
def initialize(*members)
|
1032
|
+
super(:tuple)
|
940
1033
|
@members = members
|
941
1034
|
end
|
942
1035
|
|
943
|
-
# @return [Symbol] `:tuple`
|
944
|
-
# @see Cassandra::Type#kind
|
945
|
-
def kind
|
946
|
-
:tuple
|
947
|
-
end
|
948
|
-
|
949
1036
|
# Coerces the value to Cassandra::Tuple
|
950
1037
|
# @param values [*Object] tuple values
|
951
1038
|
# @return [Cassandra::Tuple] value
|
@@ -984,12 +1071,85 @@ module Cassandra
|
|
984
1071
|
"tuple<#{@members.map(&:to_s).join(', ')}>"
|
985
1072
|
end
|
986
1073
|
|
1074
|
+
def hash
|
1075
|
+
@hash ||= begin
|
1076
|
+
h = 17
|
1077
|
+
h = 31 * h + @kind.hash
|
1078
|
+
h = 31 * h + @members.hash
|
1079
|
+
h
|
1080
|
+
end
|
1081
|
+
end
|
1082
|
+
|
987
1083
|
def eql?(other)
|
988
1084
|
other.is_a?(Tuple) && @members == other.members
|
989
1085
|
end
|
990
1086
|
alias :== :eql?
|
991
1087
|
end
|
992
1088
|
|
1089
|
+
# @!parse
|
1090
|
+
# class Uuid < Type
|
1091
|
+
# # @return [Symbol] `:uuid`
|
1092
|
+
# # @see Cassandra::Type#kind
|
1093
|
+
# def kind
|
1094
|
+
# end
|
1095
|
+
#
|
1096
|
+
# # Coerces the value to Cassandra::Uuid
|
1097
|
+
# # @param value [Object] original value
|
1098
|
+
# # @return [Cassandra::Uuid] value
|
1099
|
+
# # @see Cassandra::Type#new
|
1100
|
+
# def new(value)
|
1101
|
+
# end
|
1102
|
+
#
|
1103
|
+
# # Asserts that a given value is a Cassandra::Uuid
|
1104
|
+
# # @param value [Object] value to be validated
|
1105
|
+
# # @param message [String] error message to use when assertion
|
1106
|
+
# # fails
|
1107
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
1108
|
+
# # @raise [ArgumentError] if the value is not a Cassandra::Uuid
|
1109
|
+
# # @return [void]
|
1110
|
+
# # @see Cassandra::Type#assert
|
1111
|
+
# def assert(value, message = nil, &block)
|
1112
|
+
# end
|
1113
|
+
#
|
1114
|
+
# # @return [String] `"uuid"`
|
1115
|
+
# # @see Cassandra::Type#to_s
|
1116
|
+
# def to_s
|
1117
|
+
# end
|
1118
|
+
# end
|
1119
|
+
const_set('Uuid', Simple.new(:uuid))
|
1120
|
+
|
1121
|
+
# @!parse
|
1122
|
+
# class Varint < Type
|
1123
|
+
# # @return [Symbol] `:varint`
|
1124
|
+
# # @see Cassandra::Type#kind
|
1125
|
+
# def kind
|
1126
|
+
# end
|
1127
|
+
#
|
1128
|
+
# # Coerces the value to Integer
|
1129
|
+
# # @param value [Object] original value
|
1130
|
+
# # @return [Integer] value
|
1131
|
+
# # @see Cassandra::Type#new
|
1132
|
+
# def new(value)
|
1133
|
+
# end
|
1134
|
+
#
|
1135
|
+
# # Asserts that a given value is an Integer
|
1136
|
+
# # @param value [Object] value to be validated
|
1137
|
+
# # @param message [String] error message to use when assertion
|
1138
|
+
# # fails
|
1139
|
+
# # @yieldreturn [String] error message to use when assertion fails
|
1140
|
+
# # @raise [ArgumentError] if the value is not an Integer
|
1141
|
+
# # @return [void]
|
1142
|
+
# # @see Cassandra::Type#assert
|
1143
|
+
# def assert(value, message = nil, &block)
|
1144
|
+
# end
|
1145
|
+
#
|
1146
|
+
# # @return [String] `"varint"`
|
1147
|
+
# # @see Cassandra::Type#to_s
|
1148
|
+
# def to_s
|
1149
|
+
# end
|
1150
|
+
# end
|
1151
|
+
const_set('Varint', Simple.new(:varint))
|
1152
|
+
|
993
1153
|
class UserDefined < Type
|
994
1154
|
class Field
|
995
1155
|
# @return [String] name of this field
|
@@ -1009,6 +1169,15 @@ module Cassandra
|
|
1009
1169
|
"#{@name} #{@type}"
|
1010
1170
|
end
|
1011
1171
|
|
1172
|
+
def hash
|
1173
|
+
@hash ||= begin
|
1174
|
+
h = 17
|
1175
|
+
h = 31 * h + @name.hash
|
1176
|
+
h = 31 * h + @type.hash
|
1177
|
+
h
|
1178
|
+
end
|
1179
|
+
end
|
1180
|
+
|
1012
1181
|
def eql?(other)
|
1013
1182
|
other.is_a?(Field) &&
|
1014
1183
|
@name == other.name &&
|
@@ -1028,6 +1197,7 @@ module Cassandra
|
|
1028
1197
|
|
1029
1198
|
# @private
|
1030
1199
|
def initialize(keyspace, name, fields)
|
1200
|
+
super(:udt)
|
1031
1201
|
@keyspace = keyspace
|
1032
1202
|
@name = name
|
1033
1203
|
@fields = fields
|
@@ -1062,12 +1232,6 @@ module Cassandra
|
|
1062
1232
|
@fields.find {|f| f.name == name}
|
1063
1233
|
end
|
1064
1234
|
|
1065
|
-
# @return [Symbol] `:udt`
|
1066
|
-
# @see Cassandra::Type#kind
|
1067
|
-
def kind
|
1068
|
-
:udt
|
1069
|
-
end
|
1070
|
-
|
1071
1235
|
# Coerces the value to Cassandra::UDT
|
1072
1236
|
# @param value [Object] original value
|
1073
1237
|
# @return [Cassandra::UDT] value
|
@@ -1121,6 +1285,17 @@ module Cassandra
|
|
1121
1285
|
"#{Util.escape_name(@keyspace)}.#{Util.escape_name(@name)} {#{@fields.join(', ')}}"
|
1122
1286
|
end
|
1123
1287
|
|
1288
|
+
def hash
|
1289
|
+
@hash ||= begin
|
1290
|
+
h = 17
|
1291
|
+
h = 31 * h + @kind.hash
|
1292
|
+
h = 31 * h + @keyspace.hash
|
1293
|
+
h = 31 * h + @name.hash
|
1294
|
+
h = 31 * h + @fields.hash
|
1295
|
+
h
|
1296
|
+
end
|
1297
|
+
end
|
1298
|
+
|
1124
1299
|
def eql?(other)
|
1125
1300
|
other.is_a?(UserDefined) &&
|
1126
1301
|
@keyspace == other.keyspace &&
|
@@ -1171,14 +1346,10 @@ module Cassandra
|
|
1171
1346
|
attr_reader :name
|
1172
1347
|
|
1173
1348
|
def initialize(name)
|
1349
|
+
super(:custom)
|
1174
1350
|
@name = name
|
1175
1351
|
end
|
1176
1352
|
|
1177
|
-
# @return [Symbol] shorthand type name
|
1178
|
-
def kind
|
1179
|
-
:custom
|
1180
|
-
end
|
1181
|
-
|
1182
1353
|
# Coerces a given value to this type
|
1183
1354
|
#
|
1184
1355
|
# @param value [*Object] value to be coerced
|
@@ -1202,15 +1373,24 @@ module Cassandra
|
|
1202
1373
|
"'#{@name}'"
|
1203
1374
|
end
|
1204
1375
|
|
1376
|
+
def hash
|
1377
|
+
@hash ||= begin
|
1378
|
+
h = 17
|
1379
|
+
h = 31 * h + @kind.hash
|
1380
|
+
h = 31 * h + @name.hash
|
1381
|
+
h
|
1382
|
+
end
|
1383
|
+
end
|
1384
|
+
|
1205
1385
|
def eql?(other)
|
1206
1386
|
other.is_a?(Custom) && @name == other.name
|
1207
1387
|
end
|
1208
1388
|
alias :== :eql?
|
1209
1389
|
end
|
1210
1390
|
|
1211
|
-
# @return [Cassandra::Types::
|
1391
|
+
# @return [Cassandra::Types::Text] text type since varchar is an alias for text
|
1212
1392
|
def varchar
|
1213
|
-
|
1393
|
+
Text
|
1214
1394
|
end
|
1215
1395
|
|
1216
1396
|
# @return [Cassandra::Types::Text] text type
|
@@ -1288,8 +1468,28 @@ module Cassandra
|
|
1288
1468
|
Timeuuid
|
1289
1469
|
end
|
1290
1470
|
|
1471
|
+
# @return [Cassandra::Types::Date] date type
|
1472
|
+
def date
|
1473
|
+
Date
|
1474
|
+
end
|
1475
|
+
|
1476
|
+
# @return [Cassandra::Types::Time] time type
|
1477
|
+
def time
|
1478
|
+
Time
|
1479
|
+
end
|
1480
|
+
|
1481
|
+
# @return [Cassandra::Types::Smallint] smallint type
|
1482
|
+
def smallint
|
1483
|
+
Smallint
|
1484
|
+
end
|
1485
|
+
|
1486
|
+
# @return [Cassandra::Types::Tinyint] tinyint type
|
1487
|
+
def tinyint
|
1488
|
+
Tinyint
|
1489
|
+
end
|
1490
|
+
|
1291
1491
|
# @param value_type [Cassandra::Type] the type of elements in this list
|
1292
|
-
# @return [Cassandra::Types::
|
1492
|
+
# @return [Cassandra::Types::List] list type
|
1293
1493
|
def list(value_type)
|
1294
1494
|
Util.assert_instance_of(Cassandra::Type, value_type,
|
1295
1495
|
"list type must be a Cassandra::Type, #{value_type.inspect} given"
|
@@ -1300,7 +1500,7 @@ module Cassandra
|
|
1300
1500
|
|
1301
1501
|
# @param key_type [Cassandra::Type] the type of keys in this map
|
1302
1502
|
# @param value_type [Cassandra::Type] the type of values in this map
|
1303
|
-
# @return [Cassandra::Types::
|
1503
|
+
# @return [Cassandra::Types::Map] map type
|
1304
1504
|
def map(key_type, value_type)
|
1305
1505
|
Util.assert_instance_of(Cassandra::Type, key_type,
|
1306
1506
|
"map key type must be a Cassandra::Type, #{key_type.inspect} given"
|
@@ -1312,7 +1512,7 @@ module Cassandra
|
|
1312
1512
|
Map.new(key_type, value_type)
|
1313
1513
|
end
|
1314
1514
|
|
1315
|
-
# @param value_type [Cassandra::Type] the type of
|
1515
|
+
# @param value_type [Cassandra::Type] the type of values in this set
|
1316
1516
|
# @return [Cassandra::Types::Set] set type
|
1317
1517
|
def set(value_type)
|
1318
1518
|
Util.assert_instance_of(Cassandra::Type, value_type,
|