Skip to content

Update C++ core #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/couchbase
30 changes: 15 additions & 15 deletions ext/couchbase.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4143,7 +4143,7 @@ cb_Backend_document_scan_create(VALUE self, VALUE bucket, VALUE scope, VALUE col
rb_raise(eCouchbaseError, "Cannot perform scan operation. Unable to get bucket configuration");
return Qnil;
}
if (!config->supports_range_scan()) {
if (!config->capabilities.supports_range_scan()) {
rb_raise(eFeatureNotAvailable, "Server does not support key-value scan operations");
return Qnil;
}
Expand Down Expand Up @@ -5841,13 +5841,13 @@ cb_Backend_query_index_get_all(VALUE self, VALUE bucket_name, VALUE options)
}

static VALUE
cb_Backend_query_index_create(VALUE self, VALUE bucket_name, VALUE index_name, VALUE fields, VALUE options)
cb_Backend_query_index_create(VALUE self, VALUE bucket_name, VALUE index_name, VALUE keys, VALUE options)
{
const auto& cluster = cb_backend_to_cluster(self);

Check_Type(bucket_name, T_STRING);
Check_Type(index_name, T_STRING);
Check_Type(fields, T_ARRAY);
Check_Type(keys, T_ARRAY);
if (!NIL_P(options)) {
Check_Type(options, T_HASH);
}
Expand All @@ -5857,12 +5857,12 @@ cb_Backend_query_index_create(VALUE self, VALUE bucket_name, VALUE index_name, V
cb_extract_timeout(req, options);
req.bucket_name = cb_string_new(bucket_name);
req.index_name = cb_string_new(index_name);
auto fields_num = static_cast<std::size_t>(RARRAY_LEN(fields));
req.fields.reserve(fields_num);
for (std::size_t i = 0; i < fields_num; ++i) {
VALUE entry = rb_ary_entry(fields, static_cast<long>(i));
auto keys_num = static_cast<std::size_t>(RARRAY_LEN(keys));
req.keys.reserve(keys_num);
for (std::size_t i = 0; i < keys_num; ++i) {
VALUE entry = rb_ary_entry(keys, static_cast<long>(i));
cb_check_type(entry, T_STRING);
req.fields.emplace_back(RSTRING_PTR(entry), static_cast<std::size_t>(RSTRING_LEN(entry)));
req.keys.emplace_back(RSTRING_PTR(entry), static_cast<std::size_t>(RSTRING_LEN(entry)));
}
if (!NIL_P(options)) {
if (VALUE ignore_if_exists = rb_hash_aref(options, rb_id2sym(rb_intern("ignore_if_exists"))); ignore_if_exists == Qtrue) {
Expand Down Expand Up @@ -6292,7 +6292,7 @@ cb_Backend_collection_query_index_create(VALUE self,
VALUE scope_name,
VALUE collection_name,
VALUE index_name,
VALUE fields,
VALUE keys,
VALUE options)
{
const auto& cluster = cb_backend_to_cluster(self);
Expand All @@ -6301,7 +6301,7 @@ cb_Backend_collection_query_index_create(VALUE self,
Check_Type(scope_name, T_STRING);
Check_Type(collection_name, T_STRING);
Check_Type(index_name, T_STRING);
Check_Type(fields, T_ARRAY);
Check_Type(keys, T_ARRAY);
if (!NIL_P(options)) {
Check_Type(options, T_HASH);
}
Expand All @@ -6313,12 +6313,12 @@ cb_Backend_collection_query_index_create(VALUE self,
req.scope_name = cb_string_new(scope_name);
req.collection_name = cb_string_new(collection_name);
req.index_name = cb_string_new(index_name);
auto fields_num = static_cast<std::size_t>(RARRAY_LEN(fields));
req.fields.reserve(fields_num);
for (std::size_t i = 0; i < fields_num; ++i) {
VALUE entry = rb_ary_entry(fields, static_cast<long>(i));
auto keys_num = static_cast<std::size_t>(RARRAY_LEN(keys));
req.keys.reserve(keys_num);
for (std::size_t i = 0; i < keys_num; ++i) {
VALUE entry = rb_ary_entry(keys, static_cast<long>(i));
cb_check_type(entry, T_STRING);
req.fields.emplace_back(RSTRING_PTR(entry), static_cast<std::size_t>(RSTRING_LEN(entry)));
req.keys.emplace_back(RSTRING_PTR(entry), static_cast<std::size_t>(RSTRING_LEN(entry)));
}
if (!NIL_P(options)) {
if (VALUE ignore_if_exists = rb_hash_aref(options, rb_id2sym(rb_intern("ignore_if_exists"))); ignore_if_exists == Qtrue) {
Expand Down
8 changes: 8 additions & 0 deletions lib/couchbase/protostellar/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def query(statement, options = Couchbase::Options::Query::DEFAULT)
resps = @client.send_request(req)
ResponseConverter::Query.to_query_result(resps)
end

def search_query(...)
raise Error::FeatureNotAvailable, "scope search not supported in #{Protostellar::NAME} mode"
end

def search(...)
raise Error::FeatureNotAvailable, "scope search not supported in #{Protostellar::NAME} mode"
end
end
end
end
19 changes: 19 additions & 0 deletions test/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def setup
connect
skip("#{name}: CAVES does not support query service yet") if use_caves?
@bucket = @cluster.bucket(env.bucket)
@scope = @bucket.default_scope
@collection = @bucket.default_collection
@index_name = "idx-#{@bucket.name}-#{rand(0..100_000)}"

Expand Down Expand Up @@ -235,5 +236,23 @@ def test_vector_search_query_defaults_to_match_none

assert_equal SearchQuery.match_none.to_json, enc_query
end

def test_vector_search_not_supported
skip("#{name}: Server supports vector search") if !env.protostellar? && env.server_version.supports_vector_search?

req = SearchRequest.new(VectorSearch.new(VectorQuery.new("foo", [-1.1, 1.2])))
assert_raises(Couchbase::Error::FeatureNotAvailable) do
@cluster.search("index", req)
end
end

def test_scope_search_not_supported
skip("#{name}: Server supports scope search") if !env.protostellar? && env.server_version.supports_scoped_search_indexes?

req = SearchRequest.new(SearchQuery.match_all)
assert_raises(Couchbase::Error::FeatureNotAvailable) do
@scope.search("index", req)
end
end
end
end
10 changes: 7 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,19 @@ def supports_update_collection?
end

def supports_update_collection_max_expiry?
@version >= Gem::Version.create("7.5.0")
trinity?
end

def supports_collection_max_expiry_set_to_no_expiry?
@version >= Gem::Version.create("7.6.0")
trinity?
end

def supports_scoped_search_indexes?
@version >= Gem::Version.create("7.5.0")
trinity?
end

def supports_vector_search?
trinity?
end
end

Expand Down