Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 938 #1035

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/function/list/operations/include/list_extract_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ struct ListExtract {
}

static inline void operation(ku_string_t& str, int64_t& idx, ku_string_t& result) {
auto pos = idx > 0 ? min(idx, (int64_t)str.len) : max(str.len + idx, (int64_t)0) + 1;
result.set((char*)(str.getData() + pos - 1), 1 /* length */);
if (str.len < idx) {
result.set("", 0);
} else {
auto pos = idx > 0 ? min(idx, (int64_t)str.len) : max(str.len + idx, (int64_t)0) + 1;
result.set((char*)(str.getData() + pos - 1), 1 /* length */);
}
}

static inline void operation(Value& item, int64_t& pos, Value& result) {
Expand Down
4 changes: 2 additions & 2 deletions src/function/string/operations/include/left_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +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) :
max(left.len + (uint32_t)right, (uint32_t)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: 4 additions & 0 deletions src/function/string/operations/include/pad_operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ struct PadOperation {
static inline void operation(ku_string_t& src, int64_t count, ku_string_t& characterToPad,
ku_string_t& result, ValueVector& resultValueVector,
void (*padOperation)(ku_string_t& result, ku_string_t& src, ku_string_t& characterToPad)) {
if (count <= 0) {
result.set("", 0);
return;
}
assert(characterToPad.len == 1);
result.len = count;
if (!ku_string_t::isShortString(result.len)) {
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
70 changes: 54 additions & 16 deletions test/test_files/tinySNB/function/string.test
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,18 @@ Huber
#
#

-NAME LpadOutOfRange
-QUERY MATCH (p:person) RETURN lpad(p.fName, -10, "t")
aziz-mu marked this conversation as resolved.
Show resolved Hide resolved
---- 8









-NAME RpadStructuredStrAndLiteralInt
-QUERY MATCH (p:person) RETURN rpad(p.fName, 15, ">")
---- 8
Expand Down Expand Up @@ -380,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 @@ -424,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
aziz-mu marked this conversation as resolved.
Show resolved Hide resolved
Al
A

C

Ca
Eliza
Fa

Elizab
Far
G
Hubert Blaine Wolfeschlegelsteinhausenbergerdo
Hubert Blaine Wolfeschlegelsteinhausenbergerd

# TODO(Semih): Uncomment when enabling ad-hoc properties
#-NAME LeftUnstructuredStrAndLiteralInt
Expand Down Expand Up @@ -468,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 Expand Up @@ -513,6 +532,25 @@ B
s
E

-NAME ListExtractOutOfRange
-QUERY MATCH (a:person) RETURN a.fName[8]
---- 8




t


B

-NAME ListExtractNegativeIndex
-QUERY MATCH (o:organisation) RETURN o.name[-2]
---- 3
n
r
r

# TODO(Semih): Uncomment when enabling ad-hoc properties
#-NAME ListExtractUnstructuredString
#-QUERY MATCH (o:organisation) RETURN o.unstrStr[4]
Expand Down