Skip to content

Commit

Permalink
fixed left/right, added more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aziz-mu committed Nov 16, 2022
1 parent a7c1a27 commit 2c2f46c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
3 changes: 2 additions & 1 deletion src/function/string/operations/include/left_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ struct Left {
public:
static inline void operation(
ku_string_t& left, int64_t& right, ku_string_t& result, ValueVector& resultValueVector) {
auto len = right > 0 ? min(left.len, (uint32_t)right) : 0u;
auto len = right >= 0 ? min(left.len, (uint32_t)right) :
((uint32_t)max(left.len + right, (int64_t)0));
SubStr::operation(left, 1, len, result, resultValueVector);
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/function/string/operations/include/right_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ struct Right {
public:
static inline void operation(
ku_string_t& left, int64_t& right, ku_string_t& result, ValueVector& resultValueVector) {
auto len = right > 0 ? min(left.len, (uint32_t)right) :
max((uint32_t)0u, left.len + (uint32_t)right);
auto len = right >= 0 ? min(left.len, (uint32_t)right) :
((uint32_t)max((int64_t)0, left.len + right));
SubStr::operation(left, left.len - len + 1, len, result, resultValueVector);
}
};
Expand Down
37 changes: 22 additions & 15 deletions test/test_files/tinySNB/function/string.test
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ Hubert Bla
#
#

-NAME RpadOutOfRange
-QUERY MATCH (o:organisation) RETURN rpad(o.name, -8, "y")
---- 3




-NAME SubStrStructuredStrAndLiteralInt
-QUERY MATCH (p:person) RETURN substr(p.fName, 2, 12)
---- 8
Expand Down Expand Up @@ -436,16 +443,16 @@ CsWo
DEsWor

-NAME LeftNegativeIdxStructuredStrAndLiteralInt
-QUERY MATCH (p:person) RETURN left(p.fName, -3)
-QUERY MATCH (p:person) RETURN left(p.fName, -4)
---- 8
A

C

Eliza
Fa






Hubert Blaine Wolfeschlegelsteinhausenbergerd

# TODO(Semih): Uncomment when enabling ad-hoc properties
#-NAME LeftUnstructuredStrAndLiteralInt
Expand Down Expand Up @@ -480,16 +487,16 @@ Work
EsWork

-NAME RightNegativeIdxStructuredStrAndLiteralInt
-QUERY MATCH (p:person) RETURN right(p.fName, -2)
-QUERY MATCH (p:person) RETURN right(p.fName, -4)
---- 8
ice
b
rol
n
izabeth
rooq
eg
bert Blaine Wolfeschlegelsteinhausenbergerdorff
e

l

abeth
oq

rt Blaine Wolfeschlegelsteinhausenbergerdorff

# TODO(Semih): Uncomment when enabling ad-hoc properties
#-NAME RightUnstructuredStrAndLiteralInt
Expand Down

0 comments on commit 2c2f46c

Please sign in to comment.