cassandra-driver 3.0.0.beta.1-java → 3.0.0-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/README.md +106 -39
 - data/lib/cassandra.rb +396 -148
 - 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/attr_boolean.rb +33 -0
 - data/lib/cassandra/auth.rb +6 -5
 - data/lib/cassandra/auth/providers.rb +1 -1
 - data/lib/cassandra/auth/providers/password.rb +5 -13
 - data/lib/cassandra/cassandra_logger.rb +80 -0
 - data/lib/cassandra/cluster.rb +49 -9
 - data/lib/cassandra/cluster/client.rb +835 -209
 - data/lib/cassandra/cluster/connection_pool.rb +2 -2
 - data/lib/cassandra/cluster/connector.rb +86 -27
 - data/lib/cassandra/cluster/control_connection.rb +222 -95
 - data/lib/cassandra/cluster/failed_connection.rb +1 -1
 - data/lib/cassandra/cluster/metadata.rb +14 -8
 - data/lib/cassandra/cluster/options.rb +68 -22
 - data/lib/cassandra/cluster/registry.rb +81 -17
 - data/lib/cassandra/cluster/schema.rb +70 -8
 - data/lib/cassandra/cluster/schema/cql_type_parser.rb +15 -10
 - data/lib/cassandra/cluster/schema/fetchers.rb +601 -241
 - data/lib/cassandra/cluster/schema/fqcn_type_parser.rb +39 -38
 - data/lib/cassandra/cluster/schema/partitioners.rb +1 -1
 - data/lib/cassandra/cluster/schema/partitioners/murmur3.rb +6 -8
 - 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 +4 -23
 - data/lib/cassandra/column_container.rb +322 -0
 - data/lib/cassandra/compression.rb +1 -1
 - data/lib/cassandra/compression/compressors/lz4.rb +7 -8
 - data/lib/cassandra/compression/compressors/snappy.rb +4 -3
 - data/lib/cassandra/driver.rb +107 -46
 - data/lib/cassandra/errors.rb +303 -52
 - data/lib/cassandra/execution/info.rb +16 -5
 - data/lib/cassandra/execution/options.rb +102 -55
 - 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 +101 -49
 - data/lib/cassandra/host.rb +25 -5
 - data/lib/cassandra/index.rb +118 -0
 - data/lib/cassandra/keyspace.rb +169 -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 +39 -25
 - data/lib/cassandra/load_balancing/policies/round_robin.rb +8 -1
 - data/lib/cassandra/load_balancing/policies/token_aware.rb +22 -13
 - data/lib/cassandra/load_balancing/policies/white_list.rb +18 -5
 - data/lib/cassandra/materialized_view.rb +90 -0
 - data/lib/cassandra/null_logger.rb +27 -6
 - data/lib/cassandra/protocol.rb +1 -1
 - data/lib/cassandra/protocol/coder.rb +81 -42
 - data/lib/cassandra/protocol/cql_byte_buffer.rb +58 -44
 - data/lib/cassandra/protocol/cql_protocol_handler.rb +57 -54
 - data/lib/cassandra/protocol/request.rb +6 -7
 - data/lib/cassandra/protocol/requests/auth_response_request.rb +3 -3
 - data/lib/cassandra/protocol/requests/batch_request.rb +17 -8
 - data/lib/cassandra/protocol/requests/credentials_request.rb +3 -3
 - data/lib/cassandra/protocol/requests/execute_request.rb +39 -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 +28 -23
 - data/lib/cassandra/protocol/requests/register_request.rb +2 -2
 - data/lib/cassandra/protocol/requests/startup_request.rb +8 -8
 - data/lib/cassandra/protocol/requests/void_query_request.rb +1 -1
 - data/lib/cassandra/protocol/response.rb +3 -4
 - data/lib/cassandra/protocol/responses/already_exists_error_response.rb +12 -2
 - data/lib/cassandra/protocol/responses/auth_challenge_response.rb +4 -5
 - data/lib/cassandra/protocol/responses/auth_success_response.rb +4 -5
 - data/lib/cassandra/protocol/responses/authenticate_response.rb +4 -5
 - data/lib/cassandra/protocol/responses/error_response.rb +104 -17
 - data/lib/cassandra/protocol/responses/event_response.rb +3 -4
 - data/lib/cassandra/protocol/responses/function_failure_error_response.rb +13 -2
 - data/lib/cassandra/protocol/responses/prepared_result_response.rb +14 -9
 - 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 +6 -7
 - data/lib/cassandra/protocol/responses/result_response.rb +11 -10
 - data/lib/cassandra/protocol/responses/rows_result_response.rb +8 -7
 - data/lib/cassandra/protocol/responses/schema_change_event_response.rb +8 -8
 - data/lib/cassandra/protocol/responses/schema_change_result_response.rb +19 -13
 - data/lib/cassandra/protocol/responses/set_keyspace_result_response.rb +5 -6
 - data/lib/cassandra/protocol/responses/status_change_event_response.rb +5 -6
 - data/lib/cassandra/protocol/responses/supported_response.rb +4 -5
 - data/lib/cassandra/protocol/responses/topology_change_event_response.rb +4 -5
 - 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 +4 -5
 - 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 +98 -37
 - data/lib/cassandra/protocol/v3.rb +121 -50
 - 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 +55 -20
 - 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 +4 -2
 - data/lib/cassandra/retry/policies/fallthrough.rb +1 -1
 - data/lib/cassandra/session.rb +24 -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 +62 -18
 - data/lib/cassandra/statements/simple.rb +23 -10
 - data/lib/cassandra/statements/void.rb +1 -1
 - data/lib/cassandra/table.rb +53 -185
 - data/lib/cassandra/time.rb +11 -6
 - data/lib/cassandra/time_uuid.rb +12 -14
 - 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/tuple.rb +4 -4
 - data/lib/cassandra/types.rb +109 -71
 - data/lib/cassandra/udt.rb +66 -50
 - data/lib/cassandra/util.rb +155 -15
 - data/lib/cassandra/uuid.rb +20 -21
 - data/lib/cassandra/uuid/generator.rb +7 -5
 - data/lib/cassandra/version.rb +2 -2
 - data/lib/cassandra_murmur3.jar +0 -0
 - data/lib/datastax/cassandra.rb +1 -1
 - metadata +27 -16
 
    
        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.
         
     | 
