Skip to content

Commit

Permalink
Fix initialization of Compare expression
Browse files Browse the repository at this point in the history
Change-Id: If013cf622825a192ab00025f6b7832459b2d3550
  • Loading branch information
jedelbo committed Oct 21, 2019
1 parent 2d6bf51 commit 6d7443b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/realm/query_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ size_t NotNode::find_first_no_overlap(size_t start, size_t end)
ExpressionNode::ExpressionNode(std::unique_ptr<Expression> expression)
: m_expression(std::move(expression))
{
m_dD = 10.0;
m_dD = 100.0;
m_dT = 50.0;
}

Expand All @@ -642,6 +642,12 @@ void ExpressionNode::table_changed()
m_expression->set_base_table(m_table.get());
}

void ExpressionNode::init()
{
ParentNode::init();
m_dT = m_expression->init();
}

std::string ExpressionNode::describe(util::serializer::SerialisationState& state) const
{
if (m_expression) {
Expand Down
2 changes: 2 additions & 0 deletions src/realm/query_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ class IntegerNode<ColType, Equal> : public IntegerNodeBase<ColType> {
IntegerNodeBase<ColType>::m_condition_column->find_all(*m_result, this->m_value, 0, realm::npos);
m_index_get = 0;
m_index_end = m_result->size();
IntegerNodeBase<ColType>::m_dT = 0;
}
}

Expand Down Expand Up @@ -2374,6 +2375,7 @@ class ExpressionNode : public ParentNode {
public:
ExpressionNode(std::unique_ptr<Expression>);

void init() override;
size_t find_first_local(size_t start, size_t end) override;

void table_changed() override;
Expand Down
14 changes: 14 additions & 0 deletions src/realm/query_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ class Expression {
{
}

virtual double init()
{
return 50.0; // Default dT
}

virtual size_t find_first(size_t start, size_t end) const = 0;
virtual void set_base_table(const Table* table) = 0;
virtual void verify_column() const = 0;
Expand Down Expand Up @@ -3958,6 +3963,7 @@ inline Mixed get_mixed(const Value<T>& val)
template <>
inline Mixed get_mixed(const Value<RowIndex>&)
{
REALM_ASSERT(false);
return Mixed();
}

Expand Down Expand Up @@ -3986,6 +3992,11 @@ class Compare : public Expression {
{
m_left->set_base_table(table);
m_right->set_base_table(table);
}

double init() override
{
double dT = m_left_is_const ? 10.0 : 50.0;
if (std::is_same<TCond, Equal>::value && m_left_is_const && m_right->has_search_index()) {
if (m_left_value.m_storage.is_null(0)) {
m_matches = m_right->find_all(util::Optional<Mixed>());
Expand All @@ -4001,7 +4012,10 @@ class Compare : public Expression {
m_has_matches = true;
m_index_get = 0;
m_index_end = m_matches.size();
dT = 0;
}

return dT;
}

void verify_column() const override
Expand Down
5 changes: 5 additions & 0 deletions test/test_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12272,11 +12272,16 @@ TEST(Query_LinksWithIndex)
auto ll = foo->get_linklist(col_foo, ndx);
ll->add(2);
ll->add(4);

Query q1 =
origin->link(col_linklist).link(col_link).backlink(*foo, col_foo).column<String>(col_location) == "Fyn";
CHECK_EQUAL(q.find(), 0);
Query q2 = origin->link(col_linklist).link(col_link).backlink(*foo, col_foo).column<Int>(col_score) == 5;
CHECK_EQUAL(q.find(), 0);

// Make sure that changes in the table are reflected in the query result
middle->set_link(col_link, 3, 1);
CHECK_EQUAL(q.find(), 1);
}


Expand Down

0 comments on commit 6d7443b

Please sign in to comment.