Fix bug in InListOperator

Reviewers: florijan, teon.banek

Reviewed By: florijan

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D981
This commit is contained in:
Mislav Bradac 2017-11-14 14:42:58 +01:00
parent 463e86653d
commit e703e955a5
2 changed files with 23 additions and 3 deletions

View File

@ -157,9 +157,14 @@ class ExpressionEvaluator : public TreeVisitor<TypedValue> {
_list.type());
}
auto list = _list.Value<std::vector<TypedValue>>();
if (literal.IsNull()) {
return TypedValue::Null;
}
// If literal is NULL there is no need to try to compare it with every
// element in the list since result of every comparison will be NULL. There
// is one special case that we must test explicitly: if list is empty then
// result is false since no comparison will be performed.
if (list.size() == 0U) return false;
if (literal.IsNull()) return TypedValue::Null;
auto has_null = false;
for (const auto &element : list) {
auto result = literal == element;

View File

@ -344,6 +344,21 @@ TEST(ExpressionEvaluator, InListOperator) {
auto value = op->Accept(eval.eval);
EXPECT_TRUE(value.IsNull());
}
{
// Null literal.
auto *op = storage.Create<InListOperator>(
storage.Create<PrimitiveLiteral>(TypedValue::Null), list_literal);
auto value = op->Accept(eval.eval);
EXPECT_TRUE(value.IsNull());
}
{
// Null literal, empty list.
auto *op = storage.Create<InListOperator>(
storage.Create<PrimitiveLiteral>(TypedValue::Null),
storage.Create<ListLiteral>(std::vector<Expression *>()));
auto value = op->Accept(eval.eval);
EXPECT_FALSE(value.ValueBool());
}
}
TEST(ExpressionEvaluator, ListMapIndexingOperator) {