From 6d7443bc0811a2f6b242aa87d5b8134515c40f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Edelbo?= Date: Mon, 21 Oct 2019 14:38:20 +0200 Subject: [PATCH] Fix initialization of Compare expression Change-Id: If013cf622825a192ab00025f6b7832459b2d3550 --- src/realm/query_engine.cpp | 8 +++++++- src/realm/query_engine.hpp | 2 ++ src/realm/query_expression.hpp | 14 ++++++++++++++ test/test_query.cpp | 5 +++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/realm/query_engine.cpp b/src/realm/query_engine.cpp index 681c8161559..564a9648eb4 100644 --- a/src/realm/query_engine.cpp +++ b/src/realm/query_engine.cpp @@ -633,7 +633,7 @@ size_t NotNode::find_first_no_overlap(size_t start, size_t end) ExpressionNode::ExpressionNode(std::unique_ptr expression) : m_expression(std::move(expression)) { - m_dD = 10.0; + m_dD = 100.0; m_dT = 50.0; } @@ -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) { diff --git a/src/realm/query_engine.hpp b/src/realm/query_engine.hpp index 07b7febdf7d..806bc2ad7b2 100644 --- a/src/realm/query_engine.hpp +++ b/src/realm/query_engine.hpp @@ -910,6 +910,7 @@ class IntegerNode : public IntegerNodeBase { IntegerNodeBase::m_condition_column->find_all(*m_result, this->m_value, 0, realm::npos); m_index_get = 0; m_index_end = m_result->size(); + IntegerNodeBase::m_dT = 0; } } @@ -2374,6 +2375,7 @@ class ExpressionNode : public ParentNode { public: ExpressionNode(std::unique_ptr); + void init() override; size_t find_first_local(size_t start, size_t end) override; void table_changed() override; diff --git a/src/realm/query_expression.hpp b/src/realm/query_expression.hpp index a7835b42bc5..70ae2a0e0c9 100644 --- a/src/realm/query_expression.hpp +++ b/src/realm/query_expression.hpp @@ -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; @@ -3958,6 +3963,7 @@ inline Mixed get_mixed(const Value& val) template <> inline Mixed get_mixed(const Value&) { + REALM_ASSERT(false); return Mixed(); } @@ -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::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()); @@ -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 diff --git a/test/test_query.cpp b/test/test_query.cpp index ec96862168a..88afcbe51be 100644 --- a/test/test_query.cpp +++ b/test/test_query.cpp @@ -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(col_location) == "Fyn"; CHECK_EQUAL(q.find(), 0); Query q2 = origin->link(col_linklist).link(col_link).backlink(*foo, col_foo).column(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); }