From 15e33e2917f58703e14b86e52935740765b8372e Mon Sep 17 00:00:00 2001 From: codesigner Date: Mon, 10 Apr 2023 20:01:18 +0800 Subject: [PATCH 1/6] fix eval contains filter on storaged --- src/common/expression/RelationalExpression.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/common/expression/RelationalExpression.cpp b/src/common/expression/RelationalExpression.cpp index 887562f1cb3..645dbf4272d 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() && From b8548a4a7e7cc70e3bc4857d802a5a526c9accc6 Mon Sep 17 00:00:00 2001 From: codesigner Date: Mon, 10 Apr 2023 22:29:05 +0800 Subject: [PATCH 2/6] add tck case --- .../features/bugfix/ContainsFilter.feature | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 tests/tck/features/bugfix/ContainsFilter.feature diff --git a/tests/tck/features/bugfix/ContainsFilter.feature b/tests/tck/features/bugfix/ContainsFilter.feature new file mode 100644 index 00000000000..ebe1595641c --- /dev/null +++ b/tests/tck/features/bugfix/ContainsFilter.feature @@ -0,0 +1,32 @@ +# Copyright (c) 2022 vesoft inc. All rights reserved. +# +# This source code is licensed under Apache 2.0 License. +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 any order, with relax comparison: + | n | e | m | + | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player101"->"player100" @0 {degree: 95}] | ("player101" :player{age: 36, name: "Tony Parker"}) | + | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player100"->"player101" @0 {degree: 95}] | ("player101" :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 any order, with relax comparison: + | n | e | m | + | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player125"->"player100" @0 {degree: 90}] | ("player125" :player{age: 41, name: "Manu Ginobili"}) | + | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player100"->"player125" @0 {degree: 95}] | ("player125" :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 any order, with relax comparison: + | n | e | m | + | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:serve "player100"->"team204" @0 {end_year: 2016, start_year: 1997}] | ("team204" :team{name: "Spurs"}) | \ No newline at end of file From c9c55f7db6858322246f219c087f7e31ca2de098 Mon Sep 17 00:00:00 2001 From: codesigner Date: Mon, 10 Apr 2023 22:32:10 +0800 Subject: [PATCH 3/6] add tck case --- tests/tck/features/bugfix/ContainsFilter.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tck/features/bugfix/ContainsFilter.feature b/tests/tck/features/bugfix/ContainsFilter.feature index ebe1595641c..58782575f90 100644 --- a/tests/tck/features/bugfix/ContainsFilter.feature +++ b/tests/tck/features/bugfix/ContainsFilter.feature @@ -29,4 +29,4 @@ Feature: contains filter """ Then the result should be, in any order, with relax comparison: | n | e | m | - | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:serve "player100"->"team204" @0 {end_year: 2016, start_year: 1997}] | ("team204" :team{name: "Spurs"}) | \ No newline at end of file + | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:serve "player100"->"team204" @0 {end_year: 2016, start_year: 1997}] | ("team204" :team{name: "Spurs"}) | From 0e62fba45e3a1115f5253a16cea97825cbc7d15a Mon Sep 17 00:00:00 2001 From: codesigner Date: Tue, 11 Apr 2023 10:48:11 +0800 Subject: [PATCH 4/6] fix tck --- .../features/bugfix/ContainsFilter.feature | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tests/tck/features/bugfix/ContainsFilter.feature b/tests/tck/features/bugfix/ContainsFilter.feature index 58782575f90..440ec5d585b 100644 --- a/tests/tck/features/bugfix/ContainsFilter.feature +++ b/tests/tck/features/bugfix/ContainsFilter.feature @@ -1,6 +1,7 @@ # Copyright (c) 2022 vesoft inc. All rights reserved. # # This source code is licensed under Apache 2.0 License. +@tag1 Feature: contains filter Background: @@ -9,24 +10,26 @@ Feature: contains filter 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; + 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 any order, with relax comparison: - | n | e | m | - | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player101"->"player100" @0 {degree: 95}] | ("player101" :player{age: 36, name: "Tony Parker"}) | - | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player100"->"player101" @0 {degree: 95}] | ("player101" :player{age: 36, name: "Tony Parker"}) | + 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; + 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 any order, with relax comparison: - | n | e | m | - | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player125"->"player100" @0 {degree: 90}] | ("player125" :player{age: 41, name: "Manu Ginobili"}) | - | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:follow "player100"->"player125" @0 {degree: 95}] | ("player125" :player{age: 41, name: "Manu Ginobili"}) | + 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; + 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 any order, with relax comparison: - | n | e | m | - | ("player100" :player{age: 42, name: "Tim Duncan"}) | [:serve "player100"->"team204" @0 {end_year: 2016, start_year: 1997}] | ("team204" :team{name: "Spurs"}) | + 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"}) | + From 69c981e68bd93ba6949368ff0a37d37f99ab20c5 Mon Sep 17 00:00:00 2001 From: codesigner Date: Tue, 11 Apr 2023 13:33:54 +0800 Subject: [PATCH 5/6] fix lint --- tests/tck/features/bugfix/ContainsFilter.feature | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tck/features/bugfix/ContainsFilter.feature b/tests/tck/features/bugfix/ContainsFilter.feature index 440ec5d585b..eae4d95bf5f 100644 --- a/tests/tck/features/bugfix/ContainsFilter.feature +++ b/tests/tck/features/bugfix/ContainsFilter.feature @@ -32,4 +32,3 @@ Feature: contains filter 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"}) | - From 9b7d55f68be08e94575adc58f053029ae5d09174 Mon Sep 17 00:00:00 2001 From: codesigner Date: Tue, 11 Apr 2023 13:38:44 +0800 Subject: [PATCH 6/6] fix lint --- tests/tck/features/bugfix/ContainsFilter.feature | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/tck/features/bugfix/ContainsFilter.feature b/tests/tck/features/bugfix/ContainsFilter.feature index eae4d95bf5f..fc898c53a3f 100644 --- a/tests/tck/features/bugfix/ContainsFilter.feature +++ b/tests/tck/features/bugfix/ContainsFilter.feature @@ -16,7 +16,6 @@ Feature: contains filter | 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;