diff --git a/src/common/expression/RelationalExpression.cpp b/src/common/expression/RelationalExpression.cpp index 887562f1cb..645dbf4272 100644 --- a/src/common/expression/RelationalExpression.cpp +++ b/src/common/expression/RelationalExpression.cpp @@ -115,7 +115,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) { case Kind::kContains: { if (lhs.isBadNull() || rhs.isBadNull()) { result_ = Value::kNullBadType; - } else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) { + } else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) || + (!rhs.isNull() && !rhs.empty() && !rhs.isStr())) { result_ = Value::kNullBadType; } else if (lhs.isStr() && rhs.isStr()) { result_ = lhs.getStr().size() >= rhs.getStr().size() && @@ -128,7 +129,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) { case Kind::kNotContains: { if (lhs.isBadNull() || rhs.isBadNull()) { result_ = Value::kNullBadType; - } else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) { + } else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) || + (!rhs.isNull() && !rhs.empty() && !rhs.isStr())) { result_ = Value::kNullBadType; } else if (lhs.isStr() && rhs.isStr()) { result_ = !(lhs.getStr().size() >= rhs.getStr().size() && @@ -141,7 +143,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) { case Kind::kStartsWith: { if (lhs.isBadNull() || rhs.isBadNull()) { result_ = Value::kNullBadType; - } else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) { + } else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) || + (!rhs.isNull() && !rhs.empty() && !rhs.isStr())) { result_ = Value::kNullBadType; } else if (lhs.isStr() && rhs.isStr()) { result_ = @@ -154,7 +157,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) { case Kind::kNotStartsWith: { if (lhs.isBadNull() || rhs.isBadNull()) { result_ = Value::kNullBadType; - } else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) { + } else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) || + (!rhs.isNull() && !rhs.empty() && !rhs.isStr())) { result_ = Value::kNullBadType; } else if (lhs.isStr() && rhs.isStr()) { result_ = @@ -167,7 +171,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) { case Kind::kEndsWith: { if (lhs.isBadNull() || rhs.isBadNull()) { result_ = Value::kNullBadType; - } else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) { + } else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) || + (!rhs.isNull() && !rhs.empty() && !rhs.isStr())) { result_ = Value::kNullBadType; } else if (lhs.isStr() && rhs.isStr()) { result_ = @@ -182,7 +187,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) { case Kind::kNotEndsWith: { if (lhs.isBadNull() || rhs.isBadNull()) { result_ = Value::kNullBadType; - } else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) { + } else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) || + (!rhs.isNull() && !rhs.empty() && !rhs.isStr())) { result_ = Value::kNullBadType; } else if (lhs.isStr() && rhs.isStr()) { result_ = !(lhs.getStr().size() >= rhs.getStr().size() && diff --git a/tests/tck/features/bugfix/ContainsFilter.feature b/tests/tck/features/bugfix/ContainsFilter.feature new file mode 100644 index 0000000000..fc898c53a3 --- /dev/null +++ b/tests/tck/features/bugfix/ContainsFilter.feature @@ -0,0 +1,33 @@ +# Copyright (c) 2022 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. +@tag1 +Feature: contains filter + + Background: + Given a graph with space named "nba" + + Scenario: contains filter + When executing query: + """ + MATCH (n:player{name:"Tim Duncan"})-[e]->(m) where m.player.name contains "Tony Parker" RETURN n,e,m ORDER BY m; + """ + Then the result should be, in order: + | n | e | m | + | ("Tim Duncan" :player{age: 42, name: "Tim Duncan"} :bachelor{name: "Tim Duncan", speciality: "psychology"}) | [:like "Tim Duncan"->"Tony Parker" @0 {likeness: 95}] | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + | ("Tim Duncan" :player{age: 42, name: "Tim Duncan"} :bachelor{name: "Tim Duncan", speciality: "psychology"}) | [:teammate "Tim Duncan"->"Tony Parker" @0 {end_year: 2016, start_year: 2001}] | ("Tony Parker" :player{age: 36, name: "Tony Parker"}) | + When executing query: + """ + MATCH (n:player{name:"Tim Duncan"})-[e]->(m) where m.player.name starts with "Manu" RETURN n,e,m ORDER BY m; + """ + Then the result should be, in order: + | n | e | m | + | ("Tim Duncan" :player{age: 42, name: "Tim Duncan"} :bachelor{name: "Tim Duncan", speciality: "psychology"}) | [:like "Tim Duncan"->"Manu Ginobili" @0 {likeness: 95}] | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + | ("Tim Duncan" :player{age: 42, name: "Tim Duncan"} :bachelor{name: "Tim Duncan", speciality: "psychology"}) | [:teammate "Tim Duncan"->"Manu Ginobili" @0 {end_year: 2016, start_year: 2002}] | ("Manu Ginobili" :player{age: 41, name: "Manu Ginobili"}) | + When executing query: + """ + MATCH (n:player{name:"Tim Duncan"})-[e]->(m) where m.team.name ends with "urs" RETURN n,e,m ORDER BY m; + """ + Then the result should be, in order: + | n | e | m | + | ("Tim Duncan" :player{age: 42, name: "Tim Duncan"} :bachelor{name: "Tim Duncan", speciality: "psychology"}) | [:serve "Tim Duncan"->"Spurs" @0 {end_year: 2016, start_year: 1997}] | ("Spurs" :team{name: "Spurs"}) |