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

Fix the comparisions involving EMPTY. #5433

Merged
merged 7 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 4 additions & 4 deletions src/common/datatypes/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1777,8 +1777,8 @@ Value Value::toSet() const {
}
}
Value Value::lessThan(const Value& v) const {
if (empty() || v.empty()) {
return (v.isNull() || isNull()) ? Value::kNullValue : Value::kEmpty;
if (UNLIKELY(empty() || v.empty())) {
return Value::kNullValue;
}
auto vType = v.type();
auto hasNull = (type_ | vType) & Value::Type::NULLVALUE;
Expand Down Expand Up @@ -1871,8 +1871,8 @@ Value Value::lessThan(const Value& v) const {
}

Value Value::equal(const Value& v) const {
if (empty()) {
return v.isNull() ? Value::kNullValue : v.empty();
if (UNLIKELY(empty() || v.empty())) {
return !empty() || !v.empty() ? false : Value::kNullValue;
}
auto vType = v.type();
auto hasNull = (type_ | vType) & Value::Type::NULLVALUE;
Expand Down
24 changes: 12 additions & 12 deletions src/common/expression/test/RelationalExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,26 @@ TEST_F(ExpressionTest, LiteralConstantsRelational) {
auto *operand2 = ConstantExpression::make(&pool, Value());
auto *expr = RelationalExpression::makeEQ(&pool, operand1, operand2);
auto eval = Expression::eval(expr, gExpCtxt);
EXPECT_EQ(eval.type(), Value(true).type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value(true)) << "check failed: " << expr->toString();
EXPECT_EQ(eval.type(), Value::kNullValue.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kNullValue) << "check failed: " << expr->toString();
}
{
// empty == null
auto *operand1 = ConstantExpression::make(&pool, Value());
auto *operand2 = ConstantExpression::make(&pool, Value(NullType::__NULL__));
auto *expr = RelationalExpression::makeEQ(&pool, operand1, operand2);
auto eval = Expression::eval(expr, gExpCtxt);
EXPECT_EQ(eval.type(), Value::kNullValue.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kNullValue) << "check failed: " << expr->toString();
EXPECT_EQ(eval.type(), Value(false).type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value(false)) << "check failed: " << expr->toString();
}
{
// empty != null
auto *operand1 = ConstantExpression::make(&pool, Value());
auto *operand2 = ConstantExpression::make(&pool, Value(NullType::__NULL__));
auto *expr = RelationalExpression::makeNE(&pool, operand1, operand2);
auto eval = Expression::eval(expr, gExpCtxt);
EXPECT_EQ(eval.type(), Value::kNullValue.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kNullValue) << "check failed: " << expr->toString();
EXPECT_EQ(eval.type(), Value(true).type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value(true)) << "check failed: " << expr->toString();
}
{
// empty != 1
Expand All @@ -145,26 +145,26 @@ TEST_F(ExpressionTest, LiteralConstantsRelational) {
auto *operand2 = ConstantExpression::make(&pool, Value("1"));
auto *expr = RelationalExpression::makeGT(&pool, operand1, operand2);
auto eval = Expression::eval(expr, gExpCtxt);
EXPECT_EQ(eval.type(), Value::kEmpty.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kEmpty) << "check failed: " << expr->toString();
EXPECT_EQ(eval.type(), Value::kNullValue.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kNullValue) << "check failed: " << expr->toString();
}
{
// empty < 1
auto *operand1 = ConstantExpression::make(&pool, Value());
auto *operand2 = ConstantExpression::make(&pool, Value(1));
auto *expr = RelationalExpression::makeLT(&pool, operand1, operand2);
auto eval = Expression::eval(expr, gExpCtxt);
EXPECT_EQ(eval.type(), Value::kEmpty.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kEmpty) << "check failed: " << expr->toString();
EXPECT_EQ(eval.type(), Value::kNullValue.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kNullValue) << "check failed: " << expr->toString();
}
{
// empty >= 1.11
auto *operand1 = ConstantExpression::make(&pool, Value());
auto *operand2 = ConstantExpression::make(&pool, Value(1.11));
auto *expr = RelationalExpression::makeGE(&pool, operand1, operand2);
auto eval = Expression::eval(expr, gExpCtxt);
EXPECT_EQ(eval.type(), Value::kEmpty.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kEmpty) << "check failed: " << expr->toString();
EXPECT_EQ(eval.type(), Value::kNullValue.type()) << "type check failed: " << expr->toString();
EXPECT_EQ(eval, Value::kNullValue) << "check failed: " << expr->toString();
}
{
TEST_EXPR(null != 1, Value::kNullValue);
Expand Down
3 changes: 3 additions & 0 deletions src/graph/executor/logic/LoopExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ folly::Future<Status> LoopExecutor::execute() {
QueryExpressionContext ctx(ectx_);

auto value = expr->eval(ctx);
if (value.isNull()) {
value = Value(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that u should assign false to the value. maybe you need not to check the result of value, just delete the following DCHECK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Copy link
Contributor Author

@xtcyclist xtcyclist Mar 27, 2023

Choose a reason for hiding this comment

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

It won't pass the tck. Reverted for now.

It is an expression containing at least one EMPTY here. This place is expecting a TRUE value, if nothing more is introduced to change this part.

}
DCHECK(value.isBool());
finally_ = !(value.isBool() && value.getBool());
return finish(ResultBuilder().value(std::move(value)).iter(Iterator::Kind::kDefault).build());
Expand Down
18 changes: 18 additions & 0 deletions tests/tck/features/expression/BugFixWithngdata.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2023 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: Bug fixes with ngdata

Background:
Given a graph with space named "ngdata"

Scenario: Comparing EMPTY values
When executing query:
"""
MATCH (v0:Label_0)-[e0]->()-[e1*1..1]->(v1)
WHERE (id(v0) == 11) AND (v1.Label_6.Label_6_400_Int == v1.Label_6.Label_6_500_Int)
RETURN count(*)
"""
Then the result should be, in any order:
| count(*) |
| 0 |