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

RCORE-2221 test to prove between node wrong behaviour over links #7940

Closed
wants to merge 3 commits into from
Closed
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
32 changes: 22 additions & 10 deletions src/realm/parser/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,26 +643,38 @@ Query BetweenNode::visit(ParserDriver* drv)
Query q(drv->m_base_table);

auto tmp = prop->visit(drv);

const ObjPropertyBase* obj_prop = dynamic_cast<const ObjPropertyBase*>(tmp.get());
if (obj_prop) {
if (tmp->get_type() == type_Int) {
auto min_val = min->visit(drv, type_Int);
auto max_val = max->visit(drv, type_Int);

auto create_between_query = [&min, &max, &drv, &obj_prop](ConstTableRef table, DataType type) {
Query q(table);
auto min_val = min->visit(drv, type);
auto max_val = max->visit(drv, type);

if (type == type_Int) {
q.between(obj_prop->column_key(), min_val->get_mixed().get_int(), max_val->get_mixed().get_int());
return q;
}
if (tmp->get_type() == type_Timestamp) {
auto min_val = min->visit(drv, type_Timestamp);
auto max_val = max->visit(drv, type_Timestamp);
else if (type == type_Timestamp) {
q.between(obj_prop->column_key(), min_val->get_mixed().get_timestamp(),
max_val->get_mixed().get_timestamp());
return q;
}
return q;
};

if (obj_prop) {
const auto type = tmp->get_type();
if (type == type_Int || type == type_Timestamp) {
if (obj_prop->links_exist()) {
const auto& link_map = obj_prop->get_link_map();
Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure if this is enough, and it is covering all the cases, but it seems like it is enough to pass all core tests, we basically need to use the target table if the query is run over links. @ironage @jedelbo

Copy link
Contributor

@ironage ironage Aug 7, 2024

Choose a reason for hiding this comment

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

This approach doesn't work because you are passing the destination column and the destination table, without accounting for the links along the way. The specialized between node doesn't handle links, so we can just fall back to a normal relational comparison below. I have opened #7965 to do it this way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok great! Probably we should have a test in core that tracks this, because if something is not working, some test should tell us!!! But again, thanks for spotting this.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a test in #7965 which will catch this.

const auto tb = link_map.get_target_table();
return create_between_query(tb, type);
}
return create_between_query(drv->m_base_table, type);
}
}

RelationalNode cmp1(prop, CompareType::GREATER_EQUAL, min);
RelationalNode cmp2(prop, CompareType::LESS_EQUAL, max);

q.and_query(cmp1.visit(drv));
q.and_query(cmp2.visit(drv));

Expand Down
25 changes: 25 additions & 0 deletions test/test_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6559,4 +6559,29 @@ TEST(Parser_Wildcard)
CHECK_EQUAL(q.count(), 1);
}

TEST(Test_Between_OverLinks)
{
Group g;
TableRef parent = g.add_table("Parent");
TableRef child = g.add_table("Child");

ColKey ck_child = parent->add_column(*child, "child");
ColKey ck_int = child->add_column(type_Int, "int");

for (size_t i = 0; i < 100; ++i) {
auto obj = child->create_object();
obj.set(ck_int, (int)i);
parent->create_object().set(ck_child, obj.get_key());
}

// this works is using a RelationalNode
auto q = parent->query("child.int < 50");
CHECK(q.count() == 50);

// this uses the new in between node and verifies that the link is followed.
auto q1 = parent->query("child.int BETWEEN {0,100}");
Copy link
Member Author

Choose a reason for hiding this comment

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

Apparently we are not following the links, when we do:

auto min_val = min->visit(drv, type_Int);
auto max_val = max->visit(drv, type_Int);
q.between(obj_prop->column_key(), min_val->get_mixed().get_int(), max_val->get_mixed().get_int());
return q;

CHECK(q1.count() == 100);
}


#endif // TEST_PARSER
Loading