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
data/lib/cassandra/future.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.
|
@@ -46,7 +46,9 @@ module Cassandra
|
|
46
46
|
# @private
|
47
47
|
class Error < Future
|
48
48
|
def initialize(error)
|
49
|
-
|
49
|
+
unless error.is_a?(::Exception)
|
50
|
+
raise ::ArgumentError, "error must be an exception, #{error.inspect} given"
|
51
|
+
end
|
50
52
|
|
51
53
|
@error = error
|
52
54
|
end
|
@@ -55,41 +57,53 @@ module Cassandra
|
|
55
57
|
raise(@error, @error.message, @error.backtrace)
|
56
58
|
end
|
57
59
|
|
58
|
-
alias
|
60
|
+
alias join get
|
59
61
|
|
60
62
|
def on_success
|
61
|
-
raise ::ArgumentError,
|
63
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
62
64
|
self
|
63
65
|
end
|
64
66
|
|
65
67
|
def on_failure
|
66
|
-
raise ::ArgumentError,
|
67
|
-
|
68
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
69
|
+
begin
|
70
|
+
yield(@error)
|
71
|
+
rescue
|
72
|
+
nil
|
73
|
+
end
|
68
74
|
self
|
69
75
|
end
|
70
76
|
|
71
77
|
def on_complete
|
72
|
-
raise ::ArgumentError,
|
73
|
-
|
78
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
79
|
+
begin
|
80
|
+
yield(nil, @error)
|
81
|
+
rescue
|
82
|
+
nil
|
83
|
+
end
|
74
84
|
self
|
75
85
|
end
|
76
86
|
|
77
87
|
def add_listener(listener)
|
78
|
-
unless
|
79
|
-
raise ::ArgumentError,
|
88
|
+
unless listener.respond_to?(:success) && listener.respond_to?(:failure)
|
89
|
+
raise ::ArgumentError, 'listener must respond to both #success and #failure'
|
80
90
|
end
|
81
91
|
|
82
|
-
|
92
|
+
begin
|
93
|
+
listener.failure(@error)
|
94
|
+
rescue
|
95
|
+
nil
|
96
|
+
end
|
83
97
|
self
|
84
98
|
end
|
85
99
|
|
86
100
|
def then
|
87
|
-
raise ::ArgumentError,
|
101
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
88
102
|
self
|
89
103
|
end
|
90
104
|
|
91
105
|
def fallback
|
92
|
-
raise ::ArgumentError,
|
106
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
93
107
|
|
94
108
|
begin
|
95
109
|
result = yield(@error)
|
@@ -111,31 +125,43 @@ module Cassandra
|
|
111
125
|
@value
|
112
126
|
end
|
113
127
|
|
114
|
-
alias
|
128
|
+
alias join get
|
115
129
|
|
116
130
|
def on_success
|
117
|
-
raise ::ArgumentError,
|
118
|
-
|
131
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
132
|
+
begin
|
133
|
+
yield(@value)
|
134
|
+
rescue
|
135
|
+
nil
|
136
|
+
end
|
119
137
|
self
|
120
138
|
end
|
121
139
|
|
122
140
|
def on_failure
|
123
|
-
raise ::ArgumentError,
|
141
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
124
142
|
self
|
125
143
|
end
|
126
144
|
|
127
145
|
def on_complete
|
128
|
-
raise ::ArgumentError,
|
129
|
-
|
146
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
147
|
+
begin
|
148
|
+
yield(@value, nil)
|
149
|
+
rescue
|
150
|
+
nil
|
151
|
+
end
|
130
152
|
self
|
131
153
|
end
|
132
154
|
|
133
155
|
def add_listener(listener)
|
134
|
-
unless
|
135
|
-
raise ::ArgumentError,
|
156
|
+
unless listener.respond_to?(:success) && listener.respond_to?(:failure)
|
157
|
+
raise ::ArgumentError, 'listener must respond to both #success and #failure'
|
136
158
|
end
|
137
159
|
|
138
|
-
|
160
|
+
begin
|
161
|
+
listener.success(@value)
|
162
|
+
rescue
|
163
|
+
nil
|
164
|
+
end
|
139
165
|
self
|
140
166
|
end
|
141
167
|
|
@@ -144,7 +170,7 @@ module Cassandra
|
|
144
170
|
end
|
145
171
|
|
146
172
|
def then
|
147
|
-
raise ::ArgumentError,
|
173
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
148
174
|
|
149
175
|
begin
|
150
176
|
result = yield(@value)
|
@@ -156,7 +182,7 @@ module Cassandra
|
|
156
182
|
end
|
157
183
|
|
158
184
|
def fallback
|
159
|
-
raise ::ArgumentError,
|
185
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
160
186
|
self
|
161
187
|
end
|
162
188
|
end
|
@@ -252,7 +278,7 @@ module Cassandra
|
|
252
278
|
# @raise [ArgumentError] if no block given
|
253
279
|
# @return [self]
|
254
280
|
def on_success(&block)
|
255
|
-
raise ::ArgumentError,
|
281
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
256
282
|
@signal.on_success(&block)
|
257
283
|
self
|
258
284
|
end
|
@@ -265,7 +291,7 @@ module Cassandra
|
|
265
291
|
# @raise [ArgumentError] if no block given
|
266
292
|
# @return [self]
|
267
293
|
def on_failure(&block)
|
268
|
-
raise ::ArgumentError,
|
294
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
269
295
|
@signal.on_failure(&block)
|
270
296
|
self
|
271
297
|
end
|
@@ -281,7 +307,7 @@ module Cassandra
|
|
281
307
|
# @raise [ArgumentError] if no block given
|
282
308
|
# @return [self]
|
283
309
|
def on_complete(&block)
|
284
|
-
raise ::ArgumentError,
|
310
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
285
311
|
@signal.on_complete(&block)
|
286
312
|
self
|
287
313
|
end
|
@@ -296,8 +322,8 @@ module Cassandra
|
|
296
322
|
# `#success` and `#failure`
|
297
323
|
# @return [self]
|
298
324
|
def add_listener(listener)
|
299
|
-
unless
|
300
|
-
raise ::ArgumentError,
|
325
|
+
unless listener.respond_to?(:success) && listener.respond_to?(:failure)
|
326
|
+
raise ::ArgumentError, 'listener must respond to both #success and #failure'
|
301
327
|
end
|
302
328
|
|
303
329
|
@signal.add_listener(listener)
|
@@ -325,7 +351,7 @@ module Cassandra
|
|
325
351
|
# @raise [ArgumentError] if no block given
|
326
352
|
# @return [Cassandra::Future] a new future
|
327
353
|
def then(&block)
|
328
|
-
raise ::ArgumentError,
|
354
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
329
355
|
@signal.then(&block)
|
330
356
|
end
|
331
357
|
|
@@ -351,7 +377,7 @@ module Cassandra
|
|
351
377
|
# @raise [ArgumentError] if no block given
|
352
378
|
# @return [Cassandra::Future] a new future
|
353
379
|
def fallback(&block)
|
354
|
-
raise ::ArgumentError,
|
380
|
+
raise ::ArgumentError, 'no block given' unless block_given?
|
355
381
|
@signal.fallback(&block)
|
356
382
|
end
|
357
383
|
|
@@ -372,7 +398,7 @@ module Cassandra
|
|
372
398
|
@signal.get(timeout)
|
373
399
|
end
|
374
400
|
|
375
|
-
alias
|
401
|
+
alias join get
|
376
402
|
end
|
377
403
|
|
378
404
|
# @private
|
@@ -507,12 +533,17 @@ module Cassandra
|
|
507
533
|
@error = error
|
508
534
|
@state = :broken
|
509
535
|
|
510
|
-
listeners
|
536
|
+
listeners = @listeners
|
537
|
+
@listeners = nil
|
511
538
|
end
|
512
539
|
|
513
540
|
@executor.execute do
|
514
541
|
listeners.each do |listener|
|
515
|
-
|
542
|
+
begin
|
543
|
+
listener.failure(error)
|
544
|
+
rescue
|
545
|
+
nil
|
546
|
+
end
|
516
547
|
end
|
517
548
|
|
518
549
|
synchronize do
|
@@ -534,12 +565,17 @@ module Cassandra
|
|
534
565
|
@value = value
|
535
566
|
@state = :fulfilled
|
536
567
|
|
537
|
-
listeners
|
568
|
+
listeners = @listeners
|
569
|
+
@listeners = nil
|
538
570
|
end
|
539
571
|
|
540
572
|
@executor.execute do
|
541
573
|
listeners.each do |listener|
|
542
|
-
|
574
|
+
begin
|
575
|
+
listener.success(value)
|
576
|
+
rescue
|
577
|
+
nil
|
578
|
+
end
|
543
579
|
end
|
544
580
|
|
545
581
|
synchronize do
|
@@ -561,10 +597,12 @@ module Cassandra
|
|
561
597
|
#
|
562
598
|
# @return [Object] the value that the future has been resolved with
|
563
599
|
def get(timeout = nil)
|
564
|
-
timeout
|
600
|
+
timeout &&= Float(timeout)
|
565
601
|
|
566
602
|
if timeout
|
567
|
-
|
603
|
+
if timeout < 0
|
604
|
+
raise ::ArgumentError, "timeout cannot be negative, #{timeout.inspect} given"
|
605
|
+
end
|
568
606
|
|
569
607
|
start = ::Time.now
|
570
608
|
now = start
|
@@ -590,18 +628,18 @@ module Cassandra
|
|
590
628
|
|
591
629
|
if @state == :pending
|
592
630
|
total_wait = deadline - start
|
593
|
-
raise Errors::TimeoutError,
|
631
|
+
raise Errors::TimeoutError,
|
632
|
+
"Future did not complete within #{timeout.inspect} seconds. " \
|
633
|
+
"Wait time: #{total_wait.inspect}"
|
594
634
|
end
|
595
635
|
end
|
596
636
|
|
597
|
-
if @state == :broken
|
598
|
-
raise(@error, @error.message, @error.backtrace)
|
599
|
-
end
|
637
|
+
raise(@error, @error.message, @error.backtrace) if @state == :broken
|
600
638
|
|
601
639
|
@value
|
602
640
|
end
|
603
641
|
|
604
|
-
alias
|
642
|
+
alias join get
|
605
643
|
|
606
644
|
def add_listener(listener)
|
607
645
|
if @state == :pending
|
@@ -614,8 +652,16 @@ module Cassandra
|
|
614
652
|
end
|
615
653
|
end
|
616
654
|
|
617
|
-
|
618
|
-
|
655
|
+
begin
|
656
|
+
listener.success(@value)
|
657
|
+
rescue
|
658
|
+
nil
|
659
|
+
end if @state == :fulfilled
|
660
|
+
begin
|
661
|
+
listener.failure(@error)
|
662
|
+
rescue
|
663
|
+
nil
|
664
|
+
end if @state == :broken
|
619
665
|
|
620
666
|
self
|
621
667
|
end
|
@@ -630,7 +676,11 @@ module Cassandra
|
|
630
676
|
end
|
631
677
|
end
|
632
678
|
|
633
|
-
|
679
|
+
begin
|
680
|
+
yield(@value)
|
681
|
+
rescue
|
682
|
+
nil
|
683
|
+
end if @state == :fulfilled
|
634
684
|
|
635
685
|
self
|
636
686
|
end
|
@@ -645,7 +695,11 @@ module Cassandra
|
|
645
695
|
end
|
646
696
|
end
|
647
697
|
|
648
|
-
|
698
|
+
begin
|
699
|
+
yield(@error)
|
700
|
+
rescue
|
701
|
+
nil
|
702
|
+
end if @state == :broken
|
649
703
|
|
650
704
|
self
|
651
705
|
end
|
@@ -660,7 +714,11 @@ module Cassandra
|
|
660
714
|
end
|
661
715
|
end
|
662
716
|
|
663
|
-
|
717
|
+
begin
|
718
|
+
yield(@value, @error)
|
719
|
+
rescue
|
720
|
+
nil
|
721
|
+
end
|
664
722
|
|
665
723
|
self
|
666
724
|
end
|
data/lib/cassandra/host.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.
|
@@ -39,7 +39,13 @@ module Cassandra
|
|
39
39
|
attr_reader :status
|
40
40
|
|
41
41
|
# @private
|
42
|
-
def initialize(ip,
|
42
|
+
def initialize(ip,
|
43
|
+
id = nil,
|
44
|
+
rack = nil,
|
45
|
+
datacenter = nil,
|
46
|
+
release_version = nil,
|
47
|
+
tokens = EMPTY_LIST,
|
48
|
+
status = :up)
|
43
49
|
@ip = ip
|
44
50
|
@id = id
|
45
51
|
@rack = rack
|
@@ -72,11 +78,11 @@ module Cassandra
|
|
72
78
|
def eql?(other)
|
73
79
|
other.eql?(@ip)
|
74
80
|
end
|
75
|
-
alias
|
81
|
+
alias == eql?
|
76
82
|
|
77
83
|
# @private
|
78
84
|
def inspect
|
79
|
-
"#<#{self.class.name}:0x#{
|
85
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @ip=#{@ip}>"
|
80
86
|
end
|
81
87
|
end
|
82
88
|
end
|
data/lib/cassandra/keyspace.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.
|
@@ -42,7 +42,7 @@ module Cassandra
|
|
42
42
|
@klass == other.klass &&
|
43
43
|
@options == other.options
|
44
44
|
end
|
45
|
-
alias
|
45
|
+
alias == eql?
|
46
46
|
end
|
47
47
|
|
48
48
|
# @return [String] this keyspace name
|
@@ -51,7 +51,13 @@ module Cassandra
|
|
51
51
|
attr_reader :replication
|
52
52
|
|
53
53
|
# @private
|
54
|
-
def initialize(name,
|
54
|
+
def initialize(name,
|
55
|
+
durable_writes,
|
56
|
+
replication,
|
57
|
+
tables,
|
58
|
+
types,
|
59
|
+
functions,
|
60
|
+
aggregates)
|
55
61
|
@name = name
|
56
62
|
@durable_writes = durable_writes
|
57
63
|
@replication = replication
|
@@ -69,7 +75,7 @@ module Cassandra
|
|
69
75
|
# @return [Boolean] whether this keyspace has a table with the given name
|
70
76
|
# @param name [String] table name
|
71
77
|
def has_table?(name)
|
72
|
-
@tables.
|
78
|
+
@tables.key?(name)
|
73
79
|
end
|
74
80
|
|
75
81
|
# @return [Cassandra::Table, nil] a table or nil
|
@@ -92,13 +98,13 @@ module Cassandra
|
|
92
98
|
@tables.values
|
93
99
|
end
|
94
100
|
end
|
95
|
-
alias
|
101
|
+
alias tables each_table
|
96
102
|
|
97
103
|
# @return [Boolean] whether this keyspace has a user-defined type with the
|
98
104
|
# given name
|
99
105
|
# @param name [String] user-defined type name
|
100
106
|
def has_type?(name)
|
101
|
-
@types.
|
107
|
+
@types.key?(name)
|
102
108
|
end
|
103
109
|
|
104
110
|
# @return [Cassandra::Types::UserDefined, nil] a type or nil
|
@@ -121,13 +127,14 @@ module Cassandra
|
|
121
127
|
@types.values
|
122
128
|
end
|
123
129
|
end
|
124
|
-
alias
|
130
|
+
alias types each_type
|
125
131
|
|
126
|
-
# @return [Boolean] whether this keyspace has a function with the given name and
|
132
|
+
# @return [Boolean] whether this keyspace has a function with the given name and
|
133
|
+
# arguments
|
127
134
|
# @param name [String] function name
|
128
135
|
# @param args [Array<String>] (var-args style) function argument types
|
129
136
|
def has_function?(name, *args)
|
130
|
-
|
137
|
+
!@functions.get(name.downcase, args).nil?
|
131
138
|
end
|
132
139
|
|
133
140
|
# @return [Cassandra::Function, nil] a function or nil
|
@@ -136,7 +143,7 @@ module Cassandra
|
|
136
143
|
def function(name, *args)
|
137
144
|
# The functions_hash datastructure is a hash <[func-name, args], Function>.
|
138
145
|
# So construct the array-key we're looking for.
|
139
|
-
@functions
|
146
|
+
@functions.get(name.downcase, args)
|
140
147
|
end
|
141
148
|
|
142
149
|
# Yield or enumerate each function defined in this keyspace
|
@@ -147,27 +154,27 @@ module Cassandra
|
|
147
154
|
# @return [Array<Cassandra::Function>] a list of functions
|
148
155
|
def each_function(&block)
|
149
156
|
if block_given?
|
150
|
-
@functions.
|
157
|
+
@functions.each_function(&block)
|
151
158
|
self
|
152
159
|
else
|
153
|
-
@functions.
|
160
|
+
@functions.functions
|
154
161
|
end
|
155
162
|
end
|
156
|
-
alias
|
163
|
+
alias functions each_function
|
157
164
|
|
158
165
|
# @return [Boolean] whether this keyspace has an aggregate with the given
|
159
166
|
# name and arguments
|
160
167
|
# @param name [String] aggregate name
|
161
168
|
# @param args [Array<String>] (var-args style) aggregate function argument types
|
162
169
|
def has_aggregate?(name, *args)
|
163
|
-
|
170
|
+
!@aggregates.get(name.downcase, args).nil?
|
164
171
|
end
|
165
172
|
|
166
173
|
# @return [Cassandra::Aggregate, nil] an aggregate or nil
|
167
174
|
# @param name [String] aggregate name
|
168
175
|
# @param args [Array<String>] (var-args style) aggregate function argument types
|
169
176
|
def aggregate(name, *args)
|
170
|
-
@aggregates
|
177
|
+
@aggregates.get(name.downcase, args)
|
171
178
|
end
|
172
179
|
|
173
180
|
# Yield or enumerate each aggregate defined in this keyspace
|
@@ -178,17 +185,19 @@ module Cassandra
|
|
178
185
|
# @return [Array<Cassandra::Aggregate>] a list of aggregates
|
179
186
|
def each_aggregate(&block)
|
180
187
|
if block_given?
|
181
|
-
@aggregates.
|
188
|
+
@aggregates.each_function(&block)
|
182
189
|
self
|
183
190
|
else
|
184
|
-
@aggregates.
|
191
|
+
@aggregates.functions
|
185
192
|
end
|
186
193
|
end
|
187
|
-
alias
|
194
|
+
alias aggregates each_aggregate
|
188
195
|
|
189
196
|
# @return [String] a cql representation of this keyspace
|
190
197
|
def to_cql
|
191
|
-
"CREATE KEYSPACE #{Util.escape_name(@name)}
|
198
|
+
"CREATE KEYSPACE #{Util.escape_name(@name)} " \
|
199
|
+
"WITH replication = #{@replication.to_cql} AND " \
|
200
|
+
"durable_writes = #{@durable_writes};"
|
192
201
|
end
|
193
202
|
|
194
203
|
# @private
|
@@ -202,67 +211,115 @@ module Cassandra
|
|
202
211
|
@functions == other.raw_functions &&
|
203
212
|
@aggregates == other.raw_aggregates
|
204
213
|
end
|
205
|
-
alias
|
214
|
+
alias == eql?
|
206
215
|
|
207
216
|
# @private
|
208
217
|
def inspect
|
209
|
-
"#<#{self.class.name}:0x#{
|
218
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @name=#{@name}>"
|
210
219
|
end
|
211
220
|
|
212
221
|
# @private
|
213
222
|
def update_table(table)
|
214
223
|
tables = @tables.dup
|
215
224
|
tables[table.name] = table
|
216
|
-
Keyspace.new(@name,
|
225
|
+
Keyspace.new(@name,
|
226
|
+
@durable_writes,
|
227
|
+
@replication,
|
228
|
+
tables,
|
229
|
+
@types,
|
230
|
+
@functions,
|
231
|
+
@aggregates)
|
217
232
|
end
|
218
233
|
|
219
234
|
# @private
|
220
235
|
def delete_table(table_name)
|
221
236
|
tables = @tables.dup
|
222
237
|
tables.delete(table_name)
|
223
|
-
Keyspace.new(@name,
|
238
|
+
Keyspace.new(@name,
|
239
|
+
@durable_writes,
|
240
|
+
@replication,
|
241
|
+
tables,
|
242
|
+
@types,
|
243
|
+
@functions,
|
244
|
+
@aggregates)
|
224
245
|
end
|
225
246
|
|
226
247
|
# @private
|
227
248
|
def update_type(type)
|
228
249
|
types = @types.dup
|
229
250
|
types[type.name] = type
|
230
|
-
Keyspace.new(@name,
|
251
|
+
Keyspace.new(@name,
|
252
|
+
@durable_writes,
|
253
|
+
@replication,
|
254
|
+
@tables,
|
255
|
+
types,
|
256
|
+
@functions,
|
257
|
+
@aggregates)
|
231
258
|
end
|
232
259
|
|
233
260
|
# @private
|
234
261
|
def delete_type(type_name)
|
235
262
|
types = @types.dup
|
236
263
|
types.delete(type_name)
|
237
|
-
Keyspace.new(@name,
|
264
|
+
Keyspace.new(@name,
|
265
|
+
@durable_writes,
|
266
|
+
@replication,
|
267
|
+
@tables,
|
268
|
+
types,
|
269
|
+
@functions,
|
270
|
+
@aggregates)
|
238
271
|
end
|
239
272
|
|
240
273
|
# @private
|
241
274
|
def update_function(function)
|
242
275
|
functions = @functions.dup
|
243
|
-
functions
|
244
|
-
Keyspace.new(@name,
|
276
|
+
functions.add_or_update(function)
|
277
|
+
Keyspace.new(@name,
|
278
|
+
@durable_writes,
|
279
|
+
@replication,
|
280
|
+
@tables,
|
281
|
+
@types,
|
282
|
+
functions,
|
283
|
+
@aggregates)
|
245
284
|
end
|
246
285
|
|
247
286
|
# @private
|
248
287
|
def delete_function(function_name, function_args)
|
249
288
|
functions = @functions.dup
|
250
|
-
functions.delete(
|
251
|
-
Keyspace.new(@name,
|
289
|
+
functions.delete(function_name, function_args)
|
290
|
+
Keyspace.new(@name,
|
291
|
+
@durable_writes,
|
292
|
+
@replication,
|
293
|
+
@tables,
|
294
|
+
@types,
|
295
|
+
functions,
|
296
|
+
@aggregates)
|
252
297
|
end
|
253
298
|
|
254
299
|
# @private
|
255
300
|
def update_aggregate(aggregate)
|
256
301
|
aggregates = @aggregates.dup
|
257
|
-
aggregates
|
258
|
-
Keyspace.new(@name,
|
302
|
+
aggregates.add_or_update(aggregate)
|
303
|
+
Keyspace.new(@name,
|
304
|
+
@durable_writes,
|
305
|
+
@replication,
|
306
|
+
@tables,
|
307
|
+
@types,
|
308
|
+
@functions,
|
309
|
+
aggregates)
|
259
310
|
end
|
260
311
|
|
261
312
|
# @private
|
262
313
|
def delete_aggregate(aggregate_name, aggregate_args)
|
263
314
|
aggregates = @aggregates.dup
|
264
|
-
aggregates.delete(
|
265
|
-
Keyspace.new(@name,
|
315
|
+
aggregates.delete(aggregate_name, aggregate_args)
|
316
|
+
Keyspace.new(@name,
|
317
|
+
@durable_writes,
|
318
|
+
@replication,
|
319
|
+
@tables,
|
320
|
+
@types,
|
321
|
+
@functions,
|
322
|
+
aggregates)
|
266
323
|
end
|
267
324
|
|
268
325
|
# @private
|