Skip to content

CXX-2697 Add search index spec tests and management helpers #986

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 47 commits into from
Jul 20, 2023

Conversation

joshbsiegel
Copy link
Contributor

@joshbsiegel joshbsiegel commented Jul 11, 2023

Summary

This PR will add the search index spec tests and respective functionality needed to pass the spec tests.

Background

Due to the spec test additions made in mongodb/specifications#1423, it was necessary to sync the spec test changes made and then ensure that the driver can pass those tests. To accomplish this, we chose to add an index view API and referenced the pseudocode function definitions found in the specifications PR.

Design

The search_index_view structure is very similar to the existing index_view structure. All of the public API functions call their private counterpart which constructs a BSON command and sends it to the server. Both search_index_view and search_index_model are designed with the PIMPL pattern.

Testing

At the moment, there are only spec tests for search indexes from this commit. There is no capability for e2e testing yet but when there is a separate PR will be made with additions to test/search_index_view.cpp. Edit: e2e testing was implemented in this ticket: #1002

What's New

  • 5 new spec tests
  • Add functionality to return a search_index_view from a collection
  • search_index_model.hpp and search_index_model.cpp
  • search_index_view.hpp and search_index_view.cpp
  • private/search_index_view.hh
  • private/search_index_model.hh
  • 5 new operation handlers in operations.cpp
  • Updating CMake configuration to recognize the new files
  • private/append_aggregate_options: a helper function for options::aggregate::append and search_index_view::impl::list

@joshbsiegel joshbsiegel requested a review from kevinAlbs July 11, 2023 21:33
@@ -32,7 +32,7 @@ class MONGOCXX_API search_index_model {
///
/// Move assigns a search_index_model.
///
search_index_model& operator=(search_index_model&&) noexcept;
Copy link
Contributor Author

@joshbsiegel joshbsiegel Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking a function as noexcept requires that all members of the class must also have noexcept on the corresponding function. While the _definition field is a bsoncxx::document::value which has its move assign operator as noexcept, the bsoncxx::stdx::optional<std::string> _name field does not have the same tag on its move assign operator. Instead of making changes to stdx::optional which could affect the entire codebase, it's easier to just remove the noexcept from the move assign operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is for future testing that cannot be done at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file contains the code that was previously in options::aggregate::append. In order to reduce code duplication, the best practice would be to use append to extract the options from the options::aggregate variables passed through to list. However, because append is private, search_index_view would need to become a friend of options::aggregate. Because the code in append only accesses public variables and functions in options::aggregate and it seemed unneccessary to give search_index_view access to all of options::aggregate, we opted to move the function to a private file.

@joshbsiegel joshbsiegel requested a review from kevinAlbs July 17, 2023 20:08
@kevinAlbs kevinAlbs requested a review from eramongodb July 18, 2023 19:50
Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work. LGTM with one comment.

@joshbsiegel joshbsiegel requested a review from eramongodb July 20, 2023 15:39
@joshbsiegel joshbsiegel requested a review from eramongodb July 20, 2023 17:45
@eramongodb eramongodb requested a review from kevinAlbs July 20, 2023 17:47
Copy link
Collaborator

@eramongodb eramongodb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small feedback remaining; otherwise, LGTM. 👍


const search_index_view::impl& search_index_view::_get_impl() const {
if (!_impl) {
throw logic_error{error_code::k_invalid_client_object};
Copy link
Collaborator

@eramongodb eramongodb Jul 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs similar fix as search_index_model w.r.t. error_code enumerator.

Copy link
Collaborator

@kevinAlbs kevinAlbs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with minor comments addressed.

Comment on lines 4 to 6
#include <mongocxx/private/client_session.hh>
#include <mongocxx/private/libbson.hh>
#include <mongocxx/private/libmongoc.hh>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <mongocxx/private/client_session.hh>
#include <mongocxx/private/libbson.hh>
#include <mongocxx/private/libmongoc.hh>
#include <mongocxx/search_index_model.hpp>

Include search_index_model.hpp directly. Remove unnecessary headers.


const search_index_model::impl& search_index_model::_get_impl() const {
if (!_impl) {
throw logic_error{error_code::k_invalid_search_index_model};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw logic_error{error_code::k_invalid_search_index_model};
throw mongocxx::logic_error{error_code::k_invalid_search_index_model};

search_index_model.cpp appears to rely on headers included throughclient_session.hh. Update search_index_model.cpp to include headers needed for throwing error:

#include <mongocxx/exception/error_code.hpp>
#include <mongocxx/exception/logic_error.hpp>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants