Skip to content

Commit e3be8b0

Browse files
davidkellyavsej
andauthored
CXXCBC-275 Update query_context handling in query management calls (#337)
* CXXCBC-275 Update query_context handling in query management calls The decision is to always send a query_context, and live with the errors we see from 6.x and earlier for the management calls. We could follow up with an option that allowed to user to specify this isn't put in the calls, if really needed. * update to use scope::default_name, namespace_id Co-authored-by: Sergey Avseyev <[email protected]>
1 parent bf039d8 commit e3be8b0

File tree

7 files changed

+33
-46
lines changed

7 files changed

+33
-46
lines changed

core/operations/document_query.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,14 @@ query_request::encode_to(query_request::encoded_request_type& encoded, http_cont
137137
if (check_scan_wait && scan_wait) {
138138
body["scan_wait"] = fmt::format("{}ms", scan_wait.value().count());
139139
}
140+
140141
if (scope_qualifier) {
141142
body["query_context"] = scope_qualifier;
142-
} else if (scope_name) {
143-
if (bucket_name) {
143+
} else if (bucket_name) {
144+
if (scope_name) {
144145
body["query_context"] = fmt::format("default:`{}`.`{}`", *bucket_name, *scope_name);
146+
} else {
147+
body["query_context"] = fmt::format("default:`{}`", *bucket_name);
145148
}
146149
}
147150
for (const auto& [name, value] : raw) {

core/operations/management/query_index_build.cxx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,13 @@ query_index_build_request::encode_to(encoded_request_type& encoded, http_context
5454
R"(BUILD INDEX ON `{}`.`{}`.`{}` ({}))", bucket_name, scope_name, collection_name, quote_and_join_strings(index_names, ","));
5555
query_context += ".`" + scope_name + "`";
5656
} else {
57-
statement = fmt::format(R"(BUILD INDEX ON `{}` ({}))", bucket_name, quote_and_join_strings(index_names, ","));
58-
query_context += ".`_default`";
57+
statement = fmt::format(R"(BUILD INDEX ON {} ({}))", query_context, quote_and_join_strings(index_names, ","));
58+
query_context += fmt::format(".`{}`", couchbase::scope::default_name);
5959
}
6060
encoded.headers["content-type"] = "application/json";
61-
tao::json::value body{ { "statement", statement }, { "client_context_id", encoded.client_context_id } };
62-
if (!scope_name.empty() || !collection_name.empty()) {
63-
body["query_context"] = query_context;
64-
}
61+
tao::json::value body{ { "statement", statement },
62+
{ "client_context_id", encoded.client_context_id },
63+
{ "query_context", query_context } };
6564
encoded.method = "POST";
6665
encoded.path = "/query/service";
6766
encoded.body = utils::json::generate(body);

core/operations/management/query_index_create.cxx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,13 @@ query_index_create_request::encode_to(encoded_request_type& encoded, http_contex
4646
with_clause = fmt::format("WITH {}", utils::json::generate(with));
4747
}
4848
std::string keyspace = fmt::format("{}:`{}`", namespace_id, bucket_name);
49-
std::string query_context = keyspace;
49+
auto query_context = keyspace;
5050
if (!scope_name.empty()) {
5151
keyspace += ".`" + scope_name + "`";
5252
query_context += ".`" + scope_name + "`";
5353
} else {
54-
query_context += ".`_default`";
54+
query_context += fmt::format(".`{}`", couchbase::scope::default_name);
5555
}
56-
5756
if (!collection_name.empty()) {
5857
keyspace += ".`" + collection_name + "`";
5958
}
@@ -68,10 +67,8 @@ query_index_create_request::encode_to(encoded_request_type& encoded, http_contex
6867
utils::join_strings(fields, ", "),
6968
where_clause,
7069
with_clause) },
71-
{ "client_context_id", encoded.client_context_id } };
72-
if (!scope_name.empty() || !collection_name.empty()) {
73-
body["query_context"] = query_context;
74-
}
70+
{ "client_context_id", encoded.client_context_id },
71+
{ "query_context", query_context } };
7572
encoded.method = "POST";
7673
encoded.path = "/query/service";
7774
encoded.body = utils::json::generate(body);

