cassandra-driver 3.0.0.beta.1-java → 3.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -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.
|
@@ -32,17 +32,28 @@ module Cassandra
|
|
32
32
|
attr_reader :options
|
33
33
|
# @return [Array<Cassandra::Host>] a list of attempted hosts
|
34
34
|
attr_reader :hosts
|
35
|
-
# Actual consistency used, it can differ from consistency in
|
35
|
+
# Actual consistency used, it can differ from consistency in
|
36
|
+
# {Cassandra::Execution::Info#options} if a retry policy modified it.
|
36
37
|
# @return [Symbol] one of {Cassandra::CONSISTENCIES}
|
37
38
|
attr_reader :consistency
|
38
39
|
# @return [Integer] number of retries
|
39
40
|
attr_reader :retries
|
40
|
-
# Returns {Cassandra::Execution::Trace} if `trace: true` was passed to
|
41
|
-
#
|
41
|
+
# Returns {Cassandra::Execution::Trace} if `trace: true` was passed to
|
42
|
+
# {Cassandra::Session#execute} or {Cassandra::Session#execute_async}
|
43
|
+
# @return [Cassandra::Execution::Trace, nil] a Trace if it has been enabled for
|
44
|
+
# request
|
42
45
|
attr_reader :trace
|
43
46
|
|
44
47
|
# @private
|
45
|
-
def initialize(payload,
|
48
|
+
def initialize(payload,
|
49
|
+
warnings,
|
50
|
+
keyspace,
|
51
|
+
statement,
|
52
|
+
options,
|
53
|
+
hosts,
|
54
|
+
consistency,
|
55
|
+
retries,
|
56
|
+
trace)
|
46
57
|
@payload = payload
|
47
58
|
@warnings = warnings
|
48
59
|
@keyspace = keyspace
|
@@ -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.
|
@@ -38,11 +38,11 @@ module Cassandra
|
|
38
38
|
# @return [String] paging state
|
39
39
|
#
|
40
40
|
# @note Although this feature exists to allow web applications to store
|
41
|
-
# paging state in an [HTTP cookie](http://en.wikipedia.org/wiki/HTTP_cookie),
|
42
|
-
# expose without encrypting or otherwise securing it**.
|
43
|
-
# contains information internal to the Apache Cassandra cluster,
|
44
|
-
# partition key and data. Additionally, if a paging state is sent with
|
45
|
-
# statement, different from the original, the behavior of Cassandra is
|
41
|
+
# paging state in an [HTTP cookie](http://en.wikipedia.org/wiki/HTTP_cookie),
|
42
|
+
# **it is not safe to expose without encrypting or otherwise securing it**.
|
43
|
+
# Paging state contains information internal to the Apache Cassandra cluster,
|
44
|
+
# such as partition key and data. Additionally, if a paging state is sent with
|
45
|
+
# CQL statement, different from the original, the behavior of Cassandra is
|
46
46
|
# undefined and will likely cause a server process of the coordinator of
|
47
47
|
# such request to abort.
|
48
48
|
#
|
@@ -52,8 +52,10 @@ module Cassandra
|
|
52
52
|
# @return [nil, Hash<String, String>] custom outgoing payload, a map of
|
53
53
|
# string and byte buffers.
|
54
54
|
#
|
55
|
-
# @see https://github.com/apache/cassandra/blob/
|
56
|
-
#
|
55
|
+
# @see https://github.com/apache/cassandra/blob/cassandra-3.4/doc/native_protocol_v4.spec#L125-L131 Description
|
56
|
+
# of custom payload in Cassandra native protocol v4.
|
57
|
+
# @see https://datastax.github.io/java-driver/manual/custom_payloads/#enabling-custom-payloads-on-c-nodes
|
58
|
+
# Enabling custom payloads on Cassandra nodes.
|
57
59
|
#
|
58
60
|
# @example Sending a custom payload
|
59
61
|
# result = session.execute(payload: {
|
@@ -63,7 +65,10 @@ module Cassandra
|
|
63
65
|
attr_reader :payload
|
64
66
|
|
65
67
|
# @private
|
66
|
-
|
68
|
+
# @param options [Hash] execution options to validate and encapsulate
|
69
|
+
# @param trusted_options [Options] (optional) base Execution::Options from which
|
70
|
+
# to create this new Options object.
|
71
|
+
def initialize(options, trusted_options = nil)
|
67
72
|
consistency = options[:consistency]
|
68
73
|
page_size = options[:page_size]
|
69
74
|
trace = options[:trace]
|
@@ -75,61 +80,114 @@ module Cassandra
|
|
75
80
|
idempotent = options[:idempotent]
|
76
81
|
payload = options[:payload]
|
77
82
|
|
78
|
-
|
83
|
+
# consistency is a required attribute of an Options object. If we are creating
|
84
|
+
# an Options object from scratch (e.g. no trusted_options as base) validate the
|
85
|
+
# given consistency value (even if nil). Otherwise we're overlaying and only
|
86
|
+
# validate the consistency option if given.
|
87
|
+
if trusted_options.nil? || !consistency.nil?
|
88
|
+
Util.assert_one_of(CONSISTENCIES, consistency) do
|
89
|
+
":consistency must be one of #{CONSISTENCIES.inspect}, " \
|
90
|
+
"#{consistency.inspect} given"
|
91
|
+
end
|
92
|
+
end
|
79
93
|
|
80
94
|
unless serial_consistency.nil?
|
81
|
-
Util.assert_one_of(SERIAL_CONSISTENCIES, serial_consistency)
|
95
|
+
Util.assert_one_of(SERIAL_CONSISTENCIES, serial_consistency) do
|
96
|
+
":serial_consistency must be one of #{SERIAL_CONSISTENCIES.inspect}, " \
|
97
|
+
"#{serial_consistency.inspect} given"
|
98
|
+
end
|
82
99
|
end
|
83
100
|
|
84
101
|
unless page_size.nil?
|
85
102
|
page_size = Integer(page_size)
|
86
|
-
Util.assert(page_size > 0)
|
103
|
+
Util.assert(page_size > 0) do
|
104
|
+
":page_size must be a positive integer, #{page_size.inspect} given"
|
105
|
+
end
|
87
106
|
end
|
88
107
|
|
89
108
|
unless timeout.nil?
|
90
|
-
Util.assert_instance_of(::Numeric, timeout)
|
109
|
+
Util.assert_instance_of(::Numeric, timeout) do
|
110
|
+
":timeout must be a number of seconds, #{timeout} given"
|
111
|
+
end
|
91
112
|
Util.assert(timeout > 0) { ":timeout must be greater than 0, #{timeout} given" }
|
92
113
|
end
|
93
114
|
|
94
115
|
unless paging_state.nil?
|
95
116
|
paging_state = String(paging_state)
|
96
|
-
Util.assert_not_empty(paging_state) {
|
97
|
-
|
117
|
+
Util.assert_not_empty(paging_state) { ':paging_state must not be empty' }
|
118
|
+
|
119
|
+
# We require page_size in either the new options or trusted options.
|
120
|
+
Util.assert(!page_size.nil? ||
|
121
|
+
!(trusted_options.nil? || trusted_options.page_size.nil?)) do
|
122
|
+
':page_size is required when :paging_state is given'
|
123
|
+
end
|
98
124
|
end
|
99
125
|
|
100
|
-
|
126
|
+
# :arguments defaults to empty-list, but we want to delegate to trusted_options
|
127
|
+
# if it's set. So the logic is as follows:
|
128
|
+
# If an arguments option was given, validate and use it regardless of anything
|
129
|
+
# else.
|
130
|
+
# Otherwise, if we have trusted_options, leave arguments nil for now so as not
|
131
|
+
# to override trusted_options. Finally, if we don't have an arguments option
|
132
|
+
# nor do we have trusted_options, fall back to the default empty-list.
|
133
|
+
#
|
134
|
+
# :type_hints works exactly the same way.
|
135
|
+
if !arguments.nil?
|
136
|
+
Util.assert_instance_of_one_of([::Array, ::Hash], arguments) do
|
137
|
+
":arguments must be an Array or a Hash, #{arguments.inspect} given"
|
138
|
+
end
|
139
|
+
elsif trusted_options.nil?
|
101
140
|
arguments = EMPTY_LIST
|
102
|
-
else
|
103
|
-
Util.assert_instance_of_one_of([::Array, ::Hash], arguments) { ":arguments must be an Array or a Hash, #{arguments.inspect} given" }
|
104
141
|
end
|
105
142
|
|
106
|
-
if type_hints.nil?
|
143
|
+
if !type_hints.nil?
|
144
|
+
Util.assert_instance_of_one_of([::Array, ::Hash], type_hints) do
|
145
|
+
":type_hints must be an Array or a Hash, #{type_hints.inspect} given"
|
146
|
+
end
|
147
|
+
elsif trusted_options.nil?
|
107
148
|
type_hints = EMPTY_LIST
|
108
|
-
else
|
109
|
-
Util.assert_instance_of_one_of([::Array, ::Hash], type_hints) { ":type_hints must be an Array or a Hash, #{type_hints.inspect} given" }
|
110
149
|
end
|
111
150
|
|
112
151
|
unless payload.nil?
|
113
|
-
Util.assert_instance_of(::Hash, payload) {
|
114
|
-
Util.assert_not_empty(payload) {
|
115
|
-
Util.assert(payload.size <= 65535)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
152
|
+
Util.assert_instance_of(::Hash, payload) { ':payload must be a Hash' }
|
153
|
+
Util.assert_not_empty(payload) { ':payload must not be empty' }
|
154
|
+
Util.assert(payload.size <= 65535) do
|
155
|
+
':payload cannot contain more than 65535 key/value pairs'
|
156
|
+
end
|
157
|
+
|
158
|
+
payload = payload.each_with_object(::Hash.new) do |(key, value), p|
|
159
|
+
p[String(key)] = String(value)
|
160
|
+
end
|
120
161
|
payload.freeze
|
121
162
|
end
|
122
163
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
164
|
+
# Ok, validation is done. Time to save off all our values in our instance vars,
|
165
|
+
# merging in values from trusted_options if it's set. To keep things readable,
|
166
|
+
# we just put this into two branches of an if-else.
|
167
|
+
|
168
|
+
if trusted_options.nil?
|
169
|
+
@consistency = consistency
|
170
|
+
@page_size = page_size
|
171
|
+
@trace = !!trace
|
172
|
+
@timeout = timeout
|
173
|
+
@serial_consistency = serial_consistency
|
174
|
+
@arguments = arguments
|
175
|
+
@type_hints = type_hints
|
176
|
+
else
|
177
|
+
@consistency = consistency || trusted_options.consistency
|
178
|
+
@page_size = page_size || trusted_options.page_size
|
179
|
+
@trace = trace.nil? ? trusted_options.trace? : !!trace
|
180
|
+
@timeout = timeout || trusted_options.timeout
|
181
|
+
@serial_consistency = serial_consistency || trusted_options.serial_consistency
|
182
|
+
@arguments = arguments || trusted_options.arguments
|
183
|
+
@type_hints = type_hints || trusted_options.type_hints
|
184
|
+
end
|
185
|
+
|
186
|
+
# The following fields are *not* inherited from trusted_options, so we always
|
187
|
+
# rely on the options we were given.
|
188
|
+
@paging_state = paging_state
|
189
|
+
@idempotent = !!idempotent
|
190
|
+
@payload = payload
|
133
191
|
end
|
134
192
|
|
135
193
|
# @return [Boolean] whether request tracing was enabled
|
@@ -154,30 +212,19 @@ module Cassandra
|
|
154
212
|
other.arguments == @arguments &&
|
155
213
|
other.type_hints == @type_hints
|
156
214
|
end
|
157
|
-
alias
|
215
|
+
alias == eql?
|
158
216
|
|
159
217
|
# @private
|
160
218
|
def override(*options)
|
161
|
-
merged = options.unshift(
|
219
|
+
merged = options.unshift({}).inject do |base, opts|
|
162
220
|
next base unless opts
|
163
|
-
Util.assert_instance_of(::Hash, opts)
|
221
|
+
Util.assert_instance_of(::Hash, opts) do
|
222
|
+
"options must be a Hash, #{options.inspect} given"
|
223
|
+
end
|
164
224
|
base.merge!(opts)
|
165
225
|
end
|
166
226
|
|
167
|
-
Options.new(merged)
|
168
|
-
end
|
169
|
-
|
170
|
-
# @private
|
171
|
-
def to_h
|
172
|
-
{
|
173
|
-
:consistency => @consistency,
|
174
|
-
:page_size => @page_size,
|
175
|
-
:trace => @trace,
|
176
|
-
:timeout => @timeout,
|
177
|
-
:serial_consistency => @serial_consistency,
|
178
|
-
:arguments => @arguments || EMPTY_LIST,
|
179
|
-
:type_hints => @type_hints || EMPTY_LIST
|
180
|
-
}
|
227
|
+
Options.new(merged, self)
|
181
228
|
end
|
182
229
|
end
|
183
230
|
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.
|
@@ -44,7 +44,7 @@ module Cassandra
|
|
44
44
|
other == @id
|
45
45
|
end
|
46
46
|
|
47
|
-
alias
|
47
|
+
alias eql? ==
|
48
48
|
end
|
49
49
|
|
50
50
|
include MonitorMixin
|
@@ -124,15 +124,15 @@ module Cassandra
|
|
124
124
|
|
125
125
|
# @private
|
126
126
|
def inspect
|
127
|
-
"#<#{self.class.name}:0x#{
|
127
|
+
"#<#{self.class.name}:0x#{object_id.to_s(16)} @id=#{@id.inspect}>"
|
128
128
|
end
|
129
129
|
|
130
130
|
private
|
131
131
|
|
132
132
|
# @private
|
133
|
-
SELECT_SESSION =
|
133
|
+
SELECT_SESSION = 'SELECT * FROM system_traces.sessions WHERE session_id = %s'.freeze
|
134
134
|
# @private
|
135
|
-
SELECT_EVENTS =
|
135
|
+
SELECT_EVENTS = 'SELECT * FROM system_traces.events WHERE session_id = %s'.freeze
|
136
136
|
|
137
137
|
# @private
|
138
138
|
def load
|
@@ -140,11 +140,13 @@ module Cassandra
|
|
140
140
|
return if @loaded
|
141
141
|
|
142
142
|
attempt = 1
|
143
|
-
data = @client.query(Statements::Simple.new(SELECT_SESSION % @id),
|
143
|
+
data = @client.query(Statements::Simple.new(SELECT_SESSION % @id),
|
144
|
+
VOID_OPTIONS).get.first
|
144
145
|
|
145
146
|
while data.nil? && attempt <= 5
|
146
147
|
sleep(attempt * 0.4)
|
147
|
-
data = @client.query(Statements::Simple.new(SELECT_SESSION % @id),
|
148
|
+
data = @client.query(Statements::Simple.new(SELECT_SESSION % @id),
|
149
|
+
VOID_OPTIONS).get.first
|
148
150
|
break if data
|
149
151
|
attempt += 1
|
150
152
|
end
|
@@ -170,8 +172,13 @@ module Cassandra
|
|
170
172
|
|
171
173
|
@events = []
|
172
174
|
|
173
|
-
@client.query(Statements::Simple.new(SELECT_EVENTS % @id),
|
174
|
-
|
175
|
+
@client.query(Statements::Simple.new(SELECT_EVENTS % @id),
|
176
|
+
VOID_OPTIONS).get.each do |row|
|
177
|
+
@events << Event.new(row['event_id'],
|
178
|
+
row['activity'],
|
179
|
+
row['source'],
|
180
|
+
row['source_elapsed'],
|
181
|
+
row['thread'])
|
175
182
|
end
|
176
183
|
|
177
184
|
@events.freeze
|
data/lib/cassandra/executors.rb
CHANGED
data/lib/cassandra/function.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.
|
@@ -57,7 +57,7 @@ module Cassandra
|
|
57
57
|
# @param name [String] argument name
|
58
58
|
# @return [Boolean] whether this function has a given argument
|
59
59
|
def has_argument?(name)
|
60
|
-
@arguments_hash.
|
60
|
+
@arguments_hash.key?(name)
|
61
61
|
end
|
62
62
|
|
63
63
|
# @param name [String] argument name
|
@@ -82,12 +82,12 @@ module Cassandra
|
|
82
82
|
@arguments.dup
|
83
83
|
end
|
84
84
|
end
|
85
|
-
alias
|
85
|
+
alias arguments each_argument
|
86
86
|
|
87
87
|
# Get the list of argument types for this function.
|
88
88
|
# @return [Array<Cassandra::Type>] a list of argument types.
|
89
89
|
def argument_types
|
90
|
-
@arguments.map
|
90
|
+
@arguments.map(&:type)
|
91
91
|
end
|
92
92
|
|
93
93
|
# @private
|
@@ -101,7 +101,7 @@ module Cassandra
|
|
101
101
|
@body == other.body && \
|
102
102
|
@called_on_null == other.called_on_null?
|
103
103
|
end
|
104
|
-
alias
|
104
|
+
alias == eql?
|
105
105
|
|
106
106
|
# @private
|
107
107
|
def hash
|
@@ -120,7 +120,13 @@ module Cassandra
|
|
120
120
|
|
121
121
|
# @private
|
122
122
|
def inspect
|
123
|
-
"#<Cassandra::Function:0x#{
|
123
|
+
"#<Cassandra::Function:0x#{object_id.to_s(16)} " \
|
124
|
+
"@keyspace=#{@keyspace.inspect}, " \
|
125
|
+
"@name=#{@name.inspect}, " \
|
126
|
+
"@language=#{@language.inspect}, " \
|
127
|
+
"@type=#{@type.inspect}, " \
|
128
|
+
"@arguments=#{@arguments.inspect} " \
|
129
|
+
"@body=#{@body.inspect}>"
|
124
130
|
end
|
125
131
|
|
126
132
|
# @return [String] a cql representation of this function
|
@@ -135,16 +141,16 @@ module Cassandra
|
|
135
141
|
end
|
136
142
|
cql << "#{argument.name} #{argument.type}"
|
137
143
|
end
|
138
|
-
cql <<
|
139
|
-
if @called_on_null
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
+
cql << ')'
|
145
|
+
cql << if @called_on_null
|
146
|
+
"\n CALLED ON NULL INPUT"
|
147
|
+
else
|
148
|
+
"\n RETURNS NULL ON NULL INPUT"
|
149
|
+
end
|
144
150
|
cql << "\n RETURNS #{@type}"
|
145
151
|
cql << "\n LANGUAGE #{@language}"
|
146
152
|
cql << "\n AS $$#{@body}$$"
|
147
|
-
cql <<
|
153
|
+
cql << ';'
|
148
154
|
end
|
149
155
|
end
|
150
156
|
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
#--
|
4
|
+
# Copyright 2013-2016 DataStax, Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#++
|
18
|
+
|
19
|
+
module Cassandra
|
20
|
+
# @private
|
21
|
+
# This class encapsulates a collection of functions or aggregates.
|
22
|
+
# Really used internally, so it should not be documented.
|
23
|
+
class FunctionCollection
|
24
|
+
def initialize
|
25
|
+
@function_hash = {}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get the Function or Aggregate with the given name and argument-types.
|
29
|
+
# @param name [String] the name of the function/aggregate.
|
30
|
+
# @param argument_types [Array<Cassandra::Type>] list of argument-types.
|
31
|
+
# @return [Cassandra::Function] or [Cassandra::Aggregate] if found;
|
32
|
+
# nil otherwise.
|
33
|
+
def get(name, argument_types)
|
34
|
+
@function_hash[[name, argument_types]]
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_or_update(function)
|
38
|
+
@function_hash[[function.name, function.argument_types]] = function
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete(name, argument_types)
|
42
|
+
@function_hash.delete([name, argument_types])
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Boolean] whether this FunctionCollection is equal to the other
|
46
|
+
def eql?(other)
|
47
|
+
other.is_a?(FunctionCollection) &&
|
48
|
+
@function_hash == other.raw_functions
|
49
|
+
end
|
50
|
+
alias == eql?
|
51
|
+
|
52
|
+
def hash
|
53
|
+
@function_hash.hash
|
54
|
+
end
|
55
|
+
|
56
|
+
# Yield or enumerate each function defined in this collection
|
57
|
+
# @overload each_function
|
58
|
+
# @yieldparam function [Cassandra::Function or Cassandra::Aggregate]
|
59
|
+
# current function or aggregate
|
60
|
+
# @return [Cassandra::FunctionCollection] self
|
61
|
+
# @overload each_function
|
62
|
+
# @return [Array<Cassandra::Function> or Array<Cassandra::Aggregate>]
|
63
|
+
# a list of functions or aggregates.
|
64
|
+
def each_function(&block)
|
65
|
+
if block_given?
|
66
|
+
@function_hash.each_value(&block)
|
67
|
+
self
|
68
|
+
else
|
69
|
+
@function_hash.values
|
70
|
+
end
|
71
|
+
end
|
72
|
+
alias functions each_function
|
73
|
+
|
74
|
+
def inspect
|
75
|
+
"#<Cassandra::FunctionCollection:0x#{object_id.to_s(16)} " \
|
76
|
+
"@function_hash=#{@function_hash.inspect}>"
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
def raw_functions
|
82
|
+
@function_hash
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|