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:
parent
463e86653d
commit
e703e955a5
@ -157,9 +157,14 @@ class ExpressionEvaluator : public TreeVisitor<TypedValue> {
|
|||||||
_list.type());
|
_list.type());
|
||||||
}
|
}
|
||||||
auto list = _list.Value<std::vector<TypedValue>>();
|
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;
|
auto has_null = false;
|
||||||
for (const auto &element : list) {
|
for (const auto &element : list) {
|
||||||
auto result = literal == element;
|
auto result = literal == element;
|
||||||
|
@ -344,6 +344,21 @@ TEST(ExpressionEvaluator, InListOperator) {
|
|||||||
auto value = op->Accept(eval.eval);
|
auto value = op->Accept(eval.eval);
|
||||||
EXPECT_TRUE(value.IsNull());
|
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) {
|
TEST(ExpressionEvaluator, ListMapIndexingOperator) {
|
||||||
|
Loading…
Reference in New Issue
Block a user