Skip to content

Commit

Permalink
fix eval contains filter on storaged (#5485)
Browse files Browse the repository at this point in the history
* fix eval contains filter on storaged

* add tck case

* add tck case

* fix tck

* fix lint

* fix lint
  • Loading branch information
codesigner committed Apr 11, 2023
1 parent 0659aa2 commit 129ed2e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/common/expression/RelationalExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() &&
Expand All @@ -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() &&
Expand All @@ -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_ =
Expand All @@ -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_ =
Expand All @@ -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_ =
Expand All @@ -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() &&
Expand Down
33 changes: 33 additions & 0 deletions tests/tck/features/bugfix/ContainsFilter.feature
Original file line number Diff line number Diff line change
@@ -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"}) |

0 comments on commit 129ed2e

Please sign in to comment.