Skip to content

Commit

Permalink
for comparisions of any two values, as long as one operand is EMPTY, …
Browse files Browse the repository at this point in the history
…we return NULL.
  • Loading branch information
xtcyclist committed Mar 24, 2023
1 parent c74acf8 commit af4d809
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/common/datatypes/Value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ Value Value::toSet() const {
}
Value Value::lessThan(const Value& v) const {
if (empty() || v.empty()) {
return (v.isNull() || isNull()) ? Value::kNullValue : Value::kEmpty;
return 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,8 +100,8 @@ 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
Expand All @@ -127,44 +127,44 @@ TEST_F(ExpressionTest, LiteralConstantsRelational) {
auto *operand2 = ConstantExpression::make(&pool, Value(1));
auto *expr = RelationalExpression::makeNE(&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 != true
auto *operand1 = ConstantExpression::make(&pool, Value());
auto *operand2 = ConstantExpression::make(&pool, Value(true));
auto *expr = RelationalExpression::makeNE(&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 > "1"
auto *operand1 = ConstantExpression::make(&pool, Value());
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

0 comments on commit af4d809

Please sign in to comment.