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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32c86970c749f6a1afe3c4af85e2d16eb62c11f9
4
- data.tar.gz: 97c1cacbbffa03e9d1162dce3bbf0a1929b02af2
3
+ metadata.gz: b54cece0a4702c4e54ce84d876a1efc6dc2b913b
4
+ data.tar.gz: 045113e69793b513866c82251ee22ad1e47cfdd9
5
5
  SHA512:
6
- metadata.gz: 52a010f2c3254b953ff1d9af072ecba957def21236fafa3467029ef1fa4a50428c8179a5ee9cc5b9a421082347ad45da07966512bc8cf012fa687578eabcada9
7
- data.tar.gz: 85094e7b051ae8c91c1b6caf8669383e4671ccb18095f6265c6aff8270f47fe0debde9465042e2bb1ec8070f29e8fd66d5bd6f6d6dd132ea5d54a1e99e5cf121
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
- -- README
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/trunk/doc/native_protocol_v1.spec#L591-L603 Description of possible types of writes in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L238-L250). Note that if you specified `:username` and `:password` options, those credentials are configured automatically.
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/trunk/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.
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
@@ -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/trunk/doc/native_protocol_v2.spec#L257-L273 Cassandra native protocol v2 SASL authentication
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.udpate_table(host, keyspace, tables.first, columns)
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.udpate_type(host, keyspace, types.first)
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 udpate_table(host, keyspace_name, table, columns)
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 udpate_type(host, keyspace_name, type)
177
+ def update_type(host, keyspace_name, type)
178
178
  keyspace = @keyspaces[keyspace_name]
179
179
 
180
180
  return self unless keyspace
@@ -148,9 +148,8 @@ module Cassandra
148
148
  promise.fulfill(cluster)
149
149
  else
150
150
  f.on_failure do |e|
151
- cluster.close_async.on_complete do |_, _|
152
- promise.break(e)
153
- end
151
+ cluster.close_async
152
+ promise.break(e)
154
153
  end
155
154
  end
156
155
  end
@@ -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/trunk/doc/native_protocol_v1.spec#L554-L555 Description of Server Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L562-L572 Description of Unavailable Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L573-L574 Description of Overloaded Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L575-L576 Description of Is Bootstrapping Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L577 Description of Truncate Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L578-L603 Description of Write Timeout Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L604-L622 Description of Read Timeout Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L556-L558 Description of Protocol Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L559-L561 Description of Bad Credentials Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L638-L641 Description of Unprepared Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L623 Description of Syntax Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L624-L625 Description of Unauthorized Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L626 Description of Invalid Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L627 Description of Config Error in Apache Cassandra native protocol spec v1
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/trunk/doc/native_protocol_v1.spec#L628-L637 Description of Already Exists Error in Apache Cassandra native protocol spec v1
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
- size = read_unsigned_short
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
@@ -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/trunk/doc/native_protocol_v2.spec#L482-L487 Paging State description in Cassandra Native Protocol v2 specification
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
@@ -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 arguments for the query
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
 
@@ -17,5 +17,5 @@
17
17
  #++
18
18
 
19
19
  module Cassandra
20
- VERSION = '2.1.4'.freeze
20
+ VERSION = '2.1.5'.freeze
21
21
  end
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
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-07-01 00:00:00.000000000 Z
12
+ date: 2015-09-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ione