Skip to content

Commit

Permalink
fix == NONE {x} queries (#7333)
Browse files Browse the repository at this point in the history
* fix == NONE {x} queries

* more tests
  • Loading branch information
ironage authored Feb 13, 2024
1 parent 7df0def commit a84a3ed
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* Added a method to check if a file needs upgrade. ([#7140](https://github.com/realm/realm-core/issues/7140))

### Fixed
* Fixed queries like `indexed_property == NONE {x}` which mistakenly matched on only x instead of not x. This only applies when an indexed property with equality (==, or IN) matches with `NONE` on a list of one item. If the constant list contained more than one value then it was working correctly. ([realm-js #7862](https://github.com/realm/realm-java/issues/7862), since v12.5.0)
* Uploading the changesets recovered during an automatic client reset recovery may lead to 'Bad server version' errors and a new client reset. ([#7279](https://github.com/realm/realm-core/issues/7279), since v13.24.1)
* Fixed invalid data in error reason string when registering a subscription change notification after the subscription has already failed. ([#6839](https://github.com/realm/realm-core/issues/6839), since v11.8.0)
* Fixed crash in fulltext index using prefix search with no matches ([#7309](https://github.com/realm/realm-core/issues/7309), since v13.18.0)
Expand Down
6 changes: 5 additions & 1 deletion src/realm/query_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4262,18 +4262,22 @@ class Compare : public CompareBase {
// finding all matches up front.
Mixed const_value;
Subexpr* column;
std::optional<ExpressionComparisonType> const_value_cmp_type;
if (m_left->has_single_value()) {
const_value = m_left->get_mixed();
const_value_cmp_type = m_left->get_comparison_type();
column = m_right.get();
}
else {
const_value = m_right->get_mixed();
const_value_cmp_type = m_right->get_comparison_type();
column = m_left.get();
}

if (column->has_search_index() &&
column->get_comparison_type().value_or(ExpressionComparisonType::Any) ==
ExpressionComparisonType::Any) {
ExpressionComparisonType::Any &&
const_value_cmp_type.value_or(ExpressionComparisonType::Any) != ExpressionComparisonType::None) {
if (const_value.is_null()) {
const ObjPropertyBase* prop = dynamic_cast<const ObjPropertyBase*>(m_right.get());
// when checking for null across links, null links are considered matches,
Expand Down
30 changes: 30 additions & 0 deletions test/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,37 @@ TEST_TYPES(Parser_Numerics, Prop<Int>, Nullable<Int>, Indexed<Int>, NullableInde
verify_query(test_context, t, out.str(), 1);
verify_query_sub(test_context, t, util::format("values == $%1", i), args, 1);
}
size_t sz = t->size();
verify_query(test_context, t, "values == null", nullable ? 1 : 0);
verify_query(test_context, t, "values == ANY {-1, 0, 1}", 3);
verify_query(test_context, t, "values == ANY {0, 1}", 2);
verify_query(test_context, t, "values == ANY {1}", 1);
verify_query(test_context, t, "values == ANY {}", 0);

verify_query(test_context, t, "values == NONE {-1, 0, 1}", sz - 3);
verify_query(test_context, t, "values == NONE {-1, 0}", sz - 2);
verify_query(test_context, t, "values == NONE {-1}", sz - 1);
verify_query(test_context, t, "values == NONE {}", sz);

verify_query(test_context, t, "values == ALL {-1, 0, 1}", 0);
verify_query(test_context, t, "values == ALL {-1, 0}", 0);
verify_query(test_context, t, "values == ALL {-1}", 1);
verify_query(test_context, t, "values == ALL {}", sz);

verify_query(test_context, t, "values != NONE {-1, 0, 1}", 0);
verify_query(test_context, t, "values != NONE {-1, 0}", 0);
verify_query(test_context, t, "values != NONE {-1}", 1);
verify_query(test_context, t, "values != NONE {}", sz);

verify_query(test_context, t, "values != ANY {-1, 0, 1}", sz);
verify_query(test_context, t, "values != ANY {0, 1}", sz);
verify_query(test_context, t, "values != ANY {1}", sz - 1);
verify_query(test_context, t, "values != ANY {}", 0);

verify_query(test_context, t, "values != ALL {-1, 0, 1}", sz - 3);
verify_query(test_context, t, "values != ALL {-1, 0}", sz - 2);
verify_query(test_context, t, "values != ALL {-1}", sz - 1);
verify_query(test_context, t, "values != ALL {}", sz);
}

TEST(Parser_LinksToSameTable)
Expand Down

0 comments on commit a84a3ed

Please sign in to comment.