Skip to content

Commit

Permalink
Update after review
Browse files Browse the repository at this point in the history
  • Loading branch information
jedelbo committed Apr 9, 2021
1 parent 1edc0bb commit 676403e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/realm/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,11 @@ std::unique_ptr<ParentNode> make_condition_node(const Table& table, ColKey colum
else if (value.is_type(type_TypedLink)) {
ObjLink link = value.get_link();
auto target_table = table.get_link_target(column_key);
if (target_table->get_key() == link.get_table_key()) {
key = link.get_obj_key();
if (target_table->get_key() != link.get_table_key()) {
// This will never match
return std::unique_ptr<ParentNode>{new ExpressionNode(std::make_unique<FalseExpression>())};
}
key = link.get_obj_key();
}
return std::unique_ptr<ParentNode>{new LinksToNode<Cond>(column_key, key)};
}
Expand Down
13 changes: 3 additions & 10 deletions src/realm/query_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,9 @@ size_t LinksToNode<Equal>::find_first_local(size_t start, size_t end)
}
else if (m_column_type == col_type_Link) {
for (auto& key : m_target_keys) {
if (key) {
// LinkColumn stores link to row N as the integer N + 1
auto pos = static_cast<const ArrayKey*>(m_leaf_ptr)->find_first(key, start, end);
if (pos != realm::npos) {
return pos;
}
auto pos = static_cast<const ArrayKey*>(m_leaf_ptr)->find_first(key, start, end);
if (pos != realm::npos) {
return pos;
}
}
}
Expand All @@ -732,10 +729,6 @@ size_t LinksToNode<NotEqual>::find_first_local(size_t start, size_t end)
ObjKey key = m_target_keys[0];

if (m_column_type == col_type_LinkList || m_condition_column_key.is_set()) {
if (!key) {
// Null key is never found in link lists
return start;
}
BPlusTree<ObjKey> links(m_table.unchecked_ptr()->get_alloc());
for (size_t i = start; i < end; i++) {
if (ref_type ref = static_cast<const ArrayList*>(m_leaf_ptr)->get(i)) {
Expand Down
13 changes: 13 additions & 0 deletions test/test_query2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5216,10 +5216,16 @@ TEST(Query_LinksTo)
q = source->column<Link>(col_link).is_null();
tv = q.find_all();
CHECK_EQUAL(tv.size(), 6);
q = source->where().equal(col_link, Mixed()); // Null
tv = q.find_all();
CHECK_EQUAL(tv.size(), 6);

q = source->column<Link>(col_link) != null();
found_key = q.find();
CHECK_EQUAL(found_key, source_keys[2]);
q = source->where().not_equal(col_link, Mixed()); // Null
tv = q.find_all();
CHECK_EQUAL(tv.size(), 4);

auto linklist = source->get_object(source_keys[1]).get_linklist_ptr(col_linklist);
linklist->add(target_keys[6]);
Expand All @@ -5246,6 +5252,13 @@ TEST(Query_LinksTo)
q = source->where().not_equal(col_linklist, Mixed(target_keys[6]));
tv = q.find_all();
CHECK_EQUAL(tv.size(), 2);

q = source->where().equal(col_linklist, Mixed());
tv = q.find_all();
CHECK_EQUAL(tv.size(), 0); // LinkList never matches null
q = source->where().not_equal(col_linklist, Mixed());
tv = q.find_all();
CHECK_EQUAL(tv.size(), 3);
}

TEST(Query_Group_bug)
Expand Down

0 comments on commit 676403e

Please sign in to comment.