cassandra-driver 2.1.4-java → 2.1.5-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 +4 -4
- data/.yardopts +10 -1
- data/lib/cassandra.rb +3 -3
- data/lib/cassandra/auth.rb +1 -1
- data/lib/cassandra/cluster/client.rb +1 -1
- data/lib/cassandra/cluster/control_connection.rb +2 -5
- data/lib/cassandra/cluster/schema.rb +2 -2
- data/lib/cassandra/driver.rb +2 -3
- data/lib/cassandra/errors.rb +15 -15
- data/lib/cassandra/execution/options.rb +14 -2
- data/lib/cassandra/protocol/coder.rb +1 -1
- data/lib/cassandra/protocol/cql_byte_buffer.rb +1 -3
- data/lib/cassandra/protocol/cql_protocol_handler.rb +3 -1
- data/lib/cassandra/result.rb +1 -1
- data/lib/cassandra/session.rb +4 -1
- data/lib/cassandra/statements/batch.rb +5 -2
- data/lib/cassandra/statements/simple.rb +18 -3
- data/lib/cassandra/version.rb +1 -1
- data/lib/cassandra_murmur3.jar +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b54cece0a4702c4e54ce84d876a1efc6dc2b913b
|
4
|
+
data.tar.gz: 045113e69793b513866c82251ee22ad1e47cfdd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4406fd2b63d3468dab784cdce99d5cef2cf71e7dd5600fc8728137621d61d6dc8faefcf6d6f402f6214598ea3259e544cf6f05ec2486f7ffff58b5a3df0b2492
|
7
|
+
data.tar.gz: 8787bb59dad47ffcdc85f4c8022e128c60fd301f9a52967a285359c0a90a62a0e68206d5913719eb318409cb970f7666ee7ff0245974bee35993ae3eb111aa36
|
data/.yardopts
CHANGED
@@ -1,4 +1,13 @@
|
|
1
1
|
--no-private
|
2
2
|
--markup markdown
|
3
|
+
--type-tag expected_errors:"Expected Errors"
|
4
|
+
--tag jira_ticket:"JIRA Ticket"
|
5
|
+
--type-tag expected_result:"Expected Result"
|
6
|
+
--tag test_assumptions:"Test Assumptions"
|
7
|
+
--tag test_category:"Test Category"
|
8
|
+
|
3
9
|
lib/**/*.rb
|
4
|
-
|
10
|
+
integration/**/*.rb
|
11
|
+
-- README
|
12
|
+
|
13
|
+
load_plugins: true
|
data/lib/cassandra.rb
CHANGED
@@ -47,7 +47,7 @@ module Cassandra
|
|
47
47
|
# A list of all possible write types that a
|
48
48
|
# {Cassandra::Errors::WriteTimeoutError} can have.
|
49
49
|
#
|
50
|
-
# @see https://github.com/apache/cassandra/blob/
|
50
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L872-L887 Description of possible types of writes in Apache Cassandra native protocol spec v1
|
51
51
|
WRITE_TYPES = [:simple, :batch, :unlogged_batch, :counter, :batch_log].freeze
|
52
52
|
|
53
53
|
# Creates a {Cassandra::Cluster Cluster instance}.
|
@@ -176,9 +176,9 @@ module Cassandra
|
|
176
176
|
# @option options [Integer] :page_size (10000) default page size for all
|
177
177
|
# select queries. Set this value to `nil` to disable paging.
|
178
178
|
#
|
179
|
-
# @option options [Hash{String => String}] :credentials (none) a hash of credentials - to be used with [credentials authentication in cassandra 1.2](https://github.com/apache/cassandra/blob/
|
179
|
+
# @option options [Hash{String => String}] :credentials (none) a hash of credentials - to be used with [credentials authentication in cassandra 1.2](https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L238-L250). Note that if you specified `:username` and `:password` options, those credentials are configured automatically.
|
180
180
|
#
|
181
|
-
# @option options [Cassandra::Auth::Provider] :auth_provider (none) a custom auth provider to be used with [SASL authentication in cassandra 2.0](https://github.com/apache/cassandra/blob/
|
181
|
+
# @option options [Cassandra::Auth::Provider] :auth_provider (none) a custom auth provider to be used with [SASL authentication in cassandra 2.0](https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L257-L273). Note that if you have specified `:username` and `:password`, then a {Cassandra::Auth::Providers::Password Password Provider} will be used automatically.
|
182
182
|
#
|
183
183
|
# @option options [Cassandra::Compression::Compressor] :compressor (none) a
|
184
184
|
# custom compressor. Note that if you have specified `:compression`, an
|
data/lib/cassandra/auth.rb
CHANGED
@@ -59,7 +59,7 @@ module Cassandra
|
|
59
59
|
# subclasses of this class, but need to implement the same methods. This
|
60
60
|
# class exists only for documentation purposes.
|
61
61
|
#
|
62
|
-
# @see https://github.com/apache/cassandra/blob/
|
62
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L257-L273 Cassandra native protocol v2 SASL authentication
|
63
63
|
# @see Cassandra::Auth::Provider#create_authenticator
|
64
64
|
class Authenticator
|
65
65
|
# @!method initial_response
|
@@ -97,7 +97,7 @@ module Cassandra
|
|
97
97
|
|
98
98
|
if failed_connections.size == connections.size
|
99
99
|
errors = {}
|
100
|
-
connections.each {|c| errors[c.host] = c.error}
|
100
|
+
connections.each {|c| errors[c.host] = c.error unless c.error.nil?}
|
101
101
|
raise Errors::NoHostsAvailable.new(errors)
|
102
102
|
else
|
103
103
|
failed_connections.each do |f|
|
@@ -60,9 +60,6 @@ module Cassandra
|
|
60
60
|
plan = @load_balancing_policy.plan(nil, VOID_STATEMENT, VOID_OPTIONS)
|
61
61
|
connect_to_first_available(plan)
|
62
62
|
end
|
63
|
-
f.on_failure do |e|
|
64
|
-
close_async
|
65
|
-
end
|
66
63
|
f
|
67
64
|
end
|
68
65
|
|
@@ -394,7 +391,7 @@ module Cassandra
|
|
394
391
|
if tables.empty?
|
395
392
|
@schema.delete_table(keyspace, table)
|
396
393
|
else
|
397
|
-
@schema.
|
394
|
+
@schema.update_table(host, keyspace, tables.first, columns)
|
398
395
|
end
|
399
396
|
end
|
400
397
|
end
|
@@ -447,7 +444,7 @@ module Cassandra
|
|
447
444
|
if types.empty?
|
448
445
|
@schema.delete_type(keyspace, type)
|
449
446
|
else
|
450
|
-
@schema.
|
447
|
+
@schema.update_type(host, keyspace, types.first)
|
451
448
|
end
|
452
449
|
end
|
453
450
|
end
|
@@ -134,7 +134,7 @@ module Cassandra
|
|
134
134
|
self
|
135
135
|
end
|
136
136
|
|
137
|
-
def
|
137
|
+
def update_table(host, keyspace_name, table, columns)
|
138
138
|
keyspace = @keyspaces[keyspace_name]
|
139
139
|
|
140
140
|
return self unless keyspace
|
@@ -174,7 +174,7 @@ module Cassandra
|
|
174
174
|
self
|
175
175
|
end
|
176
176
|
|
177
|
-
def
|
177
|
+
def update_type(host, keyspace_name, type)
|
178
178
|
keyspace = @keyspaces[keyspace_name]
|
179
179
|
|
180
180
|
return self unless keyspace
|
data/lib/cassandra/driver.rb
CHANGED
data/lib/cassandra/errors.rb
CHANGED
@@ -43,7 +43,7 @@ module Cassandra
|
|
43
43
|
# Raised when something unexpected happened. This indicates a server-side
|
44
44
|
# bug.
|
45
45
|
#
|
46
|
-
# @see https://github.com/apache/cassandra/blob/
|
46
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L654-L655 Description of Server Error in Apache Cassandra native protocol spec v1
|
47
47
|
class ServerError < ::StandardError
|
48
48
|
include Error, HostError
|
49
49
|
end
|
@@ -95,7 +95,7 @@ module Cassandra
|
|
95
95
|
# @note This error can be handled by a {Cassandra::Retry::Policy} to
|
96
96
|
# determine the desired outcome.
|
97
97
|
#
|
98
|
-
# @see https://github.com/apache/cassandra/blob/
|
98
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L662-L672 Description of Unavailable Error in Apache Cassandra native protocol spec v1
|
99
99
|
class UnavailableError < ::StandardError
|
100
100
|
include ExecutionError
|
101
101
|
# Consistency level that triggered the error.
|
@@ -124,7 +124,7 @@ module Cassandra
|
|
124
124
|
# Raised when the request cannot be processed because the coordinator node
|
125
125
|
# is overloaded
|
126
126
|
#
|
127
|
-
# @see https://github.com/apache/cassandra/blob/
|
127
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L673-L674 Description of Overloaded Error in Apache Cassandra native protocol spec v1
|
128
128
|
class OverloadedError < ::StandardError
|
129
129
|
include ExecutionError, HostError
|
130
130
|
end
|
@@ -132,21 +132,21 @@ module Cassandra
|
|
132
132
|
# Raise when the request was a read request but the coordinator node is
|
133
133
|
# bootstrapping
|
134
134
|
#
|
135
|
-
# @see https://github.com/apache/cassandra/blob/
|
135
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L675-L676 Description of Is Bootstrapping Error in Apache Cassandra native protocol spec v1
|
136
136
|
class IsBootstrappingError < ::StandardError
|
137
137
|
include ExecutionError, HostError
|
138
138
|
end
|
139
139
|
|
140
140
|
# Raised when truncation failed.
|
141
141
|
#
|
142
|
-
# @see https://github.com/apache/cassandra/blob/
|
142
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L677 Description of Truncate Error in Apache Cassandra native protocol spec v1
|
143
143
|
class TruncateError < ::StandardError
|
144
144
|
include ExecutionError
|
145
145
|
end
|
146
146
|
|
147
147
|
# Raised when a write request timed out.
|
148
148
|
#
|
149
|
-
# @see https://github.com/apache/cassandra/blob/
|
149
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L678-L703 Description of Write Timeout Error in Apache Cassandra native protocol spec v1
|
150
150
|
class WriteTimeoutError < ::StandardError
|
151
151
|
include ExecutionError
|
152
152
|
|
@@ -176,7 +176,7 @@ module Cassandra
|
|
176
176
|
|
177
177
|
# Raised when a read request timed out.
|
178
178
|
#
|
179
|
-
# @see https://github.com/apache/cassandra/blob/
|
179
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L704-L721 Description of Read Timeout Error in Apache Cassandra native protocol spec v1
|
180
180
|
class ReadTimeoutError < ::StandardError
|
181
181
|
include ExecutionError
|
182
182
|
|
@@ -216,13 +216,13 @@ module Cassandra
|
|
216
216
|
# Raised when some client message triggered a protocol violation (for
|
217
217
|
# instance a QUERY message is sent before a STARTUP one has been sent)
|
218
218
|
#
|
219
|
-
# @see https://github.com/apache/cassandra/blob/
|
219
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L656-L658 Description of Protocol Error in Apache Cassandra native protocol spec v1
|
220
220
|
class ProtocolError < ClientError
|
221
221
|
end
|
222
222
|
|
223
223
|
# Raised when cannot authenticate to Cassandra
|
224
224
|
#
|
225
|
-
# @see https://github.com/apache/cassandra/blob/
|
225
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L659-L660 Description of Bad Credentials Error in Apache Cassandra native protocol spec v1
|
226
226
|
class AuthenticationError < ClientError
|
227
227
|
end
|
228
228
|
|
@@ -247,7 +247,7 @@ module Cassandra
|
|
247
247
|
# @note Seeing this error can be considered a Ruby Driver bug as it should
|
248
248
|
# handle automatic re-preparing internally.
|
249
249
|
#
|
250
|
-
# @see https://github.com/apache/cassandra/blob/
|
250
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L738-L741 Description of Unprepared Error in Apache Cassandra native protocol spec v1
|
251
251
|
class UnpreparedError < ::StandardError
|
252
252
|
include ValidationError
|
253
253
|
# @return [String] prepared statement id that triggered the error
|
@@ -263,14 +263,14 @@ module Cassandra
|
|
263
263
|
|
264
264
|
# Raised when the submitted query has a syntax error.
|
265
265
|
#
|
266
|
-
# @see https://github.com/apache/cassandra/blob/
|
266
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L723 Description of Syntax Error in Apache Cassandra native protocol spec v1
|
267
267
|
class SyntaxError < ::StandardError
|
268
268
|
include ValidationError
|
269
269
|
end
|
270
270
|
|
271
271
|
# Raised when the logged user doesn't have the right to perform the query.
|
272
272
|
#
|
273
|
-
# @see https://github.com/apache/cassandra/blob/
|
273
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L724-L725 Description of Unauthorized Error in Apache Cassandra native protocol spec v1
|
274
274
|
class UnauthorizedError < ::StandardError
|
275
275
|
include ValidationError
|
276
276
|
end
|
@@ -283,7 +283,7 @@ module Cassandra
|
|
283
283
|
# rescue Cassandra::Errors::InvalidError
|
284
284
|
# end
|
285
285
|
#
|
286
|
-
# @see https://github.com/apache/cassandra/blob/
|
286
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L726 Description of Invalid Error in Apache Cassandra native protocol spec v1
|
287
287
|
class InvalidError < ::StandardError
|
288
288
|
include ValidationError
|
289
289
|
end
|
@@ -296,7 +296,7 @@ module Cassandra
|
|
296
296
|
# rescue Cassandra::Errors::ConfigurationError
|
297
297
|
# end
|
298
298
|
#
|
299
|
-
# @see https://github.com/apache/cassandra/blob/
|
299
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L727 Description of Config Error in Apache Cassandra native protocol spec v1
|
300
300
|
class ConfigurationError < ::StandardError
|
301
301
|
include ValidationError
|
302
302
|
end
|
@@ -313,7 +313,7 @@ module Cassandra
|
|
313
313
|
# p ['already exists', e.keyspace, e.table]
|
314
314
|
# end
|
315
315
|
#
|
316
|
-
# @see https://github.com/apache/cassandra/blob/
|
316
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v1.spec#L728-L737 Description of Already Exists Error in Apache Cassandra native protocol spec v1
|
317
317
|
class AlreadyExistsError < ConfigurationError
|
318
318
|
# @return [String] keyspace
|
319
319
|
attr_reader :keyspace
|
@@ -32,6 +32,8 @@ module Cassandra
|
|
32
32
|
attr_reader :timeout
|
33
33
|
# @return [Array] positional arguments for the statement
|
34
34
|
attr_reader :arguments
|
35
|
+
# @return [Array] type hints for positional arguments for the statement
|
36
|
+
attr_reader :type_hints
|
35
37
|
|
36
38
|
# @return [String] paging state
|
37
39
|
#
|
@@ -56,6 +58,7 @@ module Cassandra
|
|
56
58
|
serial_consistency = options[:serial_consistency]
|
57
59
|
paging_state = options[:paging_state]
|
58
60
|
arguments = options[:arguments]
|
61
|
+
type_hints = options[:type_hints]
|
59
62
|
|
60
63
|
Util.assert_one_of(CONSISTENCIES, consistency) { ":consistency must be one of #{CONSISTENCIES.inspect}, #{consistency.inspect} given" }
|
61
64
|
|
@@ -85,6 +88,12 @@ module Cassandra
|
|
85
88
|
Util.assert_instance_of_one_of([::Array, ::Hash], arguments) { ":arguments must be an Array or a Hash, #{arguments.inspect} given" }
|
86
89
|
end
|
87
90
|
|
91
|
+
if type_hints.nil?
|
92
|
+
type_hints = EMPTY_LIST
|
93
|
+
else
|
94
|
+
Util.assert_instance_of_one_of([::Array, ::Hash], type_hints) { ":type_hints must be an Array or a Hash, #{type_hints.inspect} given" }
|
95
|
+
end
|
96
|
+
|
88
97
|
@consistency = consistency
|
89
98
|
@page_size = page_size
|
90
99
|
@trace = !!trace
|
@@ -92,6 +101,7 @@ module Cassandra
|
|
92
101
|
@serial_consistency = serial_consistency
|
93
102
|
@paging_state = paging_state
|
94
103
|
@arguments = arguments
|
104
|
+
@type_hints = type_hints
|
95
105
|
end
|
96
106
|
|
97
107
|
# @return [Boolean] whether request tracing was enabled
|
@@ -107,7 +117,8 @@ module Cassandra
|
|
107
117
|
other.timeout == @timeout &&
|
108
118
|
other.serial_consistency == @serial_consistency &&
|
109
119
|
other.paging_state == @paging_state &&
|
110
|
-
other.arguments == @arguments
|
120
|
+
other.arguments == @arguments &&
|
121
|
+
other.type_hints == @type_hints
|
111
122
|
end
|
112
123
|
alias :== :eql?
|
113
124
|
|
@@ -130,7 +141,8 @@ module Cassandra
|
|
130
141
|
:trace => @trace,
|
131
142
|
:timeout => @timeout,
|
132
143
|
:serial_consistency => @serial_consistency,
|
133
|
-
:arguments => @arguments || EMPTY_LIST
|
144
|
+
:arguments => @arguments || EMPTY_LIST,
|
145
|
+
:type_hints => @type_hints || EMPTY_LIST
|
134
146
|
}
|
135
147
|
end
|
136
148
|
end
|
@@ -433,7 +433,7 @@ module Cassandra
|
|
433
433
|
when 0x0020 then Types.list(read_type_v1(buffer))
|
434
434
|
when 0x0021 then Types.map(read_type_v1(buffer), read_type_v1(buffer))
|
435
435
|
when 0x0022 then Types.set(read_type_v1(buffer))
|
436
|
-
else
|
436
|
+
else
|
437
437
|
raise Errors::DecodingError, %(Unsupported column type: #{kind})
|
438
438
|
end
|
439
439
|
end
|
@@ -139,9 +139,7 @@ module Cassandra
|
|
139
139
|
end
|
140
140
|
|
141
141
|
def read_short_bytes
|
142
|
-
|
143
|
-
return nil if size & 0x8000 == 0x8000
|
144
|
-
read(size)
|
142
|
+
read(read_unsigned_short)
|
145
143
|
rescue RangeError => e
|
146
144
|
raise Errors::DecodingError, "Not enough bytes available to decode a short bytes: #{e.message}", e.backtrace
|
147
145
|
end
|
@@ -32,7 +32,7 @@ module Cassandra
|
|
32
32
|
# puts "These options are supported: #{response.options}"
|
33
33
|
class CqlProtocolHandler
|
34
34
|
# @return [String] the current keyspace for the underlying connection
|
35
|
-
attr_reader :keyspace
|
35
|
+
attr_reader :keyspace, :error
|
36
36
|
|
37
37
|
def initialize(connection, scheduler, protocol_version, compressor=nil, heartbeat_interval = 30, idle_timeout = 60)
|
38
38
|
@connection = connection
|
@@ -68,6 +68,7 @@ module Cassandra
|
|
68
68
|
@terminate = nil
|
69
69
|
@heartbeat_interval = heartbeat_interval
|
70
70
|
@idle_timeout = idle_timeout
|
71
|
+
@error = nil
|
71
72
|
end
|
72
73
|
|
73
74
|
# Returns the hostname of the underlying connection
|
@@ -314,6 +315,7 @@ module Cassandra
|
|
314
315
|
|
315
316
|
cause = e
|
316
317
|
end
|
318
|
+
@error = cause
|
317
319
|
|
318
320
|
request_failure_cause = cause || Errors::IOError.new('Connection closed')
|
319
321
|
promises_to_fail = nil
|
data/lib/cassandra/result.rb
CHANGED
@@ -86,7 +86,7 @@ module Cassandra
|
|
86
86
|
# undefined and will likely cause a server process of the coordinator of
|
87
87
|
# such request to abort.
|
88
88
|
#
|
89
|
-
# @see https://github.com/apache/cassandra/blob/
|
89
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-2.0.16/doc/native_protocol_v2.spec#L482-L487 Paging State description in Cassandra Native Protocol v2 specification
|
90
90
|
def paging_state
|
91
91
|
end
|
92
92
|
end
|
data/lib/cassandra/session.rb
CHANGED
@@ -57,6 +57,9 @@ module Cassandra
|
|
57
57
|
# initial request.
|
58
58
|
# @option options [Array, Hash] :arguments (nil) positional or named
|
59
59
|
# arguments for the statement.
|
60
|
+
# @option options [Array, Hash] :type_hints (nil) override Util.guess_type to
|
61
|
+
# determine the CQL type for an argument; nil elements will fall-back
|
62
|
+
# to Util.guess_type.
|
60
63
|
#
|
61
64
|
# @see Cassandra.cluster Options that can be specified on the cluster-level
|
62
65
|
# and their default values.
|
@@ -80,7 +83,7 @@ module Cassandra
|
|
80
83
|
|
81
84
|
case statement
|
82
85
|
when ::String
|
83
|
-
@client.query(Statements::Simple.new(statement, options.arguments), options)
|
86
|
+
@client.query(Statements::Simple.new(statement, options.arguments, options.type_hints), options)
|
84
87
|
when Statements::Simple
|
85
88
|
@client.query(statement, options)
|
86
89
|
when Statements::Prepared
|
@@ -63,6 +63,8 @@ module Cassandra
|
|
63
63
|
# @param args [Array, Hash] (nil) positional or named arguments to bind,
|
64
64
|
# must contain the same number of parameters as the number of positional
|
65
65
|
# (`?`) or named (`:name`) markers in the CQL passed.
|
66
|
+
# @param type_hints [Array, Hash] (nil) specified CQL types for positional
|
67
|
+
# or named arguments to override type guessing.
|
66
68
|
#
|
67
69
|
# @note Positional arguments for simple statements are only supported
|
68
70
|
# starting with Apache Cassandra 2.0 and above.
|
@@ -71,12 +73,13 @@ module Cassandra
|
|
71
73
|
# starting with Apache Cassandra 2.1 and above.
|
72
74
|
#
|
73
75
|
# @return [self]
|
74
|
-
def add(statement, args = nil)
|
76
|
+
def add(statement, args = nil, type_hints = nil)
|
75
77
|
args ||= EMPTY_LIST
|
78
|
+
type_hints ||= EMPTY_LIST
|
76
79
|
|
77
80
|
case statement
|
78
81
|
when String
|
79
|
-
@statements << Simple.new(statement, args)
|
82
|
+
@statements << Simple.new(statement, args, type_hints)
|
80
83
|
when Prepared
|
81
84
|
@statements << statement.bind(args)
|
82
85
|
when Bound, Simple
|
@@ -33,7 +33,10 @@ module Cassandra
|
|
33
33
|
attr_reader :params_names
|
34
34
|
|
35
35
|
# @param cql [String] a cql statement
|
36
|
-
# @param params [Array] (nil) positional
|
36
|
+
# @param params [Array, Hash] (nil) positional or named arguments
|
37
|
+
# for the query
|
38
|
+
# @param type_hints [Array, Hash] (nil) positional or named types
|
39
|
+
# to override type guessing for the query
|
37
40
|
#
|
38
41
|
# @note Positional arguments for simple statements are only supported
|
39
42
|
# starting with Apache Cassandra 2.0 and above.
|
@@ -42,25 +45,37 @@ module Cassandra
|
|
42
45
|
# starting with Apache Cassandra 2.1 and above.
|
43
46
|
#
|
44
47
|
# @raise [ArgumentError] if cql statement given is not a String
|
45
|
-
def initialize(cql, params = nil)
|
48
|
+
def initialize(cql, params = nil, type_hints = nil)
|
46
49
|
Util.assert_instance_of(::String, cql) { "cql must be a string, #{cql.inspect} given" }
|
47
50
|
|
48
51
|
params ||= EMPTY_LIST
|
49
52
|
|
53
|
+
|
50
54
|
if params.is_a?(::Hash)
|
51
55
|
params_names = []
|
52
56
|
params = params.each_with_object([]) do |(name, value), params|
|
53
57
|
params_names << name
|
54
58
|
params << value
|
55
59
|
end
|
60
|
+
if type_hints && !type_hints.empty?
|
61
|
+
Util.assert_instance_of(::Hash, type_hints) { "type_hints must be a Hash when using named params" }
|
62
|
+
end
|
56
63
|
else
|
57
64
|
Util.assert_instance_of(::Array, params) { "params must be an Array or a Hash, #{params.inspect} given" }
|
58
65
|
params_names = EMPTY_LIST
|
59
66
|
end
|
60
67
|
|
68
|
+
type_hints ||= EMPTY_LIST
|
69
|
+
|
70
|
+
if type_hints.is_a?(::Hash)
|
71
|
+
type_hints = params_names.map {|name| type_hints[name] }
|
72
|
+
else
|
73
|
+
Util.assert_instance_of(::Array, type_hints) { "type_hints must be an Array or a Hash, #{type_hints.inspect} given" }
|
74
|
+
end
|
75
|
+
|
61
76
|
@cql = cql
|
62
77
|
@params = params
|
63
|
-
@params_types = params.map {|value| Util.guess_type(value)}
|
78
|
+
@params_types = params.each_with_index.map {|value, index| (!type_hints.empty? && type_hints[index] && type_hints[index].is_a?(Type)) ? type_hints[index] : Util.guess_type(value)}
|
64
79
|
@params_names = params_names
|
65
80
|
end
|
66
81
|
|
data/lib/cassandra/version.rb
CHANGED
data/lib/cassandra_murmur3.jar
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cassandra-driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Theo Hultberg
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ione
|