Skip to content
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

Lexicographical comparison for string queries #7273

Merged
merged 4 commits into from
Jan 26, 2024
Merged

Conversation

ironage
Copy link
Contributor

@ironage ironage commented Jan 19, 2024

This feature was requested by realm/realm-swift#8008.
I also added a small performance improvement for string queries; no need to always convert the constant std::optional<std::string> to a StringData in the hot query path, it can be done once in the constructor of the query node.

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • C-API, if public C++ API changed
  • bindgen/spec.yml, if public C++ API changed

@ironage ironage self-assigned this Jan 19, 2024
Copy link

coveralls-official bot commented Jan 19, 2024

Pull Request Test Coverage Report for Build james.stone_480

  • -19 of 115 (83.48%) changed or added relevant lines in 6 files are covered.
  • 91 unchanged lines in 17 files lost coverage.
  • Overall coverage decreased (-0.01%) to 91.842%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/test_query.cpp 49 53 92.45%
test/util/unit_test.hpp 9 24 37.5%
Files with Coverage Reduction New Missed Lines %
src/realm/util/compression.cpp 1 91.59%
test/util/unit_test.hpp 1 85.66%
src/realm/object-store/shared_realm.cpp 2 93.03%
src/realm/sync/noinst/server/server_history.cpp 2 67.94%
src/realm/table_view.cpp 2 94.18%
src/realm/uuid.cpp 2 97.06%
src/realm/query_engine.hpp 3 94.12%
src/realm/sort_descriptor.cpp 3 93.7%
src/realm/util/future.hpp 3 95.98%
src/realm/sync/noinst/client_reset.cpp 4 92.96%
Totals Coverage Status
Change from base Build 1993: -0.01%
Covered Lines: 235211
Relevant Lines: 256103

💛 - Coveralls

@ironage ironage marked this pull request as draft January 20, 2024 04:27
@ironage
Copy link
Contributor Author

ironage commented Jan 20, 2024

There is a discrepancy between how nulls behave in this and the way it works in the string based queries; converting this to a draft until I investigate further.

@ironage ironage force-pushed the js/query-string-lex branch from 070690f to 23d5873 Compare January 22, 2024 23:59
@ironage ironage marked this pull request as ready for review January 23, 2024 00:01
Copy link
Member

@nicola-cab nicola-cab left a comment

Choose a reason for hiding this comment

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

nice! There is a lint issue to be fixed.

if (cond(StringData(m_value), m_ucase.c_str(), m_lcase.c_str(), t))
return s;
if constexpr (case_sensitive_comparison) {
// case insensitive not implemented for these comparisons
Copy link
Member

Choose a reason for hiding this comment

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

nit: probably a better comment here is needed, we are talking about string lexicographical comparisons, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, updated the comment to be specific

@@ -1545,9 +1544,14 @@ class StringNodeBase : public ParentNode {
template <class TConditionFunction>
class StringNode : public StringNodeBase {
public:
constexpr static bool case_sensitive_comparison =
Copy link
Member

Choose a reason for hiding this comment

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

nit: I guess you want this constexpr, available at compile time, but do you need this to be static as well, in order to be used like this StringNode::case_sensitive_comparison?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is a compile error to remove the static on a constexpr member

Copy link
Member

@nicola-cab nicola-cab Jan 24, 2024

Choose a reason for hiding this comment

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

I was more thinking whether you needed it as public member, or you could just have a constexpr variable defined in the method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see. Well I suppose it doesn't need to be public, but I'd like it at the class scope because I use it for a small optimization in the constructor as well.

Copy link
Contributor

@jedelbo jedelbo left a comment

Choose a reason for hiding this comment

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

LGTM

@cla-bot cla-bot bot added the cla: yes label Jan 26, 2024
@ironage ironage merged commit 666ba2d into master Jan 26, 2024
38 of 39 checks passed
@ironage ironage deleted the js/query-string-lex branch January 26, 2024 22:01
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants