@@ -207,9 +207,11 @@ def keyspace_dropped(keyspace)
207207 def query ( statement , options )
208208 return @futures . error ( Errors ::ClientError . new ( "Positional arguments are not supported by the current version of Apache Cassandra" ) ) if !statement . params . empty? && @connection_options . protocol_version == 1
209209
210- request = Protocol ::QueryRequest . new ( statement . cql , statement . params , statement . params_types , options . consistency , options . serial_consistency , options . page_size , options . paging_state , options . trace? , statement . params_names )
211- timeout = options . timeout
212- promise = @futures . promise
210+ timestamp = nil
211+ timestamp = Time . now if @connection_options . client_timestamps? && @connection_options . protocol_version > 2
212+ request = Protocol ::QueryRequest . new ( statement . cql , statement . params , statement . params_types , options . consistency , options . serial_consistency , options . page_size , options . paging_state , options . trace? , statement . params_names , timestamp )
213+ timeout = options . timeout
214+ promise = @futures . promise
213215
214216 keyspace = @keyspace
215217 plan = @load_balancing_policy . plan ( keyspace , statement , options )
@@ -234,9 +236,11 @@ def prepare(cql, options)
234236 end
235237
236238 def execute ( statement , options )
239+ timestamp = nil
240+ timestamp = Time . now if @connection_options . client_timestamps? && @connection_options . protocol_version > 2
237241 timeout = options . timeout
238242 result_metadata = statement . result_metadata
239- request = Protocol ::ExecuteRequest . new ( nil , statement . params_types , statement . params , result_metadata . nil? , options . consistency , options . serial_consistency , options . page_size , options . paging_state , options . trace? )
243+ request = Protocol ::ExecuteRequest . new ( nil , statement . params_types , statement . params , result_metadata . nil? , options . consistency , options . serial_consistency , options . page_size , options . paging_state , options . trace? , timestamp )
240244 promise = @futures . promise
241245
242246 keyspace = @keyspace
@@ -250,12 +254,15 @@ def execute(statement, options)
250254 def batch ( statement , options )
251255 return @futures . error ( Errors ::ClientError . new ( "Batch statements are not supported by the current version of Apache Cassandra" ) ) if @connection_options . protocol_version < 2
252256
253- timeout = options . timeout
254- keyspace = @keyspace
255- plan = @load_balancing_policy . plan ( keyspace , statement , options )
256- promise = @futures . promise
257+ timestamp = nil
258+ timestamp = Time . now if @connection_options . client_timestamps? && @connection_options . protocol_version > 2
259+ timeout = options . timeout
260+ request = Protocol ::BatchRequest . new ( BATCH_TYPES [ statement . type ] , options . consistency , options . trace? , options . serial_consistency , timestamp )
261+ keyspace = @keyspace
262+ plan = @load_balancing_policy . plan ( keyspace , statement , options )
263+ promise = @futures . promise
257264
258- batch_by_plan ( promise , keyspace , statement , options , plan , timeout )
265+ batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout )
259266
260267 promise . future
261268 end
@@ -509,7 +516,7 @@ def prepare_and_send_request_by_plan(host, connection, promise, keyspace, statem
509516 end
510517 end
511518
512- def batch_by_plan ( promise , keyspace , statement , options , plan , timeout , errors = nil , hosts = [ ] )
519+ def batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors = nil , hosts = [ ] )
513520 unless plan . has_next?
514521 promise . break ( Errors ::NoHostsAvailable . new ( errors ) )
515522 return
@@ -522,7 +529,7 @@ def batch_by_plan(promise, keyspace, statement, options, plan, timeout, errors =
522529 unless pool
523530 errors ||= { }
524531 errors [ host ] = NOT_CONNECTED
525- return batch_by_plan ( promise , keyspace , statement , options , plan , timeout , errors , hosts )
532+ return batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
526533 end
527534
528535 connection = pool . random_connection
@@ -531,31 +538,31 @@ def batch_by_plan(promise, keyspace, statement, options, plan, timeout, errors =
531538 switch = switch_keyspace ( connection , keyspace , timeout )
532539 switch . on_complete do |s |
533540 if s . resolved?
534- batch_and_send_request_by_plan ( host , connection , promise , keyspace , statement , options , plan , timeout , errors , hosts )
541+ batch_and_send_request_by_plan ( host , connection , promise , keyspace , statement , request , options , plan , timeout , errors , hosts )
535542 else
536543 s . on_failure do |e |
537544 case e
538545 when Errors ::HostError
539546 errors ||= { }
540547 errors [ host ] = e
541- batch_by_plan ( promise , keyspace , statement , options , plan , timeout , errors , hosts )
548+ batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
542549 else
543550 promise . break ( e )
544551 end
545552 end
546553 end
547554 end
548555 else
549- batch_and_send_request_by_plan ( host , connection , promise , keyspace , statement , options , plan , timeout , errors , hosts )
556+ batch_and_send_request_by_plan ( host , connection , promise , keyspace , statement , request , options , plan , timeout , errors , hosts )
550557 end
551558 rescue => e
552559 errors ||= { }
553560 errors [ host ] = e
554- batch_by_plan ( promise , keyspace , statement , options , plan , timeout , errors , hosts )
561+ batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
555562 end
556563
557- def batch_and_send_request_by_plan ( host , connection , promise , keyspace , statement , options , plan , timeout , errors , hosts )
558- request = Protocol :: BatchRequest . new ( BATCH_TYPES [ statement . type ] , options . consistency , options . trace? )
564+ def batch_and_send_request_by_plan ( host , connection , promise , keyspace , statement , request , options , plan , timeout , errors , hosts )
565+ request . clear
559566 unprepared = Hash . new { |hash , cql | hash [ cql ] = [ ] }
560567
561568 statement . statements . each do |statement |
@@ -598,7 +605,7 @@ def batch_and_send_request_by_plan(host, connection, promise, keyspace, statemen
598605 when Errors ::HostError
599606 errors ||= { }
600607 errors [ host ] = e
601- batch_by_plan ( promise , keyspace , statement , options , plan , timeout , errors , hosts )
608+ batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
602609 else
603610 promise . break ( e )
604611 end
@@ -711,7 +718,7 @@ def do_send_request_by_plan(host, connection, promise, keyspace, statement, opti
711718 when Protocol ::ExecuteRequest
712719 execute_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
713720 when Protocol ::BatchRequest
714- batch_by_plan ( promise , keyspace , statement , options , plan , timeout , errors , hosts )
721+ batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
715722 end
716723 else
717724 promise . break ( error )
@@ -774,7 +781,7 @@ def do_send_request_by_plan(host, connection, promise, keyspace, statement, opti
774781 when Protocol ::ExecuteRequest
775782 execute_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
776783 when Protocol ::BatchRequest
777- batch_by_plan ( promise , keyspace , statement , options , plan , timeout , errors , hosts )
784+ batch_by_plan ( promise , keyspace , statement , options , request , plan , timeout , errors , hosts )
778785 else
779786 promise . break ( e )
780787 end
0 commit comments