| 
         @@ -53,7 +53,9 @@ module Cassandra 
     | 
|
| 
       53 
53 
     | 
    
         
             
                    private
         
     | 
| 
       54 
54 
     | 
    
         | 
| 
       55 
55 
     | 
    
         
             
                    def max_likely_to_work(consistency, required, received)
         
     | 
| 
       56 
     | 
    
         
            -
                      if consistency == :all && 
     | 
| 
      
 56 
     | 
    
         
            +
                      if consistency == :all &&
         
     | 
| 
      
 57 
     | 
    
         
            +
                         required > 1 &&
         
     | 
| 
      
 58 
     | 
    
         
            +
                         received >= (required.to_f / 2).floor + 1
         
     | 
| 
       57 
59 
     | 
    
         
             
                        try_again(:quorum)
         
     | 
| 
       58 
60 
     | 
    
         
             
                      elsif received >= 3
         
     | 
| 
       59 
61 
     | 
    
         
             
                        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,9 @@ 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)} " \
         
     | 
| 
      
 242 
     | 
    
         
            +
                  "@keyspace=#{keyspace.inspect}, " \
         
     | 
| 
      
 243 
     | 
    
         
            +
                  "@options=#{@options.inspect}>"
         
     | 
| 
       236 
244 
     | 
    
         
             
                end
         
     | 
| 
       237 
245 
     | 
    
         
             
              end
         
     | 
| 
       238 
246 
     | 
    
         
             
            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
         
     | 
| 
         @@ -145,15 +189,15 @@ module Cassandra 
     | 
|
| 
       145 
189 
     | 
    
         
             
                      buffer.discard(4) # discard size
         
     | 
| 
       146 
190 
     | 
    
         
             
                    else
         
     | 
| 
       147 
191 
     | 
    
         
             
                      buf = Protocol::CqlByteBuffer.new
         
     | 
| 
       148 
     | 
    
         
            -
                      partition_key.each do | 
     | 
| 
       149 
     | 
    
         
            -
                        value    = values[ 
     | 
| 
       150 
     | 
    
         
            -
                        metadata = params_metadata[ 
     | 
| 
      
 192 
     | 
    
         
            +
                      partition_key.each do |ind|
         
     | 
| 
      
 193 
     | 
    
         
            +
                        value    = values[ind]
         
     | 
| 
      
 194 
     | 
    
         
            +
                        metadata = params_metadata[ind]
         
     | 
| 
       151 
195 
     | 
    
         
             
                        name     = metadata[2]
         
     | 
| 
       152 
196 
     | 
    
         
             
                        type     = metadata[3]
         
     | 
| 
       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
         
     |