yugabyte-ycql-driver 3.2.3.1
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 +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,32 @@
|
|
|
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
|
+
module Statement
|
|
21
|
+
# Determines whether or not the statement is safe to retry on timeout
|
|
22
|
+
# @return [Boolean] whether the statement is safe to retry on timeout
|
|
23
|
+
def idempotent?
|
|
24
|
+
!!@idempotent
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# @private
|
|
28
|
+
def accept(client, options)
|
|
29
|
+
raise NotImplementedError, "#{self.class} must implement :accept method"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
require 'cassandra/statements/batch'
|
|
20
|
+
require 'cassandra/statements/bound'
|
|
21
|
+
require 'cassandra/statements/prepared'
|
|
22
|
+
require 'cassandra/statements/simple'
|
|
23
|
+
require 'cassandra/statements/void'
|
|
@@ -0,0 +1,146 @@
|
|
|
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
|
+
module Statements
|
|
21
|
+
# Batch statement groups several {Cassandra::Statement}. There are several
|
|
22
|
+
# types of Batch statements available:
|
|
23
|
+
# @see Cassandra::Session#batch
|
|
24
|
+
# @see Cassandra::Session#logged_batch
|
|
25
|
+
# @see Cassandra::Session#unlogged_batch
|
|
26
|
+
# @see Cassandra::Session#counter_batch
|
|
27
|
+
class Batch
|
|
28
|
+
# @private
|
|
29
|
+
class Logged < Batch
|
|
30
|
+
def type
|
|
31
|
+
:logged
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# @private
|
|
36
|
+
class Unlogged < Batch
|
|
37
|
+
def type
|
|
38
|
+
:unlogged
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# @private
|
|
43
|
+
class Counter < Batch
|
|
44
|
+
def type
|
|
45
|
+
:counter
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Determines whether or not the statement is safe to retry on timeout
|
|
49
|
+
# Counter batches are never considered idempotent.
|
|
50
|
+
# @return [Boolean] whether the statement is safe to retry on timeout
|
|
51
|
+
def idempotent?
|
|
52
|
+
false
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
include Statement
|
|
57
|
+
|
|
58
|
+
# @private
|
|
59
|
+
attr_reader :statements
|
|
60
|
+
|
|
61
|
+
# @private
|
|
62
|
+
def initialize(options)
|
|
63
|
+
@options = options
|
|
64
|
+
@statements = []
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Adds a statement to this batch.
|
|
68
|
+
#
|
|
69
|
+
# @param statement [String, Cassandra::Statements::Simple,
|
|
70
|
+
# Cassandra::Statements::Prepared, Cassandra::Statements::Bound]
|
|
71
|
+
# statement to add.
|
|
72
|
+
# @param options [Hash] (nil) a customizable set of options
|
|
73
|
+
# @option options [Array, Hash] :arguments (nil) positional or named
|
|
74
|
+
# arguments to bind, must contain the same number of parameters as the
|
|
75
|
+
# number of positional (`?`) or named (`:name`) markers in the CQL
|
|
76
|
+
# passed.
|
|
77
|
+
# @option options [Array, Hash] :type_hints (nil) override Util.guess_type
|
|
78
|
+
# to determine the CQL type for an argument; nil elements will fall-back
|
|
79
|
+
# to Util.guess_type.
|
|
80
|
+
# @option options [Boolean] :idempotent (false) specify whether this
|
|
81
|
+
# statement can be retried safely on timeout.
|
|
82
|
+
#
|
|
83
|
+
# @note Positional arguments for simple statements are only supported
|
|
84
|
+
# starting with Apache Cassandra 2.0 and above.
|
|
85
|
+
#
|
|
86
|
+
# @note Named arguments for simple statements are only supported
|
|
87
|
+
# starting with Apache Cassandra 2.1 and above.
|
|
88
|
+
#
|
|
89
|
+
# @return [self]
|
|
90
|
+
def add(statement, options = nil)
|
|
91
|
+
options = if options.is_a?(::Hash)
|
|
92
|
+
@options.override(options)
|
|
93
|
+
else
|
|
94
|
+
@options
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
case statement
|
|
98
|
+
when String
|
|
99
|
+
@statements << Simple.new(statement,
|
|
100
|
+
options.arguments,
|
|
101
|
+
options.type_hints,
|
|
102
|
+
options.idempotent?)
|
|
103
|
+
when Prepared
|
|
104
|
+
@statements << statement.bind(options.arguments)
|
|
105
|
+
when Bound, Simple
|
|
106
|
+
@statements << statement
|
|
107
|
+
else
|
|
108
|
+
raise ::ArgumentError,
|
|
109
|
+
'a batch can only consist of simple or prepared statements, ' \
|
|
110
|
+
"#{statement.inspect} given"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
self
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# @private
|
|
117
|
+
def accept(client, options)
|
|
118
|
+
Util.assert_not_empty(statements) { 'batch cannot be empty' }
|
|
119
|
+
client.batch(self, options)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Determines whether or not the statement is safe to retry on timeout
|
|
123
|
+
# Batches are idempotent only when all statements in a batch are.
|
|
124
|
+
# @return [Boolean] whether the statement is safe to retry on timeout
|
|
125
|
+
def idempotent?
|
|
126
|
+
@statements.all?(&:idempotent?)
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# A batch statement doesn't really have any cql of its own as it is composed of
|
|
130
|
+
# multiple different statements
|
|
131
|
+
# @return [nil] nothing
|
|
132
|
+
def cql
|
|
133
|
+
nil
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# @return [Symbol] one of `:logged`, `:unlogged` or `:counter`
|
|
137
|
+
def type
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# @return [String] a CLI-friendly batch statement representation
|
|
141
|
+
def inspect
|
|
142
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @type=#{type.inspect}>"
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
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
|
+
module Statements
|
|
21
|
+
# a Bound statement is created using {Cassandra::Statements::Prepared#bind}
|
|
22
|
+
class Bound
|
|
23
|
+
include Statement
|
|
24
|
+
|
|
25
|
+
# @return [String] original cql used to prepare this statement
|
|
26
|
+
attr_reader :cql
|
|
27
|
+
# @return [Array<Object>] a list of positional parameters for the cql
|
|
28
|
+
attr_reader :params
|
|
29
|
+
# @private
|
|
30
|
+
attr_reader :params_types, :result_metadata, :keyspace, :partition_key
|
|
31
|
+
# @private prepared-statement id
|
|
32
|
+
attr_reader :id
|
|
33
|
+
|
|
34
|
+
# @private
|
|
35
|
+
def initialize(id,
|
|
36
|
+
cql,
|
|
37
|
+
params_types,
|
|
38
|
+
result_metadata,
|
|
39
|
+
params,
|
|
40
|
+
keyspace = nil,
|
|
41
|
+
partition_key = nil,
|
|
42
|
+
idempotent = false)
|
|
43
|
+
@id = id
|
|
44
|
+
@cql = cql
|
|
45
|
+
@params_types = params_types
|
|
46
|
+
@result_metadata = result_metadata
|
|
47
|
+
@params = params
|
|
48
|
+
@keyspace = keyspace
|
|
49
|
+
@partition_key = partition_key
|
|
50
|
+
@idempotent = idempotent
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @private
|
|
54
|
+
def accept(client, options)
|
|
55
|
+
client.execute(self, options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# @return [String] a CLI-friendly bound statement representation
|
|
59
|
+
def inspect
|
|
60
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect} " \
|
|
61
|
+
"@params=#{@params}>"
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,235 @@
|
|
|
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
|
+
module Statements
|
|
21
|
+
# A prepared statement is created by calling {Cassandra::Session#prepare}
|
|
22
|
+
# or {Cassandra::Session#prepare_async}.
|
|
23
|
+
class Prepared
|
|
24
|
+
include Statement
|
|
25
|
+
|
|
26
|
+
# @return [String] original cql used to prepare this statement
|
|
27
|
+
attr_reader :cql
|
|
28
|
+
# @private
|
|
29
|
+
attr_reader :result_metadata
|
|
30
|
+
# @private prepared-statement id
|
|
31
|
+
attr_reader :id
|
|
32
|
+
|
|
33
|
+
# @private
|
|
34
|
+
def initialize(id,
|
|
35
|
+
payload,
|
|
36
|
+
warnings,
|
|
37
|
+
cql,
|
|
38
|
+
params_metadata,
|
|
39
|
+
result_metadata,
|
|
40
|
+
partition_key,
|
|
41
|
+
trace_id,
|
|
42
|
+
keyspace,
|
|
43
|
+
statement,
|
|
44
|
+
options,
|
|
45
|
+
hosts,
|
|
46
|
+
consistency,
|
|
47
|
+
retries,
|
|
48
|
+
client,
|
|
49
|
+
connection_options)
|
|
50
|
+
@id = id
|
|
51
|
+
@payload = payload
|
|
52
|
+
@warnings = warnings
|
|
53
|
+
@cql = cql
|
|
54
|
+
@params_metadata = params_metadata
|
|
55
|
+
@result_metadata = result_metadata
|
|
56
|
+
@partition_key = partition_key
|
|
57
|
+
@trace_id = trace_id
|
|
58
|
+
@keyspace = keyspace
|
|
59
|
+
@statement = statement
|
|
60
|
+
@options = options
|
|
61
|
+
@hosts = hosts
|
|
62
|
+
@consistency = consistency
|
|
63
|
+
@retries = retries
|
|
64
|
+
@client = client
|
|
65
|
+
@connection_options = connection_options
|
|
66
|
+
@idempotent = options.idempotent?
|
|
67
|
+
@payload = payload
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
# Creates a statement bound with specific arguments
|
|
71
|
+
#
|
|
72
|
+
# @param args [Array, Hash] (nil) positional or named arguments to bind,
|
|
73
|
+
# must contain the same number of parameters as the number of positional
|
|
74
|
+
# (`?`) or named (`:name`) markers in the original CQL passed to
|
|
75
|
+
# {Cassandra::Session#prepare}
|
|
76
|
+
#
|
|
77
|
+
# @return [Cassandra::Statements::Bound] bound statement
|
|
78
|
+
def bind(args = nil)
|
|
79
|
+
if args
|
|
80
|
+
Util.assert_instance_of_one_of([::Array, ::Hash], args) do
|
|
81
|
+
"args must be an Array or a Hash, #{args.inspect} given"
|
|
82
|
+
end
|
|
83
|
+
else
|
|
84
|
+
args = EMPTY_LIST
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
params = []
|
|
88
|
+
param_types = []
|
|
89
|
+
|
|
90
|
+
if args.is_a?(::Hash)
|
|
91
|
+
@params_metadata.each do |(_, _, name, type)|
|
|
92
|
+
name = name.to_sym unless args.key?(name)
|
|
93
|
+
value = args.fetch(name, NOT_SET)
|
|
94
|
+
|
|
95
|
+
if NOT_SET.eql?(value)
|
|
96
|
+
if @connection_options.protocol_version < 4
|
|
97
|
+
raise ::ArgumentError,
|
|
98
|
+
"argument #{name.inspect} it not present in #{args.inspect}"
|
|
99
|
+
end
|
|
100
|
+
else
|
|
101
|
+
Util.assert_type(type, value) do
|
|
102
|
+
"argument for #{name.inspect} must be #{type}, #{value} given"
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
params << value
|
|
107
|
+
param_types << type
|
|
108
|
+
end
|
|
109
|
+
else
|
|
110
|
+
Util.assert_equal(@params_metadata.size, args.size) do
|
|
111
|
+
"expecting exactly #{@params_metadata.size} bind parameters, " \
|
|
112
|
+
"#{args.size} given"
|
|
113
|
+
end
|
|
114
|
+
@params_metadata.zip(args) do |(_, _, name, type), value|
|
|
115
|
+
if NOT_SET.eql?(value)
|
|
116
|
+
if @connection_options.protocol_version < 4
|
|
117
|
+
raise ::ArgumentError,
|
|
118
|
+
"argument #{name.inspect} it not present in #{args.inspect}"
|
|
119
|
+
end
|
|
120
|
+
else
|
|
121
|
+
Util.assert_type(type, value) do
|
|
122
|
+
"argument for #{name.inspect} must be #{type}, #{value} given"
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
params << value
|
|
127
|
+
param_types << type
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# params_metadata is an array of column-specs; each column-spec is an array
|
|
132
|
+
# of keyspace, tablename, other stuff. We only care about the keyspace name.
|
|
133
|
+
# See read_prepared_metadata_v4 in coder.rb for more details.
|
|
134
|
+
keyspace_name = @params_metadata.first.first unless @params_metadata.empty?
|
|
135
|
+
|
|
136
|
+
partition_key = create_partition_key(params)
|
|
137
|
+
|
|
138
|
+
Bound.new(@id,
|
|
139
|
+
@cql,
|
|
140
|
+
param_types,
|
|
141
|
+
@result_metadata,
|
|
142
|
+
params,
|
|
143
|
+
keyspace_name,
|
|
144
|
+
partition_key,
|
|
145
|
+
@idempotent)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# @return [Cassandra::Execution::Info] execution info for PREPARE request
|
|
149
|
+
def execution_info
|
|
150
|
+
@info ||= Execution::Info.new(@payload,
|
|
151
|
+
@warnings,
|
|
152
|
+
@keyspace,
|
|
153
|
+
@statement,
|
|
154
|
+
@options,
|
|
155
|
+
@hosts,
|
|
156
|
+
@consistency,
|
|
157
|
+
@retries,
|
|
158
|
+
@trace_id ?
|
|
159
|
+
Execution::Trace.new(@trace_id, @client, @options.load_balancing_policy) :
|
|
160
|
+
nil)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
# @private
|
|
164
|
+
def accept(client, options)
|
|
165
|
+
client.execute(bind(options.arguments), options)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# @return [String] a CLI-friendly prepared statement representation
|
|
169
|
+
def inspect
|
|
170
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect}>"
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
private
|
|
174
|
+
|
|
175
|
+
def create_partition_key(values)
|
|
176
|
+
partition_key = @partition_key
|
|
177
|
+
return nil if partition_key.empty? || partition_key.size > values.size
|
|
178
|
+
params_metadata = @params_metadata
|
|
179
|
+
|
|
180
|
+
buffer = Protocol::CqlByteBuffer.new
|
|
181
|
+
if partition_key.one?
|
|
182
|
+
i = partition_key.first
|
|
183
|
+
value = values[i]
|
|
184
|
+
metadata = params_metadata[i]
|
|
185
|
+
name = metadata[2]
|
|
186
|
+
type = metadata[3]
|
|
187
|
+
|
|
188
|
+
if NOT_SET.eql?(value)
|
|
189
|
+
raise ::ArgumentError, "argument #{name.inspect} is a part of " \
|
|
190
|
+
'the partition key and must be present.'
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
if @connection_options.protocol_version >= 4
|
|
194
|
+
Protocol::Coder.write_value_v4(buffer, value, type)
|
|
195
|
+
elsif @connection_options.protocol_version >= 3
|
|
196
|
+
Protocol::Coder.write_value_v3(buffer, value, type)
|
|
197
|
+
else
|
|
198
|
+
Protocol::Coder.write_value_v1(buffer, value, type)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
buffer.discard(4) # discard size
|
|
202
|
+
else
|
|
203
|
+
buf = Protocol::CqlByteBuffer.new
|
|
204
|
+
partition_key.each do |ind|
|
|
205
|
+
value = values[ind]
|
|
206
|
+
metadata = params_metadata[ind]
|
|
207
|
+
name = metadata[2]
|
|
208
|
+
type = metadata[3]
|
|
209
|
+
|
|
210
|
+
if NOT_SET.eql?(value)
|
|
211
|
+
raise ::ArgumentError, "argument #{name.inspect} is a part of " \
|
|
212
|
+
'the partition key and must be present.'
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
if @connection_options.protocol_version >= 4
|
|
216
|
+
Protocol::Coder.write_value_v4(buf, value, type)
|
|
217
|
+
elsif @connection_options.protocol_version >= 3
|
|
218
|
+
Protocol::Coder.write_value_v3(buf, value, type)
|
|
219
|
+
else
|
|
220
|
+
Protocol::Coder.write_value_v1(buf, value, type)
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
buf.discard(4) # discard size
|
|
224
|
+
|
|
225
|
+
size = buf.length
|
|
226
|
+
buffer.append_short(size)
|
|
227
|
+
buffer << buf.read(size) << NULL_BYTE
|
|
228
|
+
end
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
buffer.to_str
|
|
232
|
+
end
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
end
|