couchbase 3.4.0 → 3.4.2
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 +2 -2
- data/ext/couchbase/CMakeLists.txt +10 -3
- data/ext/couchbase/cmake/CompilerWarnings.cmake +12 -4
- data/ext/couchbase/cmake/Documentation.cmake +4 -3
- data/ext/couchbase/cmake/OpenSSL.cmake +52 -7
- data/ext/couchbase/cmake/ThirdPartyDependencies.cmake +4 -0
- data/ext/couchbase/cmake/VersionInfo.cmake +39 -3
- data/ext/couchbase/cmake/test_openssl.cxx +7 -0
- data/ext/couchbase/core/cluster_options.hxx +0 -1
- data/ext/couchbase/core/config_profile.cxx +23 -1
- data/ext/couchbase/core/config_profile.hxx +2 -12
- data/ext/couchbase/core/crypto/CMakeLists.txt +5 -1
- data/ext/couchbase/core/impl/analytics.cxx +236 -0
- data/ext/couchbase/core/impl/cluster.cxx +0 -1
- data/ext/couchbase/core/impl/collection_query_index_manager.cxx +3 -3
- data/ext/couchbase/core/impl/dns_srv_tracker.cxx +5 -3
- data/ext/couchbase/core/impl/get_all_query_indexes.cxx +3 -3
- data/ext/couchbase/core/impl/query.cxx +5 -5
- data/ext/couchbase/core/impl/transaction_get_result.cxx +54 -0
- data/ext/couchbase/core/io/dns_client.cxx +225 -0
- data/ext/couchbase/core/io/dns_client.hxx +19 -188
- data/ext/couchbase/core/meta/CMakeLists.txt +7 -5
- data/ext/couchbase/core/meta/version.cxx +19 -0
- data/ext/couchbase/core/operations/document_search.cxx +5 -2
- data/ext/couchbase/core/operations/document_search.hxx +0 -1
- data/ext/couchbase/core/transactions/active_transaction_record.hxx +2 -2
- data/ext/couchbase/core/transactions/atr_cleanup_entry.cxx +1 -0
- data/ext/couchbase/core/transactions/attempt_context_impl.cxx +65 -31
- data/ext/couchbase/core/transactions/attempt_context_impl.hxx +44 -23
- data/ext/couchbase/core/transactions/forward_compat.hxx +2 -2
- data/ext/couchbase/core/transactions/internal/transaction_context.hxx +13 -13
- data/ext/couchbase/core/transactions/internal/transaction_fields.hxx +1 -0
- data/ext/couchbase/core/transactions/internal/transactions_cleanup.hxx +7 -1
- data/ext/couchbase/core/transactions/staged_mutation.cxx +1 -1
- data/ext/couchbase/core/transactions/staged_mutation.hxx +12 -2
- data/ext/couchbase/core/transactions/transaction_context.cxx +9 -11
- data/ext/couchbase/core/transactions/transaction_get_result.cxx +41 -31
- data/ext/couchbase/core/transactions/transaction_get_result.hxx +7 -3
- data/ext/couchbase/core/transactions/transaction_links.hxx +13 -1
- data/ext/couchbase/core/transactions/transactions_cleanup.cxx +144 -155
- data/ext/couchbase/core/transactions/waitable_op_list.hxx +1 -0
- data/ext/couchbase/core/utils/connection_string.cxx +10 -3
- data/ext/couchbase/core/utils/connection_string.hxx +3 -3
- data/ext/couchbase/couchbase/analytics_error_context.hxx +143 -0
- data/ext/couchbase/couchbase/analytics_meta_data.hxx +155 -0
- data/ext/couchbase/couchbase/analytics_metrics.hxx +163 -0
- data/ext/couchbase/couchbase/analytics_options.hxx +359 -0
- data/ext/couchbase/couchbase/analytics_result.hxx +102 -0
- data/ext/couchbase/couchbase/analytics_scan_consistency.hxx +46 -0
- data/ext/couchbase/couchbase/analytics_status.hxx +41 -0
- data/ext/couchbase/couchbase/analytics_warning.hxx +85 -0
- data/ext/couchbase/couchbase/cluster.hxx +35 -2
- data/ext/couchbase/couchbase/cluster_options.hxx +10 -10
- data/ext/couchbase/couchbase/collection.hxx +22 -17
- data/ext/couchbase/couchbase/collection_query_index_manager.hxx +1 -1
- data/ext/couchbase/couchbase/common_options.hxx +1 -1
- data/ext/couchbase/couchbase/configuration_profile.hxx +1 -1
- data/ext/couchbase/couchbase/configuration_profiles_registry.hxx +0 -1
- data/ext/couchbase/couchbase/create_primary_query_index_options.hxx +1 -1
- data/ext/couchbase/couchbase/drop_primary_query_index_options.hxx +1 -1
- data/ext/couchbase/couchbase/drop_query_index_options.hxx +1 -1
- data/ext/couchbase/couchbase/fmt/analytics_status.hxx +76 -0
- data/ext/couchbase/couchbase/fmt/cas.hxx +12 -0
- data/ext/couchbase/couchbase/fmt/durability_level.hxx +6 -0
- data/ext/couchbase/couchbase/fmt/key_value_extended_error_info.hxx +6 -0
- data/ext/couchbase/couchbase/fmt/key_value_status_code.hxx +6 -0
- data/ext/couchbase/couchbase/fmt/mutation_token.hxx +6 -0
- data/ext/couchbase/couchbase/fmt/query_scan_consistency.hxx +6 -0
- data/ext/couchbase/couchbase/fmt/query_status.hxx +6 -0
- data/ext/couchbase/couchbase/fmt/retry_reason.hxx +6 -0
- data/ext/couchbase/couchbase/fmt/tls_verify_mode.hxx +6 -0
- data/ext/couchbase/couchbase/get_all_query_indexes_options.hxx +5 -4
- data/ext/couchbase/couchbase/query_index_manager.hxx +4 -2
- data/ext/couchbase/couchbase/query_options.hxx +0 -1
- data/ext/couchbase/couchbase/scope.hxx +34 -1
- data/ext/couchbase/couchbase/subdoc/array_add_unique.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/array_append.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/array_insert.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/array_prepend.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/count.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/counter.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/exists.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/get.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/insert.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/remove.hxx +2 -0
- data/ext/couchbase/couchbase/subdoc/replace.hxx +3 -1
- data/ext/couchbase/couchbase/subdoc/upsert.hxx +2 -0
- data/ext/couchbase/couchbase/transaction_op_error_context.hxx +4 -4
- data/ext/couchbase/couchbase/transactions/attempt_context.hxx +1 -1
- data/ext/couchbase/couchbase/transactions/transaction_get_result.hxx +36 -51
- data/ext/couchbase/couchbase/transactions/transactions_config.hxx +1 -1
- data/ext/couchbase/test/CMakeLists.txt +3 -2
- data/ext/couchbase/test/test_helper.hxx +1 -1
- data/ext/couchbase/test/test_integration_analytics.cxx +289 -13
- data/ext/couchbase/test/test_integration_crud.cxx +8 -1
- data/ext/couchbase/test/test_integration_examples.cxx +182 -0
- data/ext/couchbase/test/test_integration_management.cxx +15 -3
- data/ext/couchbase/test/test_integration_search.cxx +601 -0
- data/ext/couchbase/test/test_transaction_transaction_simple.cxx +73 -0
- data/ext/couchbase/test/test_unit_config_profiles.cxx +12 -12
- data/ext/couchbase/test/test_unit_connection_string.cxx +35 -0
- data/ext/couchbase/test/test_unit_transaction_utils.cxx +76 -19
- data/ext/couchbase/third_party/snappy/CMakeLists.txt +150 -27
- data/ext/couchbase/third_party/snappy/cmake/config.h.in +28 -24
- data/ext/couchbase/third_party/snappy/snappy-internal.h +189 -25
- data/ext/couchbase/third_party/snappy/snappy-sinksource.cc +26 -9
- data/ext/couchbase/third_party/snappy/snappy-sinksource.h +11 -11
- data/ext/couchbase/third_party/snappy/snappy-stubs-internal.cc +1 -1
- data/ext/couchbase/third_party/snappy/snappy-stubs-internal.h +227 -308
- data/ext/couchbase/third_party/snappy/snappy-stubs-public.h.in +0 -11
- data/ext/couchbase/third_party/snappy/snappy.cc +1176 -410
- data/ext/couchbase/third_party/snappy/snappy.h +19 -4
- data/ext/couchbase.cxx +506 -26
- data/ext/extconf.rb +2 -1
- data/ext/revisions.rb +3 -2
- data/lib/couchbase/binary_collection.rb +4 -4
- data/lib/couchbase/cluster.rb +13 -9
- data/lib/couchbase/cluster_registry.rb +7 -2
- data/lib/couchbase/collection.rb +5 -0
- data/lib/couchbase/configuration.rb +3 -4
- data/lib/couchbase/errors.rb +10 -0
- data/lib/couchbase/management/collection_query_index_manager.rb +183 -0
- data/lib/couchbase/management/query_index_manager.rb +35 -3
- data/lib/couchbase/management.rb +1 -0
- data/lib/couchbase/options.rb +87 -5
- data/lib/couchbase/search_options.rb +158 -240
- data/lib/couchbase/version.rb +1 -1
- metadata +21 -6
- data/ext/couchbase/core/CMakeLists.txt +0 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
#include <couchbase/analytics_error_context.hxx>
|
|
21
|
+
#include <couchbase/analytics_result.hxx>
|
|
22
|
+
#include <couchbase/analytics_scan_consistency.hxx>
|
|
23
|
+
#include <couchbase/codec/tao_json_serializer.hxx>
|
|
24
|
+
#include <couchbase/common_options.hxx>
|
|
25
|
+
#include <couchbase/mutation_state.hxx>
|
|
26
|
+
|
|
27
|
+
#include <chrono>
|
|
28
|
+
#include <functional>
|
|
29
|
+
#include <memory>
|
|
30
|
+
#include <optional>
|
|
31
|
+
|
|
32
|
+
namespace couchbase
|
|
33
|
+
{
|
|
34
|
+
/**
|
|
35
|
+
* Options for cluster#analytics_query() and scope#analytics_query().
|
|
36
|
+
*
|
|
37
|
+
* @since 1.0.0
|
|
38
|
+
* @committed
|
|
39
|
+
*/
|
|
40
|
+
struct analytics_options : public common_options<analytics_options> {
|
|
41
|
+
/**
|
|
42
|
+
* Immutable value object representing consistent options.
|
|
43
|
+
*
|
|
44
|
+
* @since 1.0.0
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
struct built : public common_options<analytics_options>::built {
|
|
48
|
+
std::optional<std::string> client_context_id;
|
|
49
|
+
const bool priority;
|
|
50
|
+
const bool readonly;
|
|
51
|
+
std::optional<analytics_scan_consistency> scan_consistency;
|
|
52
|
+
std::optional<std::chrono::milliseconds> scan_wait;
|
|
53
|
+
std::vector<mutation_token> mutation_state;
|
|
54
|
+
std::vector<codec::binary> positional_parameters;
|
|
55
|
+
std::map<std::string, codec::binary, std::less<>> named_parameters;
|
|
56
|
+
std::map<std::string, codec::binary, std::less<>> raw;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Validates options and returns them as an immutable value.
|
|
61
|
+
*
|
|
62
|
+
* @return consistent options as an immutable value
|
|
63
|
+
*
|
|
64
|
+
* @exception std::system_error with code errc::common::invalid_argument if the options are not valid
|
|
65
|
+
*
|
|
66
|
+
* @since 1.0.0
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
[[nodiscard]] auto build() const -> built
|
|
70
|
+
{
|
|
71
|
+
return {
|
|
72
|
+
build_common_options(), client_context_id_, priority_, readonly_, scan_consistency_, scan_wait_,
|
|
73
|
+
mutation_state_, positional_parameters_, named_parameters_, raw_,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Allows to give certain requests higher priority than others.
|
|
79
|
+
*
|
|
80
|
+
* @param prioritized if set to true this query will be treated with a higher priority by the service.
|
|
81
|
+
* @return this options builder for chaining purposes.
|
|
82
|
+
*
|
|
83
|
+
* @since 1.0.0
|
|
84
|
+
* @committed
|
|
85
|
+
*/
|
|
86
|
+
auto priority(bool prioritized) -> analytics_options&
|
|
87
|
+
{
|
|
88
|
+
priority_ = prioritized;
|
|
89
|
+
return self();
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Allows explicitly marking a query as being readonly and not mutating and documents on the server side.
|
|
94
|
+
*
|
|
95
|
+
* In addition to providing some security in that you are not accidentally modifying data, setting this flag to true also helps the
|
|
96
|
+
* client to more proactively retry and re-dispatch a query since then it can be sure it is idempotent. As a result, if your query is
|
|
97
|
+
* readonly then it is a good idea to set this flag.
|
|
98
|
+
*
|
|
99
|
+
* @param readonly true if readonly should be set, false is the default and will use the server side default.
|
|
100
|
+
* @return this options builder for chaining purposes.
|
|
101
|
+
*
|
|
102
|
+
* @since 1.0.0
|
|
103
|
+
* @committed
|
|
104
|
+
*/
|
|
105
|
+
auto readonly(bool readonly) -> analytics_options&
|
|
106
|
+
{
|
|
107
|
+
readonly_ = readonly;
|
|
108
|
+
return self();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Allows customizing how long the query engine is willing to wait until the index catches up to whatever scan
|
|
113
|
+
* consistency is asked for in this query.
|
|
114
|
+
*
|
|
115
|
+
* @note that if {@link analytics_scan_consistency::not_bounded} is used, this method doesn't do anything at all. If no value is
|
|
116
|
+
* provided to this method, the server default is used.
|
|
117
|
+
*
|
|
118
|
+
* @param wait the maximum duration the query engine is willing to wait before failing.
|
|
119
|
+
* @return this options builder for chaining purposes.
|
|
120
|
+
*
|
|
121
|
+
* @since 1.0.0
|
|
122
|
+
* @committed
|
|
123
|
+
*/
|
|
124
|
+
auto scan_wait(std::chrono::milliseconds wait) -> analytics_options&
|
|
125
|
+
{
|
|
126
|
+
if (scan_consistency_ == analytics_scan_consistency::not_bounded) {
|
|
127
|
+
scan_wait_.reset();
|
|
128
|
+
} else {
|
|
129
|
+
scan_wait_ = wait;
|
|
130
|
+
}
|
|
131
|
+
return self();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Supports providing a custom client context ID for this query.
|
|
136
|
+
*
|
|
137
|
+
* If no client context ID is provided by the user, a UUID is generated and sent automatically so by default it is always possible to
|
|
138
|
+
* identify a query when debugging.
|
|
139
|
+
*
|
|
140
|
+
* @param client_context_id the client context ID
|
|
141
|
+
* @return this options builder for chaining purposes.
|
|
142
|
+
*
|
|
143
|
+
* @since 1.0.0
|
|
144
|
+
* @committed
|
|
145
|
+
*/
|
|
146
|
+
auto client_context_id(std::string client_context_id) -> analytics_options&
|
|
147
|
+
{
|
|
148
|
+
if (client_context_id.empty()) {
|
|
149
|
+
client_context_id_.reset();
|
|
150
|
+
} else {
|
|
151
|
+
client_context_id_ = std::move(client_context_id);
|
|
152
|
+
}
|
|
153
|
+
return self();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Customizes the consistency guarantees for this query.
|
|
158
|
+
*
|
|
159
|
+
* Tuning the scan consistency allows to trade data "freshness" for latency and vice versa. By default
|
|
160
|
+
* {@link analytics_scan_consistency::not_bounded} is used, which means that the server returns the data it has in the index right away.
|
|
161
|
+
* This is fast, but might not include the most recent mutations. If you want to include all the mutations up to the point of the query,
|
|
162
|
+
* use {@link analytics_scan_consistency::request_plus}.
|
|
163
|
+
*
|
|
164
|
+
* Note that you cannot use this method and {@link #consistent_with(const mutation_state&)} at the same time, since they are mutually
|
|
165
|
+
* exclusive. As a rule of thumb, if you only care to be consistent with the mutation you just wrote on the same thread/app, use
|
|
166
|
+
* {@link #consistent_with(const mutation_state&)}. If you need "global" scan consistency, use
|
|
167
|
+
* {@link analytics_scan_consistency::request_plus} on this method.
|
|
168
|
+
*
|
|
169
|
+
* @param scan_consistency the index scan consistency to be used for this query
|
|
170
|
+
* @return this options builder for chaining purposes.
|
|
171
|
+
*
|
|
172
|
+
* @since 1.0.0
|
|
173
|
+
* @committed
|
|
174
|
+
*/
|
|
175
|
+
auto scan_consistency(analytics_scan_consistency scan_consistency) -> analytics_options&
|
|
176
|
+
{
|
|
177
|
+
scan_consistency_ = scan_consistency;
|
|
178
|
+
mutation_state_.clear();
|
|
179
|
+
return self();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Sets the {@link mutation_token}s this query should be consistent with.
|
|
184
|
+
*
|
|
185
|
+
* These mutation tokens are returned from mutations (i.e. as part of a {@link mutation_result}) and if you want your
|
|
186
|
+
* N1QL query to include those you need to pass the mutation tokens into a {@link mutation_state}.
|
|
187
|
+
*
|
|
188
|
+
* Note that you cannot use this method and {@link #scan_consistency(analytics_scan_consistency)} at the same time, since
|
|
189
|
+
* they are mutually exclusive. As a rule of thumb, if you only care to be consistent with the mutation you just wrote
|
|
190
|
+
* on the same thread/app, use this method. If you need "global" scan consistency, use
|
|
191
|
+
* {@link analytics_scan_consistency#request_plus} on {@link #scan_consistency(analytics_scan_consistency)}.
|
|
192
|
+
*
|
|
193
|
+
* @param state the mutation state containing the mutation tokens.
|
|
194
|
+
* @return this options builder for chaining purposes.
|
|
195
|
+
*
|
|
196
|
+
* @since 1.0.0
|
|
197
|
+
* @committed
|
|
198
|
+
*/
|
|
199
|
+
auto consistent_with(const mutation_state& state) -> analytics_options&
|
|
200
|
+
{
|
|
201
|
+
mutation_state_ = state.tokens();
|
|
202
|
+
scan_consistency_.reset();
|
|
203
|
+
return self();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
* @tparam Value
|
|
209
|
+
* @param name
|
|
210
|
+
* @param value
|
|
211
|
+
* @return this options builder for chaining purposes.
|
|
212
|
+
*
|
|
213
|
+
* @since 1.0.0
|
|
214
|
+
* @committed
|
|
215
|
+
*/
|
|
216
|
+
template<typename Value>
|
|
217
|
+
auto raw(std::string name, const Value& value) -> analytics_options&
|
|
218
|
+
{
|
|
219
|
+
raw_[std::move(name)] = std::move(codec::tao_json_serializer::serialize(value));
|
|
220
|
+
return self();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Set list of positional parameters for a query.
|
|
225
|
+
*
|
|
226
|
+
* @tparam Parameters types for the parameters
|
|
227
|
+
* @param parameters the sequence of positional parameters. Each entry will be encoded into JSON.
|
|
228
|
+
* @return this options builder for chaining purposes.
|
|
229
|
+
*
|
|
230
|
+
* @since 1.0.0
|
|
231
|
+
* @committed
|
|
232
|
+
*/
|
|
233
|
+
template<typename... Parameters>
|
|
234
|
+
auto positional_parameters(const Parameters&... parameters) -> analytics_options&
|
|
235
|
+
{
|
|
236
|
+
named_parameters_.clear();
|
|
237
|
+
positional_parameters_.clear();
|
|
238
|
+
encode_positional_parameters(parameters...);
|
|
239
|
+
return self();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Set list of named parameters for a query.
|
|
244
|
+
*
|
|
245
|
+
* @tparam Parameters types for the parameter pairs
|
|
246
|
+
* @param parameters the sequence of name-value pairs. Each value will be encoded into JSON.
|
|
247
|
+
* @return this options builder for chaining purposes.
|
|
248
|
+
*
|
|
249
|
+
* @since 1.0.0
|
|
250
|
+
* @committed
|
|
251
|
+
*/
|
|
252
|
+
template<typename... Parameters>
|
|
253
|
+
auto named_parameters(const Parameters&... parameters) -> analytics_options&
|
|
254
|
+
{
|
|
255
|
+
named_parameters_.clear();
|
|
256
|
+
positional_parameters_.clear();
|
|
257
|
+
encode_named_parameters(parameters...);
|
|
258
|
+
return self();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Set map of raw options for a query.
|
|
263
|
+
*
|
|
264
|
+
* This function expects that all parameters encoded into pairs containing mapping names of the parameter to valid JSON values encoded
|
|
265
|
+
* as string.
|
|
266
|
+
*
|
|
267
|
+
* @note This function is low-level, and instead @ref raw() should be considered.
|
|
268
|
+
*
|
|
269
|
+
* @param options mapping of pairs, where each entry contains string with valid JSON value.
|
|
270
|
+
* @return this options builder for chaining purposes.
|
|
271
|
+
*
|
|
272
|
+
* @since 1.0.0
|
|
273
|
+
* @uncommitted
|
|
274
|
+
*/
|
|
275
|
+
auto encoded_raw_options(std::map<std::string, codec::binary, std::less<>> options) -> analytics_options&
|
|
276
|
+
{
|
|
277
|
+
raw_ = std::move(options);
|
|
278
|
+
return self();
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Set list of positional parameters for a query.
|
|
283
|
+
*
|
|
284
|
+
* This function expects that all parameters encoded into byte strings containing valid JSON values.
|
|
285
|
+
*
|
|
286
|
+
* @note This function is low-level, and instead @ref positional_parameters() should be considered.
|
|
287
|
+
*
|
|
288
|
+
* @param parameters vector of binaries, where each entry contains string with valid JSON value.
|
|
289
|
+
* @return this options builder for chaining purposes.
|
|
290
|
+
*
|
|
291
|
+
* @since 1.0.0
|
|
292
|
+
* @uncommitted
|
|
293
|
+
*/
|
|
294
|
+
auto encoded_positional_parameters(std::vector<codec::binary> parameters) -> analytics_options&
|
|
295
|
+
{
|
|
296
|
+
named_parameters_.clear();
|
|
297
|
+
positional_parameters_ = std::move(parameters);
|
|
298
|
+
return self();
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Set map of named parameters for a query.
|
|
303
|
+
*
|
|
304
|
+
* This function expects that all parameters encoded into pairs containing mapping names of the parameter to valid JSON values encoded
|
|
305
|
+
* as string.
|
|
306
|
+
*
|
|
307
|
+
* @note This function is low-level, and instead @ref named_parameters() should be considered.
|
|
308
|
+
*
|
|
309
|
+
* @param parameters mapping of pairs, where each entry contains string with valid JSON value.
|
|
310
|
+
* @return this options builder for chaining purposes.
|
|
311
|
+
*
|
|
312
|
+
* @since 1.0.0
|
|
313
|
+
* @uncommitted
|
|
314
|
+
*/
|
|
315
|
+
auto encoded_named_parameters(std::map<std::string, codec::binary, std::less<>> parameters) -> analytics_options&
|
|
316
|
+
{
|
|
317
|
+
named_parameters_ = std::move(parameters);
|
|
318
|
+
positional_parameters_.clear();
|
|
319
|
+
return self();
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
private:
|
|
323
|
+
template<typename Parameter, typename... Rest>
|
|
324
|
+
void encode_positional_parameters(const Parameter& parameter, Rest... args)
|
|
325
|
+
{
|
|
326
|
+
positional_parameters_.emplace_back(std::move(codec::tao_json_serializer::serialize(parameter)));
|
|
327
|
+
if constexpr (sizeof...(args) > 0) {
|
|
328
|
+
encode_positional_parameters(args...);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
template<typename Name, typename Parameter, typename... Rest>
|
|
333
|
+
void encode_named_parameters(const std::pair<Name, Parameter>& parameter, Rest... args)
|
|
334
|
+
{
|
|
335
|
+
named_parameters_[parameter.first] = std::move(codec::tao_json_serializer::serialize(parameter.second));
|
|
336
|
+
if constexpr (sizeof...(args) > 0) {
|
|
337
|
+
encode_named_parameters(args...);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
bool priority_{ true };
|
|
342
|
+
bool readonly_{ false };
|
|
343
|
+
std::optional<std::string> client_context_id_{};
|
|
344
|
+
std::optional<std::chrono::milliseconds> scan_wait_{};
|
|
345
|
+
std::optional<analytics_scan_consistency> scan_consistency_{};
|
|
346
|
+
std::vector<mutation_token> mutation_state_{};
|
|
347
|
+
std::vector<codec::binary> positional_parameters_{};
|
|
348
|
+
std::map<std::string, codec::binary, std::less<>> raw_{};
|
|
349
|
+
std::map<std::string, codec::binary, std::less<>> named_parameters_{};
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* The signature for the handler of the @ref cluster#analytics_query() and @ref scope#analytics_query() operations
|
|
354
|
+
*
|
|
355
|
+
* @since 1.0.0
|
|
356
|
+
* @uncommitted
|
|
357
|
+
*/
|
|
358
|
+
using analytics_handler = std::function<void(couchbase::analytics_error_context, analytics_result)>;
|
|
359
|
+
} // namespace couchbase
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
#include <couchbase/analytics_meta_data.hxx>
|
|
21
|
+
#include <couchbase/codec/tao_json_serializer.hxx>
|
|
22
|
+
|
|
23
|
+
#include <chrono>
|
|
24
|
+
#include <cinttypes>
|
|
25
|
+
#include <optional>
|
|
26
|
+
#include <vector>
|
|
27
|
+
|
|
28
|
+
namespace couchbase
|
|
29
|
+
{
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Represents result of @ref cluster#analytics_query() and @ref scope#analytics_query() calls.
|
|
33
|
+
*
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
* @committed
|
|
36
|
+
*/
|
|
37
|
+
class analytics_result
|
|
38
|
+
{
|
|
39
|
+
public:
|
|
40
|
+
/**
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
analytics_result() = default;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @since 1.0.0
|
|
48
|
+
* @volatile
|
|
49
|
+
*/
|
|
50
|
+
analytics_result(analytics_meta_data meta_data, std::vector<codec::binary> rows)
|
|
51
|
+
: meta_data_{ std::move(meta_data) }
|
|
52
|
+
, rows_{ std::move(rows) }
|
|
53
|
+
{
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Returns the {@link analytics_meta_data} giving access to the additional metadata associated with this analytics query.
|
|
58
|
+
*
|
|
59
|
+
* @return response metadata
|
|
60
|
+
*
|
|
61
|
+
* @since 1.0.0
|
|
62
|
+
* @committed
|
|
63
|
+
*/
|
|
64
|
+
[[nodiscard]] auto meta_data() const -> const analytics_meta_data&
|
|
65
|
+
{
|
|
66
|
+
return meta_data_;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @return list of analytics results as binary strings
|
|
71
|
+
*
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
[[nodiscard]] auto rows_as_binary() const -> const std::vector<codec::binary>&
|
|
76
|
+
{
|
|
77
|
+
return rows_;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
template<typename Serializer,
|
|
81
|
+
typename Document = typename Serializer::document_type,
|
|
82
|
+
std::enable_if_t<codec::is_serializer_v<Serializer>, bool> = true>
|
|
83
|
+
[[nodiscard]] auto rows_as() const -> std::vector<Document>
|
|
84
|
+
{
|
|
85
|
+
std::vector<Document> rows;
|
|
86
|
+
rows.reserve(rows_.size());
|
|
87
|
+
for (const auto& row : rows_) {
|
|
88
|
+
rows.emplace_back(Serializer::template deserialize<Document>(row));
|
|
89
|
+
}
|
|
90
|
+
return rows;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
[[nodiscard]] auto rows_as_json() const -> std::vector<codec::tao_json_serializer::document_type>
|
|
94
|
+
{
|
|
95
|
+
return rows_as<codec::tao_json_serializer>();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private:
|
|
99
|
+
analytics_meta_data meta_data_{};
|
|
100
|
+
std::vector<codec::binary> rows_{};
|
|
101
|
+
};
|
|
102
|
+
} // namespace couchbase
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
namespace couchbase
|
|
21
|
+
{
|
|
22
|
+
enum class analytics_scan_consistency {
|
|
23
|
+
/**
|
|
24
|
+
* The indexer will return whatever state it has to the query engine at the time of query.
|
|
25
|
+
*
|
|
26
|
+
* This is the default (for single-statement requests). No timestamp vector is used in the index scan. This is also the fastest mode,
|
|
27
|
+
* because we avoid the cost of obtaining the vector, and we also avoid any wait for the index to catch up to the vector.
|
|
28
|
+
*
|
|
29
|
+
* @since 1.0.0
|
|
30
|
+
* @committed
|
|
31
|
+
*/
|
|
32
|
+
not_bounded = 0,
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The indexer will wait until all mutations have been processed at the time of request before returning to the query engine.
|
|
36
|
+
*
|
|
37
|
+
* This implements strong consistency per request. Before processing the request, a current vector is obtained. The vector is used as a
|
|
38
|
+
* lower bound for the statements in the request. If there are DML statements in the request, RYOW ("read your own write") is also
|
|
39
|
+
* applied within the request.
|
|
40
|
+
*
|
|
41
|
+
* @since 1.0.0
|
|
42
|
+
* @committed
|
|
43
|
+
*/
|
|
44
|
+
request_plus,
|
|
45
|
+
};
|
|
46
|
+
} // namespace couchbase
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
namespace couchbase
|
|
21
|
+
{
|
|
22
|
+
/**
|
|
23
|
+
* Status of the Analytics Query
|
|
24
|
+
*
|
|
25
|
+
* @since 1.0.0
|
|
26
|
+
* @committed
|
|
27
|
+
*/
|
|
28
|
+
enum class analytics_status {
|
|
29
|
+
running,
|
|
30
|
+
success,
|
|
31
|
+
errors,
|
|
32
|
+
completed,
|
|
33
|
+
stopped,
|
|
34
|
+
timeout,
|
|
35
|
+
closed,
|
|
36
|
+
fatal,
|
|
37
|
+
aborted,
|
|
38
|
+
unknown,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
} // namespace couchbase
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2020-Present Couchbase, Inc.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#pragma once
|
|
19
|
+
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
#include <optional>
|
|
22
|
+
#include <string>
|
|
23
|
+
|
|
24
|
+
namespace couchbase
|
|
25
|
+
{
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Represents a single warning returned from the analytics engine.
|
|
29
|
+
*
|
|
30
|
+
* @note warnings are not terminal errors but hints from the engine that something was not as expected.
|
|
31
|
+
*
|
|
32
|
+
* @since 1.0.0
|
|
33
|
+
* @committed
|
|
34
|
+
*/
|
|
35
|
+
class analytics_warning
|
|
36
|
+
{
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* @since 1.0.0
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
analytics_warning() = default;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @since 1.0.0
|
|
46
|
+
* @volatile
|
|
47
|
+
*/
|
|
48
|
+
analytics_warning(std::uint64_t code, std::string message)
|
|
49
|
+
: code_{ code }
|
|
50
|
+
, message_{ std::move(message) }
|
|
51
|
+
{
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Error code.
|
|
56
|
+
*
|
|
57
|
+
* @return error code
|
|
58
|
+
*
|
|
59
|
+
* @since 1.0.0
|
|
60
|
+
* @committed
|
|
61
|
+
*/
|
|
62
|
+
[[nodiscard]] auto code() const -> std::uint64_t
|
|
63
|
+
{
|
|
64
|
+
return code_;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Error message.
|
|
69
|
+
*
|
|
70
|
+
* @return human readable explanation
|
|
71
|
+
*
|
|
72
|
+
* @since 1.0.0
|
|
73
|
+
* @committed
|
|
74
|
+
*/
|
|
75
|
+
[[nodiscard]] auto message() const -> const std::string&
|
|
76
|
+
{
|
|
77
|
+
return message_;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private:
|
|
81
|
+
std::uint64_t code_{};
|
|
82
|
+
std::string message_{};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace couchbase
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
#pragma once
|
|
19
19
|
|
|
20
|
+
#include <couchbase/analytics_options.hxx>
|
|
20
21
|
#include <couchbase/bucket.hxx>
|
|
21
22
|
#include <couchbase/cluster_options.hxx>
|
|
22
23
|
#include <couchbase/query_index_manager.hxx>
|
|
@@ -59,7 +60,7 @@ class cluster
|
|
|
59
60
|
* @param handler the handler that implements @ref cluster_connect_handler
|
|
60
61
|
*
|
|
61
62
|
* @since 1.0.0
|
|
62
|
-
* @
|
|
63
|
+
* @committed
|
|
63
64
|
*/
|
|
64
65
|
template<typename Handler>
|
|
65
66
|
static void connect(asio::io_context& io, const std::string& connection_string, const cluster_options& options, Handler&& handler)
|
|
@@ -77,7 +78,7 @@ class cluster
|
|
|
77
78
|
* @return future object that carries cluster object and operation status
|
|
78
79
|
*
|
|
79
80
|
* @since 1.0.0
|
|
80
|
-
* @
|
|
81
|
+
* @committed
|
|
81
82
|
*/
|
|
82
83
|
[[nodiscard]] static auto connect(asio::io_context& io, const std::string& connection_string, const cluster_options& options)
|
|
83
84
|
-> std::future<std::pair<cluster, std::error_code>>
|
|
@@ -165,6 +166,38 @@ class cluster
|
|
|
165
166
|
return future;
|
|
166
167
|
}
|
|
167
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Performs a query against the analytics services.
|
|
171
|
+
*
|
|
172
|
+
* @param statement the query statement.
|
|
173
|
+
* @param options options to customize the query request.
|
|
174
|
+
* @param handler the handler that implements @ref query_handler
|
|
175
|
+
*
|
|
176
|
+
* @exception errc::common::ambiguous_timeout
|
|
177
|
+
* @exception errc::common::unambiguous_timeout
|
|
178
|
+
*
|
|
179
|
+
* @see https://docs.couchbase.com/server/current/analytics/introduction.html
|
|
180
|
+
*
|
|
181
|
+
* @since 1.0.0
|
|
182
|
+
* @committed
|
|
183
|
+
*/
|
|
184
|
+
void analytics_query(std::string statement, const analytics_options& options, analytics_handler&& handler) const;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Performs a query against the analytics services.
|
|
188
|
+
*
|
|
189
|
+
* @param statement the query statement.
|
|
190
|
+
* @param options options to customize the query request.
|
|
191
|
+
* @return future object that carries result of the operation
|
|
192
|
+
*
|
|
193
|
+
* @see https://docs.couchbase.com/server/current/analytics/introduction.html
|
|
194
|
+
*
|
|
195
|
+
* @since 1.0.0
|
|
196
|
+
* @committed
|
|
197
|
+
*/
|
|
198
|
+
[[nodiscard]] auto analytics_query(std::string statement, const analytics_options& options = {}) const
|
|
199
|
+
-> std::future<std::pair<analytics_error_context, analytics_result>>;
|
|
200
|
+
|
|
168
201
|
/**
|
|
169
202
|
* Provides access to the N1QL index management services.
|
|
170
203
|
*
|