core/operations/management/query_index_drop.cxx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,27 @@ query_index_drop_request::encode_to(encoded_request_type& encoded, http_context&
2929
return errc::common::invalid_argument;
3030
}
3131
encoded.headers["content-type"] = "application/json";
32-
std::string keyspace = fmt::format("`{}`", bucket_name);
33-
std::string query_context = keyspace;
32+
std::string query_context = fmt::format("{}:`{}`", namespace_id, bucket_name);
33+
auto keyspace = query_context;
3434
if (!scope_name.empty()) {
35-
keyspace += ".`" + scope_name + "`";
3635
query_context += ".`" + scope_name + "`";
36+
keyspace += ".`" + scope_name + "`";
3737
} else {
38-
query_context += ".`_default`";
38+
query_context += fmt::format(".`{}`", couchbase::scope::default_name);
3939
}
4040
if (!collection_name.empty()) {
4141
keyspace += ".`" + collection_name + "`";
4242
}
43-
4443
std::string drop_index_stmt;
4544
if (is_primary && index_name.empty()) {
4645
drop_index_stmt = fmt::format(R"(DROP PRIMARY INDEX ON {} USING GSI)", keyspace);
47-
} else if (!scope_name.empty() || !collection_name.empty()) {
48-
drop_index_stmt = fmt::format(R"(DROP INDEX `{}` ON {} USING GSI)", index_name, keyspace);
4946
} else {
50-
drop_index_stmt = fmt::format(R"(DROP INDEX {}.`{}` USING GSI)", keyspace, index_name);
47+
drop_index_stmt = fmt::format(R"(DROP INDEX `{}` ON {} USING GSI)", index_name, keyspace);
5148
}
5249

53-
tao::json::value body{ { "statement", drop_index_stmt }, { "client_context_id", encoded.client_context_id } };
54-
if (!scope_name.empty() || !collection_name.empty()) {
55-
body["query_context"] = query_context;
56-
}
50+
tao::json::value body{ { "statement", drop_index_stmt },
51+
{ "client_context_id", encoded.client_context_id },
52+
{ "query_context", query_context } };
5753
encoded.method = "POST";
5854
encoded.path = "/query/service";
5955
encoded.body = utils::json::generate(body);

core/operations/management/query_index_get_all.cxx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ query_index_get_all_request::encode_to(encoded_request_type& encoded, couchbase:
3939
}
4040

4141
std::string query_context = fmt::format("{}:`{}`", namespace_id, bucket_name);
42-
if (scope_name.empty()) {
43-
query_context += ".`_default`";
44-
} else {
42+
if (!scope_name.empty()) {
4543
query_context += ".`" + scope_name + "`";
44+
} else {
45+
query_context += fmt::format(".`{}`", couchbase::scope::default_name);
4646
}
4747

4848
if (collection_name == "_default" || collection_name.empty()) {
@@ -61,10 +61,8 @@ query_index_get_all_request::encode_to(encoded_request_type& encoded, couchbase:
6161
{ "client_context_id", encoded.client_context_id },
6262
{ "$bucket_name", bucket_name },
6363
{ "$scope_name", scope_name },
64-
{ "$collection_name", collection_name } };
65-
if (!scope_name.empty() || !collection_name.empty()) {
66-
body["query_context"] = query_context;
67-
}
64+
{ "$collection_name", collection_name },
65+
{ "query_context", query_context } };
6866
encoded.method = "POST";
6967
encoded.path = "/query/service";
7068
encoded.body = utils::json::generate(body);

core/operations/management/query_index_get_all_deferred.cxx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ query_index_get_all_deferred_request::encode_to(encoded_request_type& encoded, c
3333
}
3434

3535
std::string query_context = fmt::format("{}:`{}`", namespace_id, bucket_name);
36-
if (scope_name.empty()) {
37-
query_context += ".`_default`";
38-
} else {
36+
if (!scope_name.empty()) {
3937
query_context += ".`" + scope_name + "`";
38+
} else {
39+
query_context += fmt::format(".`{}`", couchbase::scope::default_name);
4040
}
4141

4242
std::string statement = "SELECT RAW name FROM system:indexes"
@@ -50,10 +50,8 @@ query_index_get_all_deferred_request::encode_to(encoded_request_type& encoded, c
5050
{ "client_context_id", encoded.client_context_id },
5151
{ "$bucket_name", bucket_name },
5252
{ "$scope_name", scope_name },
53-
{ "$collection_name", collection_name } };
54-
if (!scope_name.empty() || !collection_name.empty()) {
55-
body["query_context"] = query_context;
56-
}
53+
{ "$collection_name", collection_name },
54+
{ "query_context", query_context } };
5755
encoded.method = "POST";
5856
encoded.path = "/query/service";
5957
encoded.body = utils::json::generate(body);

test/test_integration_management.cxx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ TEST_CASE("integration: query index management", "[integration]")
967967
{
968968
test::utils::integration_test_guard integration;
969969

970-
if (!integration.cluster_version().supports_query_index_management()) {
970+
if (!integration.cluster_version().supports_collections()) {
971971
return;
972972
}
973973

@@ -1177,10 +1177,6 @@ TEST_CASE("integration: collections query index management", "[integration]")
11771177
{
11781178
test::utils::integration_test_guard integration;
11791179

1180-
if (!integration.cluster_version().supports_query_index_management()) {
1181-
return;
1182-
}
1183-
11841180
if (!integration.cluster_version().supports_collections()) {
11851181
return;
11861182
}

0 commit comments

Comments
 (0)