From 2c2f46c5fbf4b0dbaf1bab1923d46313fbafb110 Mon Sep 17 00:00:00 2001 From: aziz-mu Date: Wed, 16 Nov 2022 11:20:23 -0500 Subject: [PATCH] fixed left/right, added more tests --- .../operations/include/left_operation.h | 3 +- .../operations/include/right_operation.h | 4 +- test/test_files/tinySNB/function/string.test | 37 +++++++++++-------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/function/string/operations/include/left_operation.h b/src/function/string/operations/include/left_operation.h index 3e9ea07b933..75acf03b64e 100644 --- a/src/function/string/operations/include/left_operation.h +++ b/src/function/string/operations/include/left_operation.h @@ -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); } }; diff --git a/src/function/string/operations/include/right_operation.h b/src/function/string/operations/include/right_operation.h index 5a0f0ec4bd9..e3ef73df44e 100644 --- a/src/function/string/operations/include/right_operation.h +++ b/src/function/string/operations/include/right_operation.h @@ -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); } }; diff --git a/test/test_files/tinySNB/function/string.test b/test/test_files/tinySNB/function/string.test index 486b795aab4..5ad894f9a57 100644 --- a/test/test_files/tinySNB/function/string.test +++ b/test/test_files/tinySNB/function/string.test @@ -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 @@ -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 @@ -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