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,50 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class ErrorResponse < Response
|
|
22
|
+
attr_reader :code, :message
|
|
23
|
+
|
|
24
|
+
def initialize(*args)
|
|
25
|
+
@code, @message = args
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
29
|
+
code = buffer.read_int
|
|
30
|
+
message = buffer.read_string
|
|
31
|
+
case code
|
|
32
|
+
when 0x1000, 0x1100, 0x1200, 0x2400, 0x2500
|
|
33
|
+
new_length = length - 4 - 4 - message.bytesize
|
|
34
|
+
DetailedErrorResponse.decode(code, message, protocol_version, buffer, new_length)
|
|
35
|
+
else
|
|
36
|
+
new(code, message)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_s
|
|
41
|
+
hex_code = @code.to_s(16).rjust(4, '0').upcase
|
|
42
|
+
%(ERROR 0x#{hex_code} "#@message")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
RESPONSE_TYPES[0x00] = self
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class EventResponse < ResultResponse
|
|
22
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
23
|
+
type = buffer.read_string
|
|
24
|
+
impl = EVENT_TYPES[type]
|
|
25
|
+
raise UnsupportedEventTypeError, %(Unsupported event type: "#{type}") unless impl
|
|
26
|
+
new_length = length - 4 - type.bytesize
|
|
27
|
+
impl.decode(protocol_version, buffer, new_length, trace_id)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
RESPONSE_TYPES[0x0c] = self
|
|
33
|
+
|
|
34
|
+
EVENT_TYPES = {
|
|
35
|
+
# populated by subclasses
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class PreparedResultResponse < ResultResponse
|
|
22
|
+
attr_reader :id, :metadata, :result_metadata
|
|
23
|
+
|
|
24
|
+
def initialize(id, metadata, result_metadata, trace_id)
|
|
25
|
+
super(trace_id)
|
|
26
|
+
@id, @metadata, @result_metadata = id, metadata, result_metadata
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
30
|
+
id = buffer.read_short_bytes
|
|
31
|
+
metadata, _ = RowsResultResponse.read_metadata(protocol_version, buffer)
|
|
32
|
+
result_metadata = nil
|
|
33
|
+
if protocol_version > 1
|
|
34
|
+
result_metadata, _, _ = RowsResultResponse.read_metadata(protocol_version, buffer)
|
|
35
|
+
end
|
|
36
|
+
new(id, metadata, result_metadata, trace_id)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def eql?(other)
|
|
40
|
+
self.id == other.id && self.metadata == other.metadata && self.trace_id == other.trace_id
|
|
41
|
+
end
|
|
42
|
+
alias_method :==, :eql?
|
|
43
|
+
|
|
44
|
+
def hash
|
|
45
|
+
@h ||= begin
|
|
46
|
+
h = 0
|
|
47
|
+
h = ((h & 0x01ffffff) * 31) ^ @id.hash
|
|
48
|
+
h = ((h & 0x01ffffff) * 31) ^ @metadata.hash
|
|
49
|
+
h = ((h & 0x01ffffff) * 31) ^ @trace_id.hash
|
|
50
|
+
h
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def to_s
|
|
55
|
+
hex_id = @id.each_byte.map { |x| x.to_s(16).rjust(2, '0') }.join('')
|
|
56
|
+
%(RESULT PREPARED #{hex_id} #@metadata)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
RESULT_TYPES[0x04] = self
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class RawRowsResultResponse < RowsResultResponse
|
|
22
|
+
def initialize(protocol_version, raw_rows, paging_state, trace_id)
|
|
23
|
+
super(nil, nil, paging_state, trace_id)
|
|
24
|
+
@protocol_version = protocol_version
|
|
25
|
+
@raw_rows = raw_rows
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def materialize(metadata)
|
|
29
|
+
@metadata = metadata
|
|
30
|
+
@rows = RowsResultResponse.read_rows(@protocol_version, @raw_rows, @metadata)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def rows
|
|
34
|
+
raise UnmaterializedRowsError, 'Not materialized!' unless @rows
|
|
35
|
+
@rows
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def to_s
|
|
39
|
+
%(RESULT ROWS (raw))
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class ReadyResponse < Response
|
|
22
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
23
|
+
new
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def eql?(rs)
|
|
27
|
+
self.class === rs
|
|
28
|
+
end
|
|
29
|
+
alias_method :==, :eql?
|
|
30
|
+
|
|
31
|
+
def hash
|
|
32
|
+
@h ||= to_s.hash ^ 0xbadc0de
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def to_s
|
|
36
|
+
'READY'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
RESPONSE_TYPES[0x02] = self
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class ResultResponse < Response
|
|
22
|
+
attr_reader :trace_id
|
|
23
|
+
|
|
24
|
+
def initialize(trace_id)
|
|
25
|
+
@trace_id = trace_id
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
29
|
+
kind = buffer.read_int
|
|
30
|
+
impl = RESULT_TYPES[kind]
|
|
31
|
+
raise UnsupportedResultKindError, %(Unsupported result kind: #{kind}) unless impl
|
|
32
|
+
impl.decode(protocol_version, buffer, length - 4, trace_id)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def void?
|
|
36
|
+
false
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
RESPONSE_TYPES[0x08] = self
|
|
42
|
+
|
|
43
|
+
RESULT_TYPES = [
|
|
44
|
+
# populated by subclasses
|
|
45
|
+
]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class RowsResultResponse < ResultResponse
|
|
22
|
+
attr_reader :rows, :metadata, :paging_state
|
|
23
|
+
|
|
24
|
+
def initialize(rows, metadata, paging_state, trace_id)
|
|
25
|
+
super(trace_id)
|
|
26
|
+
@rows, @metadata, @paging_state = rows, metadata, paging_state
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
30
|
+
original_buffer_length = buffer.length
|
|
31
|
+
column_specs, columns_count, paging_state = read_metadata(protocol_version, buffer)
|
|
32
|
+
if column_specs.nil?
|
|
33
|
+
consumed_bytes = original_buffer_length - buffer.length
|
|
34
|
+
remaining_bytes = CqlByteBuffer.new(buffer.read(length - consumed_bytes))
|
|
35
|
+
RawRowsResultResponse.new(protocol_version, remaining_bytes, paging_state, trace_id)
|
|
36
|
+
else
|
|
37
|
+
new(read_rows(protocol_version, buffer, column_specs), column_specs, paging_state, trace_id)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def to_s
|
|
42
|
+
%(RESULT ROWS #@metadata #@rows)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
RESULT_TYPES[0x02] = self
|
|
48
|
+
|
|
49
|
+
COLUMN_TYPES = [
|
|
50
|
+
nil,
|
|
51
|
+
:ascii,
|
|
52
|
+
:bigint,
|
|
53
|
+
:blob,
|
|
54
|
+
:boolean,
|
|
55
|
+
:counter,
|
|
56
|
+
:decimal,
|
|
57
|
+
:double,
|
|
58
|
+
:float,
|
|
59
|
+
:int,
|
|
60
|
+
:text,
|
|
61
|
+
:timestamp,
|
|
62
|
+
:uuid,
|
|
63
|
+
:varchar,
|
|
64
|
+
:varint,
|
|
65
|
+
:timeuuid,
|
|
66
|
+
:inet,
|
|
67
|
+
].freeze
|
|
68
|
+
|
|
69
|
+
TYPE_CONVERTER = TypeConverter.new
|
|
70
|
+
|
|
71
|
+
GLOBAL_TABLES_SPEC_FLAG = 0x01
|
|
72
|
+
HAS_MORE_PAGES_FLAG = 0x02
|
|
73
|
+
NO_METADATA_FLAG = 0x04
|
|
74
|
+
|
|
75
|
+
def self.read_column_type(buffer)
|
|
76
|
+
id, type = buffer.read_option do |id, b|
|
|
77
|
+
if id > 0 && id <= 0x10
|
|
78
|
+
COLUMN_TYPES[id]
|
|
79
|
+
elsif id == 0x20
|
|
80
|
+
sub_type = read_column_type(buffer)
|
|
81
|
+
[:list, sub_type]
|
|
82
|
+
elsif id == 0x21
|
|
83
|
+
key_type = read_column_type(buffer)
|
|
84
|
+
value_type = read_column_type(buffer)
|
|
85
|
+
[:map, key_type, value_type]
|
|
86
|
+
elsif id == 0x22
|
|
87
|
+
sub_type = read_column_type(buffer)
|
|
88
|
+
[:set, sub_type]
|
|
89
|
+
else
|
|
90
|
+
raise UnsupportedColumnTypeError, %(Unsupported column type: #{id})
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
type
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.read_metadata(protocol_version, buffer)
|
|
97
|
+
flags = buffer.read_int
|
|
98
|
+
columns_count = buffer.read_int
|
|
99
|
+
paging_state = nil
|
|
100
|
+
column_specs = nil
|
|
101
|
+
if flags & HAS_MORE_PAGES_FLAG != 0
|
|
102
|
+
paging_state = buffer.read_bytes
|
|
103
|
+
end
|
|
104
|
+
if flags & NO_METADATA_FLAG == 0
|
|
105
|
+
if flags & GLOBAL_TABLES_SPEC_FLAG != 0
|
|
106
|
+
global_keyspace_name = buffer.read_string
|
|
107
|
+
global_table_name = buffer.read_string
|
|
108
|
+
end
|
|
109
|
+
column_specs = columns_count.times.map do
|
|
110
|
+
if global_keyspace_name
|
|
111
|
+
keyspace_name = global_keyspace_name
|
|
112
|
+
table_name = global_table_name
|
|
113
|
+
else
|
|
114
|
+
keyspace_name = buffer.read_string
|
|
115
|
+
table_name = buffer.read_string
|
|
116
|
+
end
|
|
117
|
+
column_name = buffer.read_string
|
|
118
|
+
type = read_column_type(buffer)
|
|
119
|
+
[keyspace_name, table_name, column_name, type]
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
[column_specs, columns_count, paging_state]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def self.read_rows(protocol_version, buffer, column_specs)
|
|
126
|
+
rows_count = buffer.read_int
|
|
127
|
+
rows = []
|
|
128
|
+
rows_count.times do |row_index|
|
|
129
|
+
row = {}
|
|
130
|
+
column_specs.each do |column_spec|
|
|
131
|
+
row[column_spec[2]] = TYPE_CONVERTER.from_bytes(buffer, column_spec[3])
|
|
132
|
+
end
|
|
133
|
+
rows << row
|
|
134
|
+
end
|
|
135
|
+
rows
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class SchemaChangeEventResponse < EventResponse
|
|
22
|
+
TYPE = 'SCHEMA_CHANGE'.freeze
|
|
23
|
+
|
|
24
|
+
attr_reader :type, :change, :keyspace, :table
|
|
25
|
+
|
|
26
|
+
def initialize(*args)
|
|
27
|
+
@change, @keyspace, @table = args
|
|
28
|
+
@type = TYPE
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
32
|
+
new(buffer.read_string, buffer.read_string, buffer.read_string)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def eql?(rs)
|
|
36
|
+
rs.type == self.type && rs.change == self.change && rs.keyspace == self.keyspace && rs.table == self.table
|
|
37
|
+
end
|
|
38
|
+
alias_method :==, :eql?
|
|
39
|
+
|
|
40
|
+
def hash
|
|
41
|
+
@h ||= begin
|
|
42
|
+
h = 0
|
|
43
|
+
h = ((h & 33554431) * 31) ^ @type.hash
|
|
44
|
+
h = ((h & 33554431) * 31) ^ @change.hash
|
|
45
|
+
h = ((h & 33554431) * 31) ^ @keyspace.hash
|
|
46
|
+
h = ((h & 33554431) * 31) ^ @table.hash
|
|
47
|
+
h
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def to_s
|
|
52
|
+
%(EVENT #@type #@change "#@keyspace" "#@table")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
EVENT_TYPES[TYPE] = self
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class SchemaChangeResultResponse < ResultResponse
|
|
22
|
+
attr_reader :change, :keyspace, :table
|
|
23
|
+
|
|
24
|
+
def initialize(change, keyspace, table, trace_id)
|
|
25
|
+
super(trace_id)
|
|
26
|
+
@change, @keyspace, @table = change, keyspace, table
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
30
|
+
new(buffer.read_string, buffer.read_string, buffer.read_string, trace_id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def eql?(other)
|
|
34
|
+
self.change == other.change && self.keyspace == other.keyspace && self.table == other.table
|
|
35
|
+
end
|
|
36
|
+
alias_method :==, :eql?
|
|
37
|
+
|
|
38
|
+
def hash
|
|
39
|
+
@h ||= begin
|
|
40
|
+
h = 0
|
|
41
|
+
h = ((h & 0xffffffff) * 31) ^ @change.hash
|
|
42
|
+
h = ((h & 0xffffffff) * 31) ^ @keyspace.hash
|
|
43
|
+
h = ((h & 0xffffffff) * 31) ^ @table.hash
|
|
44
|
+
h
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def to_s
|
|
49
|
+
%(RESULT SCHEMA_CHANGE #@change "#@keyspace" "#@table")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
RESULT_TYPES[0x05] = self
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class SetKeyspaceResultResponse < ResultResponse
|
|
22
|
+
attr_reader :keyspace
|
|
23
|
+
|
|
24
|
+
def initialize(keyspace, trace_id)
|
|
25
|
+
super(trace_id)
|
|
26
|
+
@keyspace = keyspace
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
30
|
+
new(buffer.read_string, trace_id)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def to_s
|
|
34
|
+
%(RESULT SET_KEYSPACE "#@keyspace")
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
RESULT_TYPES[0x03] = self
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class StatusChangeEventResponse < EventResponse
|
|
22
|
+
TYPE = 'STATUS_CHANGE'.freeze
|
|
23
|
+
|
|
24
|
+
attr_reader :type, :change, :address, :port
|
|
25
|
+
|
|
26
|
+
def initialize(*args)
|
|
27
|
+
@change, @address, @port = args
|
|
28
|
+
@type = TYPE
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
32
|
+
new(buffer.read_string, *buffer.read_inet)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def to_s
|
|
36
|
+
%(EVENT #@type #@change #@address:#@port)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
EVENT_TYPES[TYPE] = self
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
module Protocol
|
|
21
|
+
class SupportedResponse < Response
|
|
22
|
+
attr_reader :options
|
|
23
|
+
|
|
24
|
+
def initialize(options)
|
|
25
|
+
@options = options
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.decode(protocol_version, buffer, length, trace_id=nil)
|
|
29
|
+
new(buffer.read_string_multimap)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def to_s
|
|
33
|
+
%(SUPPORTED #{options})
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
RESPONSE_TYPES[0x06] = self
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|