cassandra-driver 3.0.0.beta.1 → 3.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +90 -38
- data/ext/cassandra_murmur3/cassandra_murmur3.c +1 -1
- data/lib/cassandra.rb +327 -130
- data/lib/cassandra/address_resolution.rb +1 -1
- data/lib/cassandra/address_resolution/policies/ec2_multi_region.rb +1 -1
- data/lib/cassandra/address_resolution/policies/none.rb +1 -1
- data/lib/cassandra/aggregate.rb +21 -7
- data/lib/cassandra/argument.rb +2 -2
- data/lib/cassandra/auth.rb +4 -4
- data/lib/cassandra/auth/providers.rb +1 -1
- data/lib/cassandra/auth/providers/password.rb +9 -5
- data/lib/cassandra/cassandra_logger.rb +80 -0
- data/lib/cassandra/cluster.rb +38 -9
- data/lib/cassandra/cluster/client.rb +801 -205
- data/lib/cassandra/cluster/connection_pool.rb +2 -2
- data/lib/cassandra/cluster/connector.rb +74 -25
- data/lib/cassandra/cluster/control_connection.rb +217 -82
- data/lib/cassandra/cluster/failed_connection.rb +1 -1
- data/lib/cassandra/cluster/metadata.rb +12 -4
- data/lib/cassandra/cluster/options.rb +60 -11
- data/lib/cassandra/cluster/registry.rb +69 -16
- data/lib/cassandra/cluster/schema.rb +25 -7
- data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
- data/lib/cassandra/cluster/schema/fetchers.rb +263 -106
- data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +41 -36
- data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +3 -3
- data/lib/cassandra/cluster/schema/partitioners/ordered.rb +1 -1
- data/lib/cassandra/cluster/schema/partitioners/random.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies/network_topology.rb +19 -18
- data/lib/cassandra/cluster/schema/replication_strategies/none.rb +1 -1
- data/lib/cassandra/cluster/schema/replication_strategies/simple.rb +1 -1
- data/lib/cassandra/column.rb +3 -3
- data/lib/cassandra/compression.rb +1 -1
- data/lib/cassandra/compression/compressors/lz4.rb +4 -3
- data/lib/cassandra/compression/compressors/snappy.rb +4 -3
- data/lib/cassandra/driver.rb +103 -41
- data/lib/cassandra/errors.rb +265 -30
- data/lib/cassandra/execution/info.rb +16 -5
- data/lib/cassandra/execution/options.rb +99 -54
- data/lib/cassandra/execution/trace.rb +16 -9
- data/lib/cassandra/executors.rb +1 -1
- data/lib/cassandra/function.rb +19 -13
- data/lib/cassandra/function_collection.rb +85 -0
- data/lib/cassandra/future.rb +106 -48
- data/lib/cassandra/host.rb +10 -4
- data/lib/cassandra/keyspace.rb +90 -33
- data/lib/cassandra/listener.rb +1 -1
- data/lib/cassandra/load_balancing.rb +2 -2
- data/lib/cassandra/load_balancing/policies.rb +1 -1
- data/lib/cassandra/load_balancing/policies/dc_aware_round_robin.rb +18 -18
- data/lib/cassandra/load_balancing/policies/round_robin.rb +1 -1
- data/lib/cassandra/load_balancing/policies/token_aware.rb +15 -13
- data/lib/cassandra/load_balancing/policies/white_list.rb +11 -5
- data/lib/cassandra/null_logger.rb +27 -6
- data/lib/cassandra/protocol.rb +1 -1
- data/lib/cassandra/protocol/coder.rb +78 -39
- data/lib/cassandra/protocol/cql_byte_buffer.rb +50 -33
- data/lib/cassandra/protocol/cql_protocol_handler.rb +44 -45
- data/lib/cassandra/protocol/request.rb +2 -2
- data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
- data/lib/cassandra/protocol/requests/batch_request.rb +16 -7
- data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
- data/lib/cassandra/protocol/requests/execute_request.rb +41 -20
- data/lib/cassandra/protocol/requests/options_request.rb +1 -1
- data/lib/cassandra/protocol/requests/prepare_request.rb +5 -5
- data/lib/cassandra/protocol/requests/query_request.rb +27 -22
- data/lib/cassandra/protocol/requests/register_request.rb +2 -2
- data/lib/cassandra/protocol/requests/startup_request.rb +6 -4
- data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
- data/lib/cassandra/protocol/response.rb +2 -2
- data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
- data/lib/cassandra/protocol/responses/auth_challenge_response.rb +1 -1
- data/lib/cassandra/protocol/responses/auth_success_response.rb +1 -1
- data/lib/cassandra/protocol/responses/authenticate_response.rb +1 -1
- data/lib/cassandra/protocol/responses/error_response.rb +101 -13
- data/lib/cassandra/protocol/responses/event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
- data/lib/cassandra/protocol/responses/prepared_result_response.rb +11 -5
- data/lib/cassandra/protocol/responses/raw_rows_result_response.rb +14 -9
- data/lib/cassandra/protocol/responses/read_failure_error_response.rb +26 -4
- data/lib/cassandra/protocol/responses/read_timeout_error_response.rb +22 -3
- data/lib/cassandra/protocol/responses/ready_response.rb +3 -3
- data/lib/cassandra/protocol/responses/result_response.rb +4 -2
- data/lib/cassandra/protocol/responses/rows_result_response.rb +5 -3
- data/lib/cassandra/protocol/responses/schema_change_event_response.rb +5 -4
- data/lib/cassandra/protocol/responses/schema_change_result_response.rb +16 -9
- data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +2 -2
- data/lib/cassandra/protocol/responses/status_change_event_response.rb +2 -2
- data/lib/cassandra/protocol/responses/supported_response.rb +1 -1
- data/lib/cassandra/protocol/responses/topology_change_event_response.rb +1 -1
- data/lib/cassandra/protocol/responses/unavailable_error_response.rb +20 -3
- data/lib/cassandra/protocol/responses/unprepared_error_response.rb +11 -2
- data/lib/cassandra/protocol/responses/void_result_response.rb +1 -1
- data/lib/cassandra/protocol/responses/write_failure_error_response.rb +26 -4
- data/lib/cassandra/protocol/responses/write_timeout_error_response.rb +22 -3
- data/lib/cassandra/protocol/v1.rb +101 -36
- data/lib/cassandra/protocol/v3.rb +124 -51
- data/lib/cassandra/protocol/v4.rb +172 -68
- data/lib/cassandra/reconnection.rb +1 -1
- data/lib/cassandra/reconnection/policies.rb +1 -1
- data/lib/cassandra/reconnection/policies/constant.rb +2 -4
- data/lib/cassandra/reconnection/policies/exponential.rb +6 -6
- data/lib/cassandra/result.rb +53 -19
- data/lib/cassandra/retry.rb +8 -8
- data/lib/cassandra/retry/policies.rb +1 -1
- data/lib/cassandra/retry/policies/default.rb +1 -1
- data/lib/cassandra/retry/policies/downgrading_consistency.rb +7 -3
- data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
- data/lib/cassandra/session.rb +22 -16
- data/lib/cassandra/statement.rb +1 -1
- data/lib/cassandra/statements.rb +1 -1
- data/lib/cassandra/statements/batch.rb +16 -10
- data/lib/cassandra/statements/bound.rb +10 -3
- data/lib/cassandra/statements/prepared.rb +59 -15
- data/lib/cassandra/statements/simple.rb +23 -10
- data/lib/cassandra/statements/void.rb +1 -1
- data/lib/cassandra/table.rb +79 -30
- data/lib/cassandra/time.rb +11 -6
- data/lib/cassandra/time_uuid.rb +7 -7
- data/lib/cassandra/tuple.rb +16 -8
- data/lib/cassandra/types.rb +20 -9
- data/lib/cassandra/udt.rb +32 -36
- data/lib/cassandra/util.rb +20 -13
- data/lib/cassandra/uuid.rb +22 -15
- data/lib/cassandra/uuid/generator.rb +7 -5
- data/lib/cassandra/version.rb +2 -2
- data/lib/datastax/cassandra.rb +1 -1
- metadata +5 -3
data/lib/cassandra/retry.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -23,10 +23,10 @@ module Cassandra
|
|
23
23
|
# its methods. This class exists for documentation purposes only.
|
24
24
|
module Policy
|
25
25
|
# Decides wether to retry a read and at what consistency level.
|
26
|
-
#
|
26
|
+
#
|
27
27
|
# @note this method may be called even if required_responses >= received
|
28
28
|
# responses if data_present is false.
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# @param statement [Cassandra::Statement] the original statement that timed out
|
31
31
|
# @param consistency [Symbol] the original consistency level for the
|
32
32
|
# request, one of {Cassandra::CONSISTENCIES}
|
@@ -37,7 +37,7 @@ module Cassandra
|
|
37
37
|
# @param retrieved [Boolean] whether actual data (as opposed to data
|
38
38
|
# checksum) was present in the received responses.
|
39
39
|
# @param retries [Integer] the number of retries already performed
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# @return [Cassandra::Policies::Retry::Decision] a retry decision
|
42
42
|
#
|
43
43
|
# @see Cassandra::Retry::Policy#try_again
|
@@ -47,7 +47,7 @@ module Cassandra
|
|
47
47
|
end
|
48
48
|
|
49
49
|
# Decides wether to retry a write and at what consistency level.
|
50
|
-
#
|
50
|
+
#
|
51
51
|
# @param statement [Cassandra::Statement] the original statement that timed out
|
52
52
|
# @param consistency [Symbol] the original consistency level for the
|
53
53
|
# request, one of {Cassandra::CONSISTENCIES}
|
@@ -57,7 +57,7 @@ module Cassandra
|
|
57
57
|
# @param received [Integer] the number of acks received by the time the
|
58
58
|
# query timed out
|
59
59
|
# @param retries [Integer] the number of retries already performed
|
60
|
-
#
|
60
|
+
#
|
61
61
|
# @return [Cassandra::Policies::Retry::Decision] a retry decision
|
62
62
|
#
|
63
63
|
# @see Cassandra::Retry::Policy#try_again
|
@@ -68,7 +68,7 @@ module Cassandra
|
|
68
68
|
|
69
69
|
# Decides wether to retry and at what consistency level on an Unavailable
|
70
70
|
# exception.
|
71
|
-
#
|
71
|
+
#
|
72
72
|
# @param statement [Cassandra::Statement] the original Statement that timed out
|
73
73
|
# @param consistency [Symbol] the original consistency level for the
|
74
74
|
# request, one of {Cassandra::CONSISTENCIES}
|
@@ -76,7 +76,7 @@ module Cassandra
|
|
76
76
|
# requested consistency level
|
77
77
|
# @param alive [Integer] the number of replicas available for the request
|
78
78
|
# @param retries [Integer] the number of retries already performed
|
79
|
-
#
|
79
|
+
#
|
80
80
|
# @return [Cassandra::Policies::Retry::Decision] a retry decision
|
81
81
|
#
|
82
82
|
# @see Cassandra::Retry::Policy#try_again
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -24,7 +24,9 @@ module Cassandra
|
|
24
24
|
|
25
25
|
def read_timeout(statement, consistency, required, received, retrieved, retries)
|
26
26
|
return reraise if retries > 0 || SERIAL_CONSISTENCIES.include?(consistency)
|
27
|
-
|
27
|
+
if received < required
|
28
|
+
return max_likely_to_work(consistency, required, received)
|
29
|
+
end
|
28
30
|
|
29
31
|
retrieved ? reraise : try_again(consistency)
|
30
32
|
end
|
@@ -53,7 +55,9 @@ module Cassandra
|
|
53
55
|
private
|
54
56
|
|
55
57
|
def max_likely_to_work(consistency, required, received)
|
56
|
-
if consistency == :all &&
|
58
|
+
if consistency == :all &&
|
59
|
+
required > 1 &&
|
60
|
+
received >= (required.to_f / 2).floor + 1
|
57
61
|
try_again(:quorum)
|
58
62
|
elsif received >= 3
|
59
63
|
try_again(:three)
|
data/lib/cassandra/session.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -17,7 +17,9 @@
|
|
17
17
|
#++
|
18
18
|
|
19
19
|
module Cassandra
|
20
|
-
# Sessions are used for query execution. Each session tracks its current keyspace.
|
20
|
+
# Sessions are used for query execution. Each session tracks its current keyspace.
|
21
|
+
# A session should be reused as much as possible, however it is ok to create several
|
22
|
+
# independent session for interacting with different keyspaces in the same application.
|
21
23
|
class Session
|
22
24
|
extend Forwardable
|
23
25
|
|
@@ -79,15 +81,19 @@ module Cassandra
|
|
79
81
|
# @see Cassandra::Session#execute A list of errors this future can be
|
80
82
|
# resolved with
|
81
83
|
def execute_async(statement, options = nil)
|
82
|
-
if options
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
options = if options
|
85
|
+
@options.override(options)
|
86
|
+
else
|
87
|
+
@options
|
88
|
+
end
|
87
89
|
|
88
90
|
case statement
|
89
91
|
when ::String
|
90
|
-
@client.query(Statements::Simple.new(statement,
|
92
|
+
@client.query(Statements::Simple.new(statement,
|
93
|
+
options.arguments,
|
94
|
+
options.type_hints,
|
95
|
+
options.idempotent?),
|
96
|
+
options)
|
91
97
|
when Statements::Simple
|
92
98
|
@client.query(statement, options)
|
93
99
|
when Statements::Prepared
|
@@ -95,7 +101,7 @@ module Cassandra
|
|
95
101
|
when Statements::Bound
|
96
102
|
@client.execute(statement, options)
|
97
103
|
when Statements::Batch
|
98
|
-
Util.assert_not_empty(statement.statements) {
|
104
|
+
Util.assert_not_empty(statement.statements) { 'batch cannot be empty' }
|
99
105
|
@client.batch(statement, options)
|
100
106
|
else
|
101
107
|
@futures.error(::ArgumentError.new("unsupported statement #{statement.inspect}"))
|
@@ -143,11 +149,11 @@ module Cassandra
|
|
143
149
|
# @return [Cassandra::Future<Cassandra::Statements::Prepared>] future
|
144
150
|
# prepared statement
|
145
151
|
def prepare_async(statement, options = nil)
|
146
|
-
if options.is_a?(::Hash)
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
152
|
+
options = if options.is_a?(::Hash)
|
153
|
+
@options.override(options)
|
154
|
+
else
|
155
|
+
@options
|
156
|
+
end
|
151
157
|
|
152
158
|
case statement
|
153
159
|
when ::String
|
@@ -181,7 +187,7 @@ module Cassandra
|
|
181
187
|
yield(statement) if block_given?
|
182
188
|
statement
|
183
189
|
end
|
184
|
-
alias
|
190
|
+
alias batch logged_batch
|
185
191
|
|
186
192
|
# Returns a unlogged {Statements::Batch} instance and optionally yields it
|
187
193
|
# to a given block
|
@@ -232,7 +238,7 @@ module Cassandra
|
|
232
238
|
|
233
239
|
# @private
|
234
240
|
def inspect
|
235
|
-
"#<#{self.class.name}:0x#{
|
241
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)}>"
|
236
242
|
end
|
237
243
|
end
|
238
244
|
end
|
data/lib/cassandra/statement.rb
CHANGED
data/lib/cassandra/statements.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -88,21 +88,26 @@ module Cassandra
|
|
88
88
|
#
|
89
89
|
# @return [self]
|
90
90
|
def add(statement, options = nil)
|
91
|
-
if options.is_a?(::Hash)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
options = if options.is_a?(::Hash)
|
92
|
+
@options.override(options)
|
93
|
+
else
|
94
|
+
@options
|
95
|
+
end
|
96
96
|
|
97
97
|
case statement
|
98
98
|
when String
|
99
|
-
@statements << Simple.new(statement,
|
99
|
+
@statements << Simple.new(statement,
|
100
|
+
options.arguments,
|
101
|
+
options.type_hints,
|
102
|
+
options.idempotent?)
|
100
103
|
when Prepared
|
101
104
|
@statements << statement.bind(options.arguments)
|
102
105
|
when Bound, Simple
|
103
106
|
@statements << statement
|
104
107
|
else
|
105
|
-
raise ::ArgumentError,
|
108
|
+
raise ::ArgumentError,
|
109
|
+
'a batch can only consist of simple or prepared statements, ' \
|
110
|
+
"#{statement.inspect} given"
|
106
111
|
end
|
107
112
|
|
108
113
|
self
|
@@ -115,7 +120,8 @@ module Cassandra
|
|
115
120
|
@statements.all?(&:idempotent?)
|
116
121
|
end
|
117
122
|
|
118
|
-
# A batch statement doesn't really have any cql of its own as it is composed of
|
123
|
+
# A batch statement doesn't really have any cql of its own as it is composed of
|
124
|
+
# multiple different statements
|
119
125
|
# @return [nil] nothing
|
120
126
|
def cql
|
121
127
|
nil
|
@@ -127,7 +133,7 @@ module Cassandra
|
|
127
133
|
|
128
134
|
# @return [String] a CLI-friendly batch statement representation
|
129
135
|
def inspect
|
130
|
-
"#<#{self.class.name}:0x#{
|
136
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @type=#{type.inspect}>"
|
131
137
|
end
|
132
138
|
end
|
133
139
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -30,7 +30,13 @@ module Cassandra
|
|
30
30
|
attr_reader :params_types, :result_metadata, :keyspace, :partition_key
|
31
31
|
|
32
32
|
# @private
|
33
|
-
def initialize(cql,
|
33
|
+
def initialize(cql,
|
34
|
+
params_types,
|
35
|
+
result_metadata,
|
36
|
+
params,
|
37
|
+
keyspace = nil,
|
38
|
+
partition_key = nil,
|
39
|
+
idempotent = false)
|
34
40
|
@cql = cql
|
35
41
|
@params_types = params_types
|
36
42
|
@result_metadata = result_metadata
|
@@ -42,7 +48,8 @@ module Cassandra
|
|
42
48
|
|
43
49
|
# @return [String] a CLI-friendly bound statement representation
|
44
50
|
def inspect
|
45
|
-
"#<#{self.class.name}:0x#{
|
51
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect} " \
|
52
|
+
"@params=#{@params}>"
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
#--
|
4
|
-
# Copyright 2013-
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -29,7 +29,21 @@ module Cassandra
|
|
29
29
|
attr_reader :result_metadata
|
30
30
|
|
31
31
|
# @private
|
32
|
-
def initialize(payload,
|
32
|
+
def initialize(payload,
|
33
|
+
warnings,
|
34
|
+
cql,
|
35
|
+
params_metadata,
|
36
|
+
result_metadata,
|
37
|
+
partition_key,
|
38
|
+
trace_id,
|
39
|
+
keyspace,
|
40
|
+
statement,
|
41
|
+
options,
|
42
|
+
hosts,
|
43
|
+
consistency,
|
44
|
+
retries,
|
45
|
+
client,
|
46
|
+
connection_options)
|
33
47
|
@payload = payload
|
34
48
|
@warnings = warnings
|
35
49
|
@cql = cql
|
@@ -59,7 +73,9 @@ module Cassandra
|
|
59
73
|
# @return [Cassandra::Statements::Bound] bound statement
|
60
74
|
def bind(args = nil)
|
61
75
|
if args
|
62
|
-
Util.assert_instance_of_one_of([::Array, ::Hash], args)
|
76
|
+
Util.assert_instance_of_one_of([::Array, ::Hash], args) do
|
77
|
+
"args must be an Array or a Hash, #{args.inspect} given"
|
78
|
+
end
|
63
79
|
else
|
64
80
|
args = EMPTY_LIST
|
65
81
|
end
|
@@ -69,29 +85,38 @@ module Cassandra
|
|
69
85
|
|
70
86
|
if args.is_a?(::Hash)
|
71
87
|
@params_metadata.each do |(_, _, name, type)|
|
72
|
-
name = name.to_sym unless args.
|
88
|
+
name = name.to_sym unless args.key?(name)
|
73
89
|
value = args.fetch(name, NOT_SET)
|
74
90
|
|
75
91
|
if NOT_SET.eql?(value)
|
76
92
|
if @connection_options.protocol_version < 4
|
77
|
-
raise ::ArgumentError,
|
93
|
+
raise ::ArgumentError,
|
94
|
+
"argument #{name.inspect} it not present in #{args.inspect}"
|
78
95
|
end
|
79
96
|
else
|
80
|
-
Util.assert_type(type, value)
|
97
|
+
Util.assert_type(type, value) do
|
98
|
+
"argument for #{name.inspect} must be #{type}, #{value} given"
|
99
|
+
end
|
81
100
|
end
|
82
101
|
|
83
102
|
params << value
|
84
103
|
param_types << type
|
85
104
|
end
|
86
105
|
else
|
87
|
-
Util.assert_equal(@params_metadata.size, args.size)
|
106
|
+
Util.assert_equal(@params_metadata.size, args.size) do
|
107
|
+
"expecting exactly #{@params_metadata.size} bind parameters, " \
|
108
|
+
"#{args.size} given"
|
109
|
+
end
|
88
110
|
@params_metadata.zip(args) do |(_, _, name, type), value|
|
89
111
|
if NOT_SET.eql?(value)
|
90
112
|
if @connection_options.protocol_version < 4
|
91
|
-
raise ::ArgumentError,
|
113
|
+
raise ::ArgumentError,
|
114
|
+
"argument #{name.inspect} it not present in #{args.inspect}"
|
92
115
|
end
|
93
116
|
else
|
94
|
-
Util.assert_type(type, value)
|
117
|
+
Util.assert_type(type, value) do
|
118
|
+
"argument for #{name.inspect} must be #{type}, #{value} given"
|
119
|
+
end
|
95
120
|
end
|
96
121
|
|
97
122
|
params << value
|
@@ -99,21 +124,40 @@ module Cassandra
|
|
99
124
|
end
|
100
125
|
end
|
101
126
|
|
102
|
-
|
127
|
+
# params_metadata is an array of column-specs; each column-spec is an array
|
128
|
+
# of keyspace, tablename, other stuff. We only care about the keyspace name.
|
129
|
+
# See read_prepared_metadata_v4 in coder.rb for more details.
|
130
|
+
keyspace_name = @params_metadata.first.first unless @params_metadata.empty?
|
103
131
|
|
104
132
|
partition_key = create_partition_key(params)
|
105
133
|
|
106
|
-
Bound.new(@cql,
|
134
|
+
Bound.new(@cql,
|
135
|
+
param_types,
|
136
|
+
@result_metadata,
|
137
|
+
params,
|
138
|
+
keyspace_name,
|
139
|
+
partition_key,
|
140
|
+
@idempotent)
|
107
141
|
end
|
108
142
|
|
109
143
|
# @return [Cassandra::Execution::Info] execution info for PREPARE request
|
110
144
|
def execution_info
|
111
|
-
@info ||= Execution::Info.new(@payload,
|
145
|
+
@info ||= Execution::Info.new(@payload,
|
146
|
+
@warnings,
|
147
|
+
@keyspace,
|
148
|
+
@statement,
|
149
|
+
@options,
|
150
|
+
@hosts,
|
151
|
+
@consistency,
|
152
|
+
@retries,
|
153
|
+
@trace_id ?
|
154
|
+
Execution::Trace.new(@trace_id, @client) :
|
155
|
+
nil)
|
112
156
|
end
|
113
157
|
|
114
158
|
# @return [String] a CLI-friendly prepared statement representation
|
115
159
|
def inspect
|
116
|
-
"#<#{self.class.name}:0x#{
|
160
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @cql=#{@cql.inspect}>"
|
117
161
|
end
|
118
162
|
|
119
163
|
private
|
@@ -133,7 +177,7 @@ module Cassandra
|
|
133
177
|
|
134
178
|
if NOT_SET.eql?(value)
|
135
179
|
raise ::ArgumentError, "argument #{name.inspect} is a part of " \
|
136
|
-
|
180
|
+
'the partition key and must be present.'
|
137
181
|
end
|
138
182
|
|
139
183
|
if @connection_options.protocol_version >= 3
|
@@ -153,7 +197,7 @@ module Cassandra
|
|
153
197
|
|
154
198
|
if NOT_SET.eql?(value)
|
155
199
|
raise ::ArgumentError, "argument #{name.inspect} is a part of " \
|
156
|
-
|
200
|
+
'the partition key and must be present.'
|
157
201
|
end
|
158
202
|
|
159
203
|
if @connection_options.protocol_version >= 3
|