yugabyte-ycql-driver 3.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +13 -0
- data/README.md +242 -0
- data/ext/cassandra_murmur3/cassandra_murmur3.c +178 -0
- data/ext/cassandra_murmur3/extconf.rb +2 -0
- data/lib/cassandra/address_resolution.rb +36 -0
- data/lib/cassandra/address_resolution/policies.rb +2 -0
- data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +56 -0
- data/lib/cassandra/address_resolution/policies/none.rb +35 -0
- data/lib/cassandra/aggregate.rb +123 -0
- data/lib/cassandra/argument.rb +51 -0
- data/lib/cassandra/attr_boolean.rb +33 -0
- data/lib/cassandra/auth.rb +100 -0
- data/lib/cassandra/auth/providers.rb +17 -0
- data/lib/cassandra/auth/providers/password.rb +65 -0
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +331 -0
- data/lib/cassandra/cluster/client.rb +1612 -0
- data/lib/cassandra/cluster/connection_pool.rb +78 -0
- data/lib/cassandra/cluster/connector.rb +372 -0
- data/lib/cassandra/cluster/control_connection.rb +962 -0
- data/lib/cassandra/cluster/failed_connection.rb +35 -0
- data/lib/cassandra/cluster/metadata.rb +142 -0
- data/lib/cassandra/cluster/options.rb +145 -0
- data/lib/cassandra/cluster/registry.rb +284 -0
- data/lib/cassandra/cluster/schema.rb +405 -0
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +112 -0
- data/lib/cassandra/cluster/schema/fetchers.rb +1627 -0
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +175 -0
- data/lib/cassandra/cluster/schema/partitioners.rb +21 -0
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +45 -0
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +37 -0
- data/lib/cassandra/cluster/schema/partitioners/random.rb +37 -0
- data/lib/cassandra/cluster/schema/replication_strategies.rb +21 -0
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +102 -0
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +39 -0
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +44 -0
- data/lib/cassandra/column.rb +66 -0
- data/lib/cassandra/column_container.rb +326 -0
- data/lib/cassandra/compression.rb +69 -0
- data/lib/cassandra/compression/compressors/lz4.rb +73 -0
- data/lib/cassandra/compression/compressors/snappy.rb +69 -0
- data/lib/cassandra/custom_data.rb +53 -0
- data/lib/cassandra/driver.rb +260 -0
- data/lib/cassandra/errors.rb +784 -0
- data/lib/cassandra/execution/info.rb +69 -0
- data/lib/cassandra/execution/options.rb +267 -0
- data/lib/cassandra/execution/profile.rb +153 -0
- data/lib/cassandra/execution/profile_manager.rb +71 -0
- data/lib/cassandra/execution/trace.rb +192 -0
- data/lib/cassandra/executors.rb +113 -0
- data/lib/cassandra/function.rb +156 -0
- data/lib/cassandra/function_collection.rb +85 -0
- data/lib/cassandra/future.rb +794 -0
- data/lib/cassandra/host.rb +102 -0
- data/lib/cassandra/index.rb +118 -0
- data/lib/cassandra/keyspace.rb +473 -0
- data/lib/cassandra/listener.rb +87 -0
- data/lib/cassandra/load_balancing.rb +121 -0
- data/lib/cassandra/load_balancing/policies.rb +20 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +172 -0
- data/lib/cassandra/load_balancing/policies/round_robin.rb +141 -0
- data/lib/cassandra/load_balancing/policies/token_aware.rb +149 -0
- data/lib/cassandra/load_balancing/policies/white_list.rb +100 -0
- data/lib/cassandra/materialized_view.rb +92 -0
- data/lib/cassandra/null_logger.rb +56 -0
- data/lib/cassandra/protocol.rb +102 -0
- data/lib/cassandra/protocol/coder.rb +1085 -0
- data/lib/cassandra/protocol/cql_byte_buffer.rb +418 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +448 -0
- data/lib/cassandra/protocol/request.rb +41 -0
- data/lib/cassandra/protocol/requests/auth_response_request.rb +51 -0
- data/lib/cassandra/protocol/requests/batch_request.rb +117 -0
- data/lib/cassandra/protocol/requests/credentials_request.rb +51 -0
- data/lib/cassandra/protocol/requests/execute_request.rb +122 -0
- data/lib/cassandra/protocol/requests/options_request.rb +39 -0
- data/lib/cassandra/protocol/requests/prepare_request.rb +59 -0
- data/lib/cassandra/protocol/requests/query_request.rb +112 -0
- data/lib/cassandra/protocol/requests/register_request.rb +38 -0
- data/lib/cassandra/protocol/requests/startup_request.rb +49 -0
- data/lib/cassandra/protocol/requests/void_query_request.rb +24 -0
- data/lib/cassandra/protocol/response.rb +28 -0
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +50 -0
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +36 -0
- data/lib/cassandra/protocol/responses/auth_success_response.rb +36 -0
- data/lib/cassandra/protocol/responses/authenticate_response.rb +36 -0
- data/lib/cassandra/protocol/responses/error_response.rb +142 -0
- data/lib/cassandra/protocol/responses/event_response.rb +30 -0
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +52 -0
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +62 -0
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +59 -0
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +71 -0
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +61 -0
- data/lib/cassandra/protocol/responses/ready_response.rb +43 -0
- data/lib/cassandra/protocol/responses/result_response.rb +42 -0
- data/lib/cassandra/protocol/responses/rows_result_response.rb +39 -0
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +73 -0
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +70 -0
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +37 -0
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +39 -0
- data/lib/cassandra/protocol/responses/supported_response.rb +36 -0
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +33 -0
- data/lib/cassandra/protocol/responses/unavailable_error_response.rb +58 -0
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +48 -0
- data/lib/cassandra/protocol/responses/void_result_response.rb +34 -0
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +73 -0
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +63 -0
- data/lib/cassandra/protocol/v1.rb +326 -0
- data/lib/cassandra/protocol/v3.rb +358 -0
- data/lib/cassandra/protocol/v4.rb +478 -0
- data/lib/cassandra/reconnection.rb +49 -0
- data/lib/cassandra/reconnection/policies.rb +20 -0
- data/lib/cassandra/reconnection/policies/constant.rb +46 -0
- data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
- data/lib/cassandra/result.rb +276 -0
- data/lib/cassandra/retry.rb +154 -0
- data/lib/cassandra/retry/policies.rb +21 -0
- data/lib/cassandra/retry/policies/default.rb +53 -0
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +73 -0
- data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
- data/lib/cassandra/session.rb +270 -0
- data/lib/cassandra/statement.rb +32 -0
- data/lib/cassandra/statements.rb +23 -0
- data/lib/cassandra/statements/batch.rb +146 -0
- data/lib/cassandra/statements/bound.rb +65 -0
- data/lib/cassandra/statements/prepared.rb +235 -0
- data/lib/cassandra/statements/simple.rb +118 -0
- data/lib/cassandra/statements/void.rb +38 -0
- data/lib/cassandra/table.rb +240 -0
- data/lib/cassandra/time.rb +103 -0
- data/lib/cassandra/time_uuid.rb +78 -0
- data/lib/cassandra/timestamp_generator.rb +37 -0
- data/lib/cassandra/timestamp_generator/simple.rb +38 -0
- data/lib/cassandra/timestamp_generator/ticking_on_duplicate.rb +58 -0
- data/lib/cassandra/trigger.rb +67 -0
- data/lib/cassandra/tuple.rb +131 -0
- data/lib/cassandra/types.rb +1704 -0
- data/lib/cassandra/udt.rb +443 -0
- data/lib/cassandra/util.rb +464 -0
- data/lib/cassandra/uuid.rb +110 -0
- data/lib/cassandra/uuid/generator.rb +212 -0
- data/lib/cassandra/version.rb +21 -0
- data/lib/datastax/cassandra.rb +47 -0
- data/lib/ycql.rb +842 -0
- metadata +243 -0
@@ -0,0 +1,405 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 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
|
+
class Cluster
|
21
|
+
# @private
|
22
|
+
class Schema
|
23
|
+
include MonitorMixin
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@keyspaces = ::Hash.new
|
27
|
+
@listeners = ::Set.new
|
28
|
+
|
29
|
+
mon_initialize
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_pk_idx(metadata)
|
33
|
+
return EMPTY_LIST unless metadata
|
34
|
+
|
35
|
+
# metadata is an array of column-specs; each column-spec is an array
|
36
|
+
# of keyspace_name, tablename, other stuff. We only care about the first two.
|
37
|
+
# See read_prepared_metadata_v4 in coder.rb for more details.
|
38
|
+
# NB: sandman: I think all of the column specs have the same keyspace and
|
39
|
+
# table name in this context, so we can safely grab the first.
|
40
|
+
|
41
|
+
keyspace_name, table_name = metadata.first
|
42
|
+
return EMPTY_LIST unless keyspace_name && table_name
|
43
|
+
|
44
|
+
keyspace = @keyspaces[keyspace_name]
|
45
|
+
return EMPTY_LIST unless keyspace
|
46
|
+
|
47
|
+
table = keyspace.table(table_name)
|
48
|
+
return EMPTY_LIST unless table
|
49
|
+
|
50
|
+
partition_key = table.partition_key
|
51
|
+
return EMPTY_LIST unless partition_key && partition_key.size <= metadata.size
|
52
|
+
|
53
|
+
partition_key.map do |column|
|
54
|
+
i = metadata.index {|(_, _, name, _)| name == column.name}
|
55
|
+
return EMPTY_LIST if i.nil?
|
56
|
+
i
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def add_listener(listener)
|
61
|
+
synchronize do
|
62
|
+
@listeners = @listeners.dup.add(listener)
|
63
|
+
end
|
64
|
+
|
65
|
+
self
|
66
|
+
end
|
67
|
+
|
68
|
+
def remove_listener(listener)
|
69
|
+
synchronize do
|
70
|
+
@listeners = @listeners.dup.delete(listener)
|
71
|
+
end
|
72
|
+
|
73
|
+
self
|
74
|
+
end
|
75
|
+
|
76
|
+
def replace(keyspaces)
|
77
|
+
current_keyspaces = ::Set.new
|
78
|
+
|
79
|
+
keyspaces.each do |keyspace|
|
80
|
+
current_keyspaces << keyspace.name
|
81
|
+
|
82
|
+
replace_keyspace(keyspace)
|
83
|
+
end
|
84
|
+
|
85
|
+
@keyspaces.each do |name, _keyspace|
|
86
|
+
delete_keyspace(name) unless current_keyspaces.include?(name)
|
87
|
+
end
|
88
|
+
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
92
|
+
def replace_keyspace(keyspace)
|
93
|
+
old_keyspace = @keyspaces[keyspace.name]
|
94
|
+
|
95
|
+
return self if old_keyspace == keyspace
|
96
|
+
|
97
|
+
synchronize do
|
98
|
+
keyspaces = @keyspaces.dup
|
99
|
+
keyspaces[keyspace.name] = keyspace
|
100
|
+
@keyspaces = keyspaces
|
101
|
+
end
|
102
|
+
|
103
|
+
if old_keyspace
|
104
|
+
keyspace_changed(keyspace)
|
105
|
+
else
|
106
|
+
keyspace_created(keyspace)
|
107
|
+
end
|
108
|
+
|
109
|
+
self
|
110
|
+
end
|
111
|
+
|
112
|
+
def delete_keyspace(keyspace_name)
|
113
|
+
keyspace = @keyspaces[keyspace_name]
|
114
|
+
|
115
|
+
return self unless keyspace
|
116
|
+
|
117
|
+
synchronize do
|
118
|
+
keyspaces = @keyspaces.dup
|
119
|
+
keyspaces.delete(keyspace_name)
|
120
|
+
@keyspaces = keyspaces
|
121
|
+
end
|
122
|
+
|
123
|
+
keyspace_dropped(keyspace)
|
124
|
+
|
125
|
+
self
|
126
|
+
end
|
127
|
+
|
128
|
+
def replace_table(table)
|
129
|
+
keyspace = table.keyspace
|
130
|
+
|
131
|
+
return self unless keyspace
|
132
|
+
|
133
|
+
old_table = keyspace.table(table.name)
|
134
|
+
|
135
|
+
return self if old_table == table
|
136
|
+
|
137
|
+
keyspace = keyspace.update_table(table)
|
138
|
+
|
139
|
+
synchronize do
|
140
|
+
keyspaces = @keyspaces.dup
|
141
|
+
keyspaces[keyspace.name] = keyspace
|
142
|
+
@keyspaces = keyspaces
|
143
|
+
end
|
144
|
+
|
145
|
+
keyspace_changed(keyspace)
|
146
|
+
|
147
|
+
self
|
148
|
+
end
|
149
|
+
|
150
|
+
def delete_table(keyspace_name, table_name)
|
151
|
+
keyspace = @keyspaces[keyspace_name]
|
152
|
+
|
153
|
+
return self unless keyspace
|
154
|
+
|
155
|
+
table = keyspace.table(table_name)
|
156
|
+
|
157
|
+
return self unless table
|
158
|
+
|
159
|
+
keyspace = keyspace.delete_table(table_name)
|
160
|
+
|
161
|
+
synchronize do
|
162
|
+
keyspaces = @keyspaces.dup
|
163
|
+
keyspaces[keyspace_name] = keyspace
|
164
|
+
@keyspaces = keyspaces
|
165
|
+
end
|
166
|
+
|
167
|
+
keyspace_changed(keyspace)
|
168
|
+
|
169
|
+
self
|
170
|
+
end
|
171
|
+
|
172
|
+
def replace_materialized_view(view)
|
173
|
+
keyspace = view.keyspace
|
174
|
+
|
175
|
+
return self unless keyspace
|
176
|
+
|
177
|
+
old_view = keyspace.materialized_view(view.name)
|
178
|
+
|
179
|
+
return self if old_view == view
|
180
|
+
|
181
|
+
keyspace = keyspace.update_materialized_view(view)
|
182
|
+
|
183
|
+
synchronize do
|
184
|
+
keyspaces = @keyspaces.dup
|
185
|
+
keyspaces[keyspace.name] = keyspace
|
186
|
+
@keyspaces = keyspaces
|
187
|
+
end
|
188
|
+
|
189
|
+
keyspace_changed(keyspace)
|
190
|
+
|
191
|
+
self
|
192
|
+
end
|
193
|
+
|
194
|
+
def delete_materialized_view(keyspace_name, view_name)
|
195
|
+
keyspace = @keyspaces[keyspace_name]
|
196
|
+
|
197
|
+
return self unless keyspace
|
198
|
+
|
199
|
+
view = keyspace.materialized_view(view_name)
|
200
|
+
|
201
|
+
return self unless view
|
202
|
+
|
203
|
+
keyspace = keyspace.delete_materialized_view(view_name)
|
204
|
+
|
205
|
+
synchronize do
|
206
|
+
keyspaces = @keyspaces.dup
|
207
|
+
keyspaces[keyspace_name] = keyspace
|
208
|
+
@keyspaces = keyspaces
|
209
|
+
end
|
210
|
+
|
211
|
+
keyspace_changed(keyspace)
|
212
|
+
|
213
|
+
self
|
214
|
+
end
|
215
|
+
|
216
|
+
def replace_type(type)
|
217
|
+
keyspace = @keyspaces[type.keyspace]
|
218
|
+
|
219
|
+
return self unless keyspace
|
220
|
+
|
221
|
+
old_type = keyspace.type(type.name)
|
222
|
+
|
223
|
+
return self if old_type == type
|
224
|
+
|
225
|
+
keyspace = keyspace.update_type(type)
|
226
|
+
|
227
|
+
synchronize do
|
228
|
+
keyspaces = @keyspaces.dup
|
229
|
+
keyspaces[keyspace.name] = keyspace
|
230
|
+
@keyspaces = keyspaces
|
231
|
+
end
|
232
|
+
|
233
|
+
keyspace_changed(keyspace)
|
234
|
+
|
235
|
+
self
|
236
|
+
end
|
237
|
+
|
238
|
+
def delete_type(keyspace_name, type_name)
|
239
|
+
keyspace = @keyspaces[keyspace_name]
|
240
|
+
|
241
|
+
return self unless keyspace
|
242
|
+
|
243
|
+
type = keyspace.type(type_name)
|
244
|
+
|
245
|
+
return self unless type
|
246
|
+
|
247
|
+
keyspace = keyspace.delete_type(type_name)
|
248
|
+
|
249
|
+
synchronize do
|
250
|
+
keyspaces = @keyspaces.dup
|
251
|
+
keyspaces[keyspace_name] = keyspace
|
252
|
+
@keyspaces = keyspaces
|
253
|
+
end
|
254
|
+
|
255
|
+
keyspace_changed(keyspace)
|
256
|
+
|
257
|
+
self
|
258
|
+
end
|
259
|
+
|
260
|
+
def replace_function(function)
|
261
|
+
keyspace = @keyspaces[function.keyspace]
|
262
|
+
|
263
|
+
return self unless keyspace
|
264
|
+
|
265
|
+
old_function = keyspace.function(function.name, *function.argument_types)
|
266
|
+
|
267
|
+
return self if old_function == function
|
268
|
+
|
269
|
+
keyspace = keyspace.update_function(function)
|
270
|
+
|
271
|
+
synchronize do
|
272
|
+
keyspaces = @keyspaces.dup
|
273
|
+
keyspaces[keyspace.name] = keyspace
|
274
|
+
@keyspaces = keyspaces
|
275
|
+
end
|
276
|
+
|
277
|
+
keyspace_changed(keyspace)
|
278
|
+
|
279
|
+
self
|
280
|
+
end
|
281
|
+
|
282
|
+
def delete_function(keyspace_name, function_name, function_arg_types)
|
283
|
+
keyspace = @keyspaces[keyspace_name]
|
284
|
+
|
285
|
+
return self unless keyspace
|
286
|
+
|
287
|
+
function = keyspace.function(function_name, *function_arg_types)
|
288
|
+
|
289
|
+
return self unless function
|
290
|
+
|
291
|
+
keyspace = keyspace.delete_function(function_name, function_arg_types)
|
292
|
+
|
293
|
+
synchronize do
|
294
|
+
keyspaces = @keyspaces.dup
|
295
|
+
keyspaces[keyspace_name] = keyspace
|
296
|
+
@keyspaces = keyspaces
|
297
|
+
end
|
298
|
+
|
299
|
+
keyspace_changed(keyspace)
|
300
|
+
|
301
|
+
self
|
302
|
+
end
|
303
|
+
|
304
|
+
def replace_aggregate(aggregate)
|
305
|
+
keyspace = @keyspaces[aggregate.keyspace]
|
306
|
+
|
307
|
+
return self unless keyspace
|
308
|
+
|
309
|
+
old_aggregate = keyspace.aggregate(aggregate.name, *aggregate.argument_types)
|
310
|
+
|
311
|
+
return self if old_aggregate == aggregate
|
312
|
+
|
313
|
+
keyspace = keyspace.update_aggregate(aggregate)
|
314
|
+
|
315
|
+
synchronize do
|
316
|
+
keyspaces = @keyspaces.dup
|
317
|
+
keyspaces[keyspace.name] = keyspace
|
318
|
+
@keyspaces = keyspaces
|
319
|
+
end
|
320
|
+
|
321
|
+
keyspace_changed(keyspace)
|
322
|
+
|
323
|
+
self
|
324
|
+
end
|
325
|
+
|
326
|
+
def delete_aggregate(keyspace_name, aggregate_name, aggregate_arg_types)
|
327
|
+
keyspace = @keyspaces[keyspace_name]
|
328
|
+
|
329
|
+
return self unless keyspace
|
330
|
+
|
331
|
+
aggregate = keyspace.aggregate(aggregate_name, *aggregate_arg_types)
|
332
|
+
|
333
|
+
return self unless aggregate
|
334
|
+
|
335
|
+
keyspace = keyspace.delete_aggregate(aggregate_name, aggregate_arg_types)
|
336
|
+
|
337
|
+
synchronize do
|
338
|
+
keyspaces = @keyspaces.dup
|
339
|
+
keyspaces[keyspace_name] = keyspace
|
340
|
+
@keyspaces = keyspaces
|
341
|
+
end
|
342
|
+
|
343
|
+
keyspace_changed(keyspace)
|
344
|
+
|
345
|
+
self
|
346
|
+
end
|
347
|
+
|
348
|
+
def has_keyspace?(name)
|
349
|
+
@keyspaces.include?(name)
|
350
|
+
end
|
351
|
+
|
352
|
+
def keyspace(name)
|
353
|
+
@keyspaces[name]
|
354
|
+
end
|
355
|
+
|
356
|
+
def each_keyspace(&block)
|
357
|
+
if block_given?
|
358
|
+
@keyspaces.each_value(&block)
|
359
|
+
self
|
360
|
+
else
|
361
|
+
@keyspaces.values
|
362
|
+
end
|
363
|
+
end
|
364
|
+
alias keyspaces each_keyspace
|
365
|
+
|
366
|
+
private
|
367
|
+
|
368
|
+
def keyspace_created(keyspace)
|
369
|
+
@listeners.each do |listener|
|
370
|
+
begin
|
371
|
+
listener.keyspace_created(keyspace)
|
372
|
+
rescue
|
373
|
+
nil
|
374
|
+
end
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def keyspace_changed(keyspace)
|
379
|
+
@listeners.each do |listener|
|
380
|
+
begin
|
381
|
+
listener.keyspace_changed(keyspace)
|
382
|
+
rescue
|
383
|
+
nil
|
384
|
+
end
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
388
|
+
def keyspace_dropped(keyspace)
|
389
|
+
@listeners.each do |listener|
|
390
|
+
begin
|
391
|
+
listener.keyspace_dropped(keyspace)
|
392
|
+
rescue
|
393
|
+
nil
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
require 'cassandra/cluster/schema/cql_type_parser'
|
402
|
+
require 'cassandra/cluster/schema/fetchers'
|
403
|
+
require 'cassandra/cluster/schema/partitioners'
|
404
|
+
require 'cassandra/cluster/schema/replication_strategies'
|
405
|
+
require 'cassandra/cluster/schema/fqcn_type_parser'
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 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
|
+
class Cluster
|
21
|
+
class Schema
|
22
|
+
class CQLTypeParser
|
23
|
+
IncompleteTypeError = ::Class.new(::StandardError)
|
24
|
+
|
25
|
+
# @private
|
26
|
+
Node = Struct.new(:parent, :name, :children)
|
27
|
+
|
28
|
+
def parse(string, types)
|
29
|
+
frozen = false
|
30
|
+
node = parse_node(string)
|
31
|
+
|
32
|
+
if node.name == 'frozen'
|
33
|
+
frozen = true
|
34
|
+
node = node.children.first
|
35
|
+
end
|
36
|
+
|
37
|
+
[lookup_type(node, types), frozen]
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def lookup_type(node, types)
|
43
|
+
case node.name
|
44
|
+
when 'text' then Cassandra::Types.text
|
45
|
+
when 'blob' then Cassandra::Types.blob
|
46
|
+
when 'ascii' then Cassandra::Types.ascii
|
47
|
+
when 'bigint' then Cassandra::Types.bigint
|
48
|
+
when 'counter' then Cassandra::Types.counter
|
49
|
+
when 'int' then Cassandra::Types.int
|
50
|
+
when 'varint' then Cassandra::Types.varint
|
51
|
+
when 'boolean' then Cassandra::Types.boolean
|
52
|
+
when 'decimal' then Cassandra::Types.decimal
|
53
|
+
when 'double' then Cassandra::Types.double
|
54
|
+
when 'float' then Cassandra::Types.float
|
55
|
+
when 'inet' then Cassandra::Types.inet
|
56
|
+
when 'timestamp' then Cassandra::Types.timestamp
|
57
|
+
when 'uuid' then Cassandra::Types.uuid
|
58
|
+
when 'timeuuid' then Cassandra::Types.timeuuid
|
59
|
+
when 'date' then Cassandra::Types.date
|
60
|
+
when 'smallint' then Cassandra::Types.smallint
|
61
|
+
when 'time' then Cassandra::Types.time
|
62
|
+
when 'tinyint' then Cassandra::Types.tinyint
|
63
|
+
when 'map' then
|
64
|
+
Cassandra::Types.map(*node.children.map { |t| lookup_type(t, types)})
|
65
|
+
when 'set' then
|
66
|
+
Cassandra::Types.set(lookup_type(node.children.first, types))
|
67
|
+
when 'list' then
|
68
|
+
Cassandra::Types.list(lookup_type(node.children.first, types))
|
69
|
+
when 'tuple' then
|
70
|
+
Cassandra::Types.tuple(*node.children.map { |t| lookup_type(t, types)})
|
71
|
+
when 'frozen' then
|
72
|
+
Cassandra::Types.frozen(lookup_type(node.children.first, types))
|
73
|
+
when 'empty' then
|
74
|
+
Cassandra::Types.custom('org.apache.cassandra.db.marshal.EmptyType')
|
75
|
+
when /\A'/ then
|
76
|
+
# Custom type.
|
77
|
+
Cassandra::Types.custom(node.name[1..-2])
|
78
|
+
else
|
79
|
+
types.fetch(node.name) do
|
80
|
+
raise IncompleteTypeError, "unable to lookup type #{node.name.inspect}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def parse_node(string)
|
86
|
+
root = node = Node.new(nil, '', [])
|
87
|
+
|
88
|
+
string.each_char do |char|
|
89
|
+
case char
|
90
|
+
when '<' # starting type params
|
91
|
+
child = Node.new(node, '', [])
|
92
|
+
node.children << child
|
93
|
+
node = child
|
94
|
+
when ','
|
95
|
+
child = Node.new(node.parent, '', [])
|
96
|
+
node.parent.children << child
|
97
|
+
node = child
|
98
|
+
when '>'
|
99
|
+
node = node.parent
|
100
|
+
when ' '
|
101
|
+
next
|
102
|
+
else
|
103
|
+
node.name << char unless char == '"'
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
root
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|