cassandra-driver 1.0.0.beta.2-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 +7 -0
- data/.yardopts +4 -0
- data/README.md +125 -0
- data/lib/cassandra/auth/providers/password.rb +73 -0
- data/lib/cassandra/auth/providers.rb +16 -0
- data/lib/cassandra/auth.rb +97 -0
- data/lib/cassandra/client/batch.rb +212 -0
- data/lib/cassandra/client/client.rb +591 -0
- data/lib/cassandra/client/column_metadata.rb +54 -0
- data/lib/cassandra/client/connection_manager.rb +72 -0
- data/lib/cassandra/client/connector.rb +277 -0
- data/lib/cassandra/client/execute_options_decoder.rb +59 -0
- data/lib/cassandra/client/null_logger.rb +37 -0
- data/lib/cassandra/client/peer_discovery.rb +50 -0
- data/lib/cassandra/client/prepared_statement.rb +314 -0
- data/lib/cassandra/client/query_result.rb +230 -0
- data/lib/cassandra/client/request_runner.rb +71 -0
- data/lib/cassandra/client/result_metadata.rb +48 -0
- data/lib/cassandra/client/void_result.rb +78 -0
- data/lib/cassandra/client.rb +144 -0
- data/lib/cassandra/cluster/client.rb +768 -0
- data/lib/cassandra/cluster/connector.rb +244 -0
- data/lib/cassandra/cluster/control_connection.rb +425 -0
- data/lib/cassandra/cluster/metadata.rb +124 -0
- data/lib/cassandra/cluster/options.rb +42 -0
- data/lib/cassandra/cluster/registry.rb +198 -0
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +47 -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/partitioners.rb +21 -0
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +92 -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/cluster/schema/replication_strategies.rb +21 -0
- data/lib/cassandra/cluster/schema/type_parser.rb +138 -0
- data/lib/cassandra/cluster/schema.rb +340 -0
- data/lib/cassandra/cluster.rb +215 -0
- data/lib/cassandra/column.rb +92 -0
- data/lib/cassandra/compression/compressors/lz4.rb +72 -0
- data/lib/cassandra/compression/compressors/snappy.rb +66 -0
- data/lib/cassandra/compression.rb +66 -0
- data/lib/cassandra/driver.rb +111 -0
- data/lib/cassandra/errors.rb +79 -0
- data/lib/cassandra/execution/info.rb +51 -0
- data/lib/cassandra/execution/options.rb +80 -0
- data/lib/cassandra/execution/trace.rb +152 -0
- data/lib/cassandra/future.rb +675 -0
- data/lib/cassandra/host.rb +79 -0
- data/lib/cassandra/keyspace.rb +133 -0
- data/lib/cassandra/listener.rb +87 -0
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +149 -0
- data/lib/cassandra/load_balancing/policies/round_robin.rb +132 -0
- data/lib/cassandra/load_balancing/policies/token_aware.rb +119 -0
- data/lib/cassandra/load_balancing/policies/white_list.rb +90 -0
- data/lib/cassandra/load_balancing/policies.rb +19 -0
- data/lib/cassandra/load_balancing.rb +113 -0
- data/lib/cassandra/protocol/cql_byte_buffer.rb +307 -0
- data/lib/cassandra/protocol/cql_protocol_handler.rb +323 -0
- data/lib/cassandra/protocol/frame_decoder.rb +128 -0
- data/lib/cassandra/protocol/frame_encoder.rb +48 -0
- data/lib/cassandra/protocol/request.rb +38 -0
- data/lib/cassandra/protocol/requests/auth_response_request.rb +47 -0
- data/lib/cassandra/protocol/requests/batch_request.rb +76 -0
- data/lib/cassandra/protocol/requests/credentials_request.rb +47 -0
- data/lib/cassandra/protocol/requests/execute_request.rb +103 -0
- data/lib/cassandra/protocol/requests/options_request.rb +39 -0
- data/lib/cassandra/protocol/requests/prepare_request.rb +50 -0
- data/lib/cassandra/protocol/requests/query_request.rb +153 -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 +38 -0
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +41 -0
- data/lib/cassandra/protocol/responses/auth_success_response.rb +41 -0
- data/lib/cassandra/protocol/responses/authenticate_response.rb +41 -0
- data/lib/cassandra/protocol/responses/detailed_error_response.rb +60 -0
- data/lib/cassandra/protocol/responses/error_response.rb +50 -0
- data/lib/cassandra/protocol/responses/event_response.rb +39 -0
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +64 -0
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +43 -0
- data/lib/cassandra/protocol/responses/ready_response.rb +44 -0
- data/lib/cassandra/protocol/responses/result_response.rb +48 -0
- data/lib/cassandra/protocol/responses/rows_result_response.rb +139 -0
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +60 -0
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +57 -0
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +42 -0
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +44 -0
- data/lib/cassandra/protocol/responses/supported_response.rb +41 -0
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +34 -0
- data/lib/cassandra/protocol/responses/void_result_response.rb +39 -0
- data/lib/cassandra/protocol/type_converter.rb +384 -0
- data/lib/cassandra/protocol.rb +93 -0
- data/lib/cassandra/reconnection/policies/constant.rb +48 -0
- data/lib/cassandra/reconnection/policies/exponential.rb +79 -0
- data/lib/cassandra/reconnection/policies.rb +20 -0
- data/lib/cassandra/reconnection.rb +49 -0
- data/lib/cassandra/result.rb +215 -0
- data/lib/cassandra/retry/policies/default.rb +47 -0
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +71 -0
- data/lib/cassandra/retry/policies/fallthrough.rb +39 -0
- data/lib/cassandra/retry/policies.rb +21 -0
- data/lib/cassandra/retry.rb +142 -0
- data/lib/cassandra/session.rb +202 -0
- data/lib/cassandra/statement.rb +22 -0
- data/lib/cassandra/statements/batch.rb +95 -0
- data/lib/cassandra/statements/bound.rb +48 -0
- data/lib/cassandra/statements/prepared.rb +81 -0
- data/lib/cassandra/statements/simple.rb +58 -0
- data/lib/cassandra/statements/void.rb +33 -0
- data/lib/cassandra/statements.rb +23 -0
- data/lib/cassandra/table.rb +299 -0
- data/lib/cassandra/time_uuid.rb +142 -0
- data/lib/cassandra/util.rb +167 -0
- data/lib/cassandra/uuid.rb +104 -0
- data/lib/cassandra/version.rb +21 -0
- data/lib/cassandra.rb +428 -0
- data/lib/cassandra_murmur3.jar +0 -0
- metadata +211 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
#--
|
|
4
|
+
# Copyright 2013-2014 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
|
+
require 'cassandra/cluster/schema/replication_strategies/simple'
|
|
20
|
+
require 'cassandra/cluster/schema/replication_strategies/network_topology'
|
|
21
|
+
require 'cassandra/cluster/schema/replication_strategies/none'
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
#--
|
|
4
|
+
# Copyright 2013-2014 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 TypeParser
|
|
23
|
+
# @private
|
|
24
|
+
Node = Struct.new(:parent, :name, :children)
|
|
25
|
+
# @private
|
|
26
|
+
Result = Struct.new(:results, :collections)
|
|
27
|
+
|
|
28
|
+
@@types = {
|
|
29
|
+
"org.apache.cassandra.db.marshal.AsciiType" => :ascii,
|
|
30
|
+
"org.apache.cassandra.db.marshal.LongType" => :bigint,
|
|
31
|
+
"org.apache.cassandra.db.marshal.BytesType" => :blob,
|
|
32
|
+
"org.apache.cassandra.db.marshal.BooleanType" => :boolean,
|
|
33
|
+
"org.apache.cassandra.db.marshal.CounterColumnType" => :counter,
|
|
34
|
+
"org.apache.cassandra.db.marshal.DecimalType" => :decimal,
|
|
35
|
+
"org.apache.cassandra.db.marshal.DoubleType" => :double,
|
|
36
|
+
"org.apache.cassandra.db.marshal.FloatType" => :float,
|
|
37
|
+
"org.apache.cassandra.db.marshal.InetAddressType" => :inet,
|
|
38
|
+
"org.apache.cassandra.db.marshal.Int32Type" => :int,
|
|
39
|
+
"org.apache.cassandra.db.marshal.UTF8Type" => :text,
|
|
40
|
+
"org.apache.cassandra.db.marshal.TimestampType" => :timestamp,
|
|
41
|
+
"org.apache.cassandra.db.marshal.DateType" => :timestamp,
|
|
42
|
+
"org.apache.cassandra.db.marshal.UUIDType" => :uuid,
|
|
43
|
+
"org.apache.cassandra.db.marshal.IntegerType" => :varint,
|
|
44
|
+
"org.apache.cassandra.db.marshal.TimeUUIDType" => :timeuuid,
|
|
45
|
+
"org.apache.cassandra.db.marshal.MapType" => :map,
|
|
46
|
+
"org.apache.cassandra.db.marshal.SetType" => :set,
|
|
47
|
+
"org.apache.cassandra.db.marshal.ListType" => :list
|
|
48
|
+
}.freeze
|
|
49
|
+
|
|
50
|
+
def parse(string)
|
|
51
|
+
create_result(parse_node(string))
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
def create_result(node)
|
|
57
|
+
collections = nil
|
|
58
|
+
results = []
|
|
59
|
+
|
|
60
|
+
if node.name == "org.apache.cassandra.db.marshal.CompositeType"
|
|
61
|
+
collections = {}
|
|
62
|
+
|
|
63
|
+
if node.children.last.name == "org.apache.cassandra.db.marshal.ColumnToCollectionType"
|
|
64
|
+
node.children.pop.children.each do |child|
|
|
65
|
+
key, name = child.name.split(":")
|
|
66
|
+
key = [key].pack('H*').force_encoding(::Encoding::UTF_8)
|
|
67
|
+
|
|
68
|
+
if name == "org.apache.cassandra.db.marshal.ReversedType"
|
|
69
|
+
collections[key] = lookup_type(child.children.first)
|
|
70
|
+
else
|
|
71
|
+
child.name = name
|
|
72
|
+
collections[key] = lookup_type(child)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
node.children.each do |child|
|
|
78
|
+
results << create_type(child)
|
|
79
|
+
end
|
|
80
|
+
else
|
|
81
|
+
results << create_type(node)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
Result.new(results, collections)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def create_type(node)
|
|
88
|
+
order = :asc
|
|
89
|
+
|
|
90
|
+
if node.name == "org.apache.cassandra.db.marshal.ReversedType"
|
|
91
|
+
order = :desc
|
|
92
|
+
node = node.children.first
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
[lookup_type(node), order]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def lookup_type(node)
|
|
99
|
+
type = @@types[node.name]
|
|
100
|
+
|
|
101
|
+
case type
|
|
102
|
+
when :set, :list
|
|
103
|
+
[type, lookup_type(node.children.first)]
|
|
104
|
+
when :map
|
|
105
|
+
[type, *node.children.map {|child| lookup_type(child)}]
|
|
106
|
+
else
|
|
107
|
+
type
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def parse_node(string)
|
|
112
|
+
root = node = Node.new(nil, '', [])
|
|
113
|
+
|
|
114
|
+
string.each_char do |char|
|
|
115
|
+
case char
|
|
116
|
+
when '(' # starting type params
|
|
117
|
+
child = Node.new(node, '', [])
|
|
118
|
+
node.children << child
|
|
119
|
+
node = child
|
|
120
|
+
when ','
|
|
121
|
+
child = Node.new(node.parent, '', [])
|
|
122
|
+
node.parent.children << child
|
|
123
|
+
node = child
|
|
124
|
+
when ')'
|
|
125
|
+
node = node.parent
|
|
126
|
+
when ' '
|
|
127
|
+
next
|
|
128
|
+
else
|
|
129
|
+
node.name << char
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
root
|
|
134
|
+
end
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
#--
|
|
4
|
+
# Copyright 2013-2014 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(schema_type_parser)
|
|
26
|
+
@type_parser = schema_type_parser
|
|
27
|
+
@keyspaces = ::Hash.new
|
|
28
|
+
@listeners = ::Set.new
|
|
29
|
+
|
|
30
|
+
mon_initialize
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def create_partition_key(keyspace, table, values)
|
|
34
|
+
keyspace = @keyspaces[keyspace]
|
|
35
|
+
keyspace && keyspace.create_partition_key(table, values)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def add_listener(listener)
|
|
39
|
+
synchronize do
|
|
40
|
+
@listeners = @listeners.dup.add(listener)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def remove_listener(listener)
|
|
47
|
+
synchronize do
|
|
48
|
+
@listeners = @listeners.dup.delete(listener)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
self
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def update_keyspaces(host, keyspaces, tables, columns)
|
|
55
|
+
columns = columns.each_with_object(deephash { [] }) do |row, index|
|
|
56
|
+
index[row['keyspace_name']] << row
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
tables = tables.each_with_object(deephash { [] }) do |row, index|
|
|
60
|
+
index[row['keyspace_name']] << row
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
current_keyspaces = ::Set.new
|
|
64
|
+
|
|
65
|
+
keyspaces.each do |row|
|
|
66
|
+
current_keyspaces << keyspace = row['keyspace_name']
|
|
67
|
+
|
|
68
|
+
update_keyspace(host, row, tables[keyspace], columns[keyspace])
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
@keyspaces.each do |name, keyspace|
|
|
72
|
+
delete_keyspace(name) unless current_keyspaces.include?(name)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
self
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def update_keyspace(host, keyspace, tables, columns)
|
|
79
|
+
keyspace_name = keyspace['keyspace_name']
|
|
80
|
+
|
|
81
|
+
columns = columns.each_with_object(deephash { ::Hash.new }) do |row, index|
|
|
82
|
+
index[row['columnfamily_name']][row['column_name']] = row
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
tables = tables.each_with_object(Hash.new) do |row, index|
|
|
86
|
+
name = row['columnfamily_name']
|
|
87
|
+
index[name] = create_table(row, columns[name], host.release_version)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
replication = Keyspace::Replication.new(keyspace['strategy_class'], ::JSON.load(keyspace['strategy_options']))
|
|
91
|
+
keyspace = Keyspace.new(keyspace_name, keyspace['durable_writes'], replication, tables)
|
|
92
|
+
|
|
93
|
+
return self if keyspace == @keyspaces[keyspace_name]
|
|
94
|
+
|
|
95
|
+
created = !@keyspaces.include?(keyspace_name)
|
|
96
|
+
|
|
97
|
+
synchronize do
|
|
98
|
+
keyspaces = @keyspaces.dup
|
|
99
|
+
keyspaces[keyspace_name] = keyspace
|
|
100
|
+
@keyspaces = keyspaces
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
if created
|
|
104
|
+
keyspace_created(keyspace)
|
|
105
|
+
else
|
|
106
|
+
keyspace_changed(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 udpate_table(host, keyspace_name, table, columns)
|
|
129
|
+
keyspace = @keyspaces[keyspace_name]
|
|
130
|
+
|
|
131
|
+
return self unless keyspace
|
|
132
|
+
|
|
133
|
+
table = create_table(table, columns, host.release_version)
|
|
134
|
+
keyspace = keyspace.update_table(table)
|
|
135
|
+
|
|
136
|
+
synchronize do
|
|
137
|
+
keyspaces = @keyspaces.dup
|
|
138
|
+
keyspaces[keyspace_name] = keyspace
|
|
139
|
+
@keyspaces = keyspaces
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
keyspace_updated(keyspace)
|
|
143
|
+
|
|
144
|
+
self
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def has_keyspace?(name)
|
|
148
|
+
@keyspaces.include?(name)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def keyspace(name)
|
|
152
|
+
@keyspaces[name]
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def each_keyspace(&block)
|
|
156
|
+
if block_given?
|
|
157
|
+
@keyspaces.each_value(&block)
|
|
158
|
+
self
|
|
159
|
+
else
|
|
160
|
+
@keyspaces.values
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
alias :keyspaces :each_keyspace
|
|
164
|
+
|
|
165
|
+
private
|
|
166
|
+
|
|
167
|
+
def create_table(table, columns, version)
|
|
168
|
+
keyspace = table['keyspace_name']
|
|
169
|
+
name = table['columnfamily_name']
|
|
170
|
+
key_validator = @type_parser.parse(table['key_validator'])
|
|
171
|
+
comparator = @type_parser.parse(table['comparator'])
|
|
172
|
+
column_aliases = ::JSON.load(table['column_aliases'])
|
|
173
|
+
|
|
174
|
+
clustering_size = find_clustering_size(comparator, columns.values,
|
|
175
|
+
column_aliases, version)
|
|
176
|
+
|
|
177
|
+
is_dense = clustering_size != comparator.results.size - 1
|
|
178
|
+
is_compact = is_dense || !comparator.collections
|
|
179
|
+
partition_key = []
|
|
180
|
+
clustering_columns = []
|
|
181
|
+
clustering_order = []
|
|
182
|
+
|
|
183
|
+
compaction_strategy = Table::Compaction.new(
|
|
184
|
+
table['compaction_strategy_class'],
|
|
185
|
+
::JSON.load(table['compaction_strategy_options'])
|
|
186
|
+
)
|
|
187
|
+
compression_parameters = ::JSON.load(table['compression_parameters'])
|
|
188
|
+
|
|
189
|
+
options = Table::Options.new(table, compaction_strategy, compression_parameters, is_compact, version)
|
|
190
|
+
columns = create_columns(key_validator, comparator, column_aliases, is_dense, clustering_size, table, columns, version, partition_key, clustering_columns, clustering_order)
|
|
191
|
+
|
|
192
|
+
Table.new(keyspace, name, partition_key, clustering_columns, columns, options, clustering_order)
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def find_clustering_size(comparator, columns, aliases, cassandra_version)
|
|
196
|
+
if cassandra_version.start_with?('1')
|
|
197
|
+
if comparator.collections
|
|
198
|
+
size = comparator.results.size
|
|
199
|
+
(!comparator.collections.empty? || aliases.size == size - 1 && comparator.results.last.first == :text) ? size - 1 : size
|
|
200
|
+
else
|
|
201
|
+
(!aliases.empty? || columns.empty?) ? 1 : 0
|
|
202
|
+
end
|
|
203
|
+
else
|
|
204
|
+
max_index = nil
|
|
205
|
+
|
|
206
|
+
columns.each do |cl|
|
|
207
|
+
if cl['type'].upcase == 'CLUSTERING_KEY'
|
|
208
|
+
index = cl['component_index'] || 0
|
|
209
|
+
|
|
210
|
+
if max_index.nil? || index > max_index
|
|
211
|
+
max_index = index
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
return 0 if max_index.nil?
|
|
217
|
+
|
|
218
|
+
max_index + 1
|
|
219
|
+
end
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def create_columns(key_validator, comparator, column_aliases, is_dense, clustering_size, table, columns, cassandra_version, partition_key, clustering_columns, clustering_order)
|
|
223
|
+
table_columns = {}
|
|
224
|
+
other_columns = []
|
|
225
|
+
|
|
226
|
+
if cassandra_version.start_with?('1')
|
|
227
|
+
key_aliases = ::JSON.load(table['key_aliases'])
|
|
228
|
+
|
|
229
|
+
key_validator.results.each_with_index do |(type, order), i|
|
|
230
|
+
key_alias = key_aliases.fetch(i) { i.zero? ? "key" : "key#{i + 1}" }
|
|
231
|
+
|
|
232
|
+
partition_key[i] = Column.new(key_alias, type, order)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
if comparator.results.size > 1
|
|
236
|
+
clustering_size.times do |i|
|
|
237
|
+
column_alias = column_aliases.fetch(i) { "column#{i + 1}" }
|
|
238
|
+
type, order = comparator.results.fetch(i)
|
|
239
|
+
|
|
240
|
+
clustering_columns[i] = Column.new(column_alias, type, order)
|
|
241
|
+
clustering_order[i] = order
|
|
242
|
+
end
|
|
243
|
+
else
|
|
244
|
+
column_alias = column_aliases.first || "column1"
|
|
245
|
+
type, order = comparator.results.first
|
|
246
|
+
|
|
247
|
+
clustering_columns[0] = Column.new(column_alias, type, order)
|
|
248
|
+
clustering_order[0] = order
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
if is_dense
|
|
252
|
+
value_alias = table['value_alias']
|
|
253
|
+
value_alias = 'value' if value_alias.nil? || value_alias.empty?
|
|
254
|
+
type, order = @type_parser.parse(table['default_validator']).results.first
|
|
255
|
+
other_columns << Column.new(value_alias, type, order)
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
columns.each do |name, row|
|
|
259
|
+
other_columns << create_column(row)
|
|
260
|
+
end
|
|
261
|
+
else
|
|
262
|
+
columns.each do |name, row|
|
|
263
|
+
next if row['column_name'].empty?
|
|
264
|
+
|
|
265
|
+
column = create_column(row)
|
|
266
|
+
type = row['type']
|
|
267
|
+
index = row['component_index'] || 0
|
|
268
|
+
|
|
269
|
+
case type.upcase
|
|
270
|
+
when 'PARTITION_KEY'
|
|
271
|
+
partition_key[index] = column
|
|
272
|
+
when 'CLUSTERING_KEY'
|
|
273
|
+
clustering_columns[index] = column
|
|
274
|
+
clustering_order[index] = column.order
|
|
275
|
+
else
|
|
276
|
+
other_columns << column
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
partition_key.each do |column|
|
|
282
|
+
table_columns[column.name] = column
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
clustering_columns.each do |column|
|
|
286
|
+
table_columns[column.name] = column
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
other_columns.each do |column|
|
|
290
|
+
table_columns[column.name] = column
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
table_columns
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def create_column(column)
|
|
297
|
+
name = column['column_name']
|
|
298
|
+
type, order = @type_parser.parse(column['validator']).results.first
|
|
299
|
+
is_static = (column['type'] == 'STATIC')
|
|
300
|
+
|
|
301
|
+
if column['index_type'].nil?
|
|
302
|
+
index = nil
|
|
303
|
+
elsif column['index_type'].upcase == 'CUSTOM' || !column['index_options']
|
|
304
|
+
index = Column::Index.new(column['index_name'])
|
|
305
|
+
else
|
|
306
|
+
options = ::JSON.load(column['index_options'])
|
|
307
|
+
index = Column::Index.new(column['index_name'], options['class_name'])
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
Column.new(name, type, order, index, is_static)
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
def deephash
|
|
314
|
+
::Hash.new {|hash, key| hash[key] = yield}
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def keyspace_created(keyspace)
|
|
318
|
+
@listeners.each do |listener|
|
|
319
|
+
listener.keyspace_created(keyspace) rescue nil
|
|
320
|
+
end
|
|
321
|
+
end
|
|
322
|
+
|
|
323
|
+
def keyspace_changed(keyspace)
|
|
324
|
+
@listeners.each do |listener|
|
|
325
|
+
listener.keyspace_changed(keyspace) rescue nil
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def keyspace_dropped(keyspace)
|
|
330
|
+
@listeners.each do |listener|
|
|
331
|
+
listener.keyspace_dropped(keyspace) rescue nil
|
|
332
|
+
end
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
end
|
|
336
|
+
end
|
|
337
|
+
|
|
338
|
+
require 'cassandra/cluster/schema/partitioners'
|
|
339
|
+
require 'cassandra/cluster/schema/replication_strategies'
|
|
340
|
+
require 'cassandra/cluster/schema/type_parser'
|