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

ARROW-15699: [C++][Gandiva] Fix implementation of left and right func… #12440

Closed
wants to merge 1 commit into from

Conversation

nivia007
Copy link

…tions to handle more cases

Added conditions to handle below cases:
case where left('abcdef', -6) -> "" and left('abcdef', -7) -> ""
case where right('abcdef', -6) -> "" and right('abcdef', -7) -> ""

@github-actions
Copy link

@github-actions
Copy link

⚠️ Ticket has not been started in JIRA, please click 'Start Progress'.

@@ -2207,6 +2213,12 @@ const char* right_utf8_int32(gdv_int64 context, const char* text, gdv_int32 text
return "";
}

//case where right('abcdef', -6) -> "" and right('abcdef', -7) -> ""
if(number < 0 && abs(number) >= text_len) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not handling mutibyte unicode characters

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it for left('abc¥', -4) and it is returning correct result, Would it better if I put this condition in the for loop below
if (number < 0 && char_count <= abs(number)) {
*out_len = 0;
return "";
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

text_len for strings with multibyte characters will be number of bytes rather than number of characters.. while number refers the character count

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I assumed text_len is no of characters.

@nivia007 nivia007 force-pushed the fix_left_right_functions branch 5 times, most recently from 5803604 to 61eac98 Compare March 11, 2022 15:26
int32_t start_char_pos; // the char result start position (inclusive)
int32_t end_char_len; // the char result end position (inclusive)
int32_t end_pos; // the char result end position (inclusive)

if (number > 0) {
// case where right('abc', 5) ==> 'abc' start_char_pos=1.
start_char_pos = (char_count > number) ? char_count - number : 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this logic is not correct for multibyte unicode characters.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm. looks like it is being handled in following lines

@nivia007 nivia007 force-pushed the fix_left_right_functions branch 4 times, most recently from aa360b5 to 5ee9753 Compare March 17, 2022 04:48
…tions to handle more cases

Proper handling of multibyte characters

Added conditions to handle below cases:
case where left('abcdef', -6) -> "" and left('abcdef', -7) -> ""
case where right('abcdef', -6) -> "" and right('abcdef', -7) -> ""
@ursabot
Copy link

ursabot commented Mar 17, 2022

Benchmark runs are scheduled for baseline = 91f6585 and contender = 7e70c42. 7e70c42 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Finished ⬇️0.0% ⬆️0.0%] ec2-t3-xlarge-us-east-2
[Finished ⬇️0.21% ⬆️0.04%] test-mac-arm
[Failed ⬇️0.36% ⬆️0.0%] ursa-i9-9960x
[Finished ⬇️0.34% ⬆️0.09%] ursa-thinkcentre-m75q
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants