Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 129ed2e

Browse files
authored
fix eval contains filter on storaged (vesoft-inc#5485)
* fix eval contains filter on storaged * add tck case * add tck case * fix tck * fix lint * fix lint
1 parent 0659aa2 commit 129ed2e

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

src/common/expression/RelationalExpression.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) {
115115
case Kind::kContains: {
116116
if (lhs.isBadNull() || rhs.isBadNull()) {
117117
result_ = Value::kNullBadType;
118-
} else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) {
118+
} else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) ||
119+
(!rhs.isNull() && !rhs.empty() && !rhs.isStr())) {
119120
result_ = Value::kNullBadType;
120121
} else if (lhs.isStr() && rhs.isStr()) {
121122
result_ = lhs.getStr().size() >= rhs.getStr().size() &&
@@ -128,7 +129,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) {
128129
case Kind::kNotContains: {
129130
if (lhs.isBadNull() || rhs.isBadNull()) {
130131
result_ = Value::kNullBadType;
131-
} else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) {
132+
} else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) ||
133+
(!rhs.isNull() && !rhs.empty() && !rhs.isStr())) {
132134
result_ = Value::kNullBadType;
133135
} else if (lhs.isStr() && rhs.isStr()) {
134136
result_ = !(lhs.getStr().size() >= rhs.getStr().size() &&
@@ -141,7 +143,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) {
141143
case Kind::kStartsWith: {
142144
if (lhs.isBadNull() || rhs.isBadNull()) {
143145
result_ = Value::kNullBadType;
144-
} else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) {
146+
} else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) ||
147+
(!rhs.isNull() && !rhs.empty() && !rhs.isStr())) {
145148
result_ = Value::kNullBadType;
146149
} else if (lhs.isStr() && rhs.isStr()) {
147150
result_ =
@@ -154,7 +157,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) {
154157
case Kind::kNotStartsWith: {
155158
if (lhs.isBadNull() || rhs.isBadNull()) {
156159
result_ = Value::kNullBadType;
157-
} else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) {
160+
} else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) ||
161+
(!rhs.isNull() && !rhs.empty() && !rhs.isStr())) {
158162
result_ = Value::kNullBadType;
159163
} else if (lhs.isStr() && rhs.isStr()) {
160164
result_ =
@@ -167,7 +171,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) {
167171
case Kind::kEndsWith: {
168172
if (lhs.isBadNull() || rhs.isBadNull()) {
169173
result_ = Value::kNullBadType;
170-
} else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) {
174+
} else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) ||
175+
(!rhs.isNull() && !rhs.empty() && !rhs.isStr())) {
171176
result_ = Value::kNullBadType;
172177
} else if (lhs.isStr() && rhs.isStr()) {
173178
result_ =
@@ -182,7 +187,8 @@ const Value& RelationalExpression::eval(ExpressionContext& ctx) {
182187
case Kind::kNotEndsWith: {
183188
if (lhs.isBadNull() || rhs.isBadNull()) {
184189
result_ = Value::kNullBadType;
185-
} else if ((!lhs.isNull() && !lhs.isStr()) || (!rhs.isNull() && !rhs.isStr())) {
190+
} else if ((!lhs.isNull() && !lhs.empty() && !lhs.isStr()) ||
191+
(!rhs.isNull() && !rhs.empty() && !rhs.isStr())) {
186192
result_ = Value::kNullBadType;
187193
} else if (lhs.isStr() && rhs.isStr()) {
188194
result_ = !(lhs.getStr().size() >= rhs.getStr().size() &&
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright (c) 2022 vesoft inc. All rights reserved.
2+
#
3+
# This source code is licensed under Apache 2.0 License.
4+
@tag1
5+
Feature: contains filter
6+
7+
Background:
8+
Given a graph with space named "nba"
9+
10+
Scenario: contains filter
11+
When executing query:
12+
"""
13+
MATCH (n:player{name:"Tim Duncan"})-[e]->(m) where m.player.name contains "Tony Parker" RETURN n,e,m ORDER BY m;
14+
"""
15+
Then the result should be, in order:
16+
| n | e | m |
17+
| ("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"}) |
18+
| ("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"}) |
19+
When executing query:
20+
"""
21+
MATCH (n:player{name:"Tim Duncan"})-[e]->(m) where m.player.name starts with "Manu" RETURN n,e,m ORDER BY m;
22+
"""
23+
Then the result should be, in order:
24+
| n | e | m |
25+
| ("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"}) |
26+
| ("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"}) |
27+
When executing query:
28+
"""
29+
MATCH (n:player{name:"Tim Duncan"})-[e]->(m) where m.team.name ends with "urs" RETURN n,e,m ORDER BY m;
30+
"""
31+
Then the result should be, in order:
32+
| n | e | m |
33+
| ("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 commit comments

Comments
 (0)