-
Notifications
You must be signed in to change notification settings - Fork 2k
MINOR: fix concat_ws corner bug #2128
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
Conversation
|
Now it's failing with two NULLs at last arguments. To Reproduce SELECT concat_ws('|','a',NULL, NULL);
-- Result: a|Expected behavior SELECT concat_ws('|','a',NULL, NULL);
-- Result: aI would suggest to append separator before pushing value. E.g. let mut owned_string: String = "".to_owned();
let mut first = true;
for arg_index in 1..args.len() {
let arg = &args[arg_index];
if !arg.is_null(index) {
// if not first push separator
if !first {
owned_string.push_str(sep);
first = false;
}
owned_string.push_str(arg.value(index));
}
} |
|
How about let mut owned_string = Vec::with_capacity(args.len()-1);
for arg_index in 1..args.len() {
let arg = &args[arg_index];
if !arg.is_null(index) {
owned_string.push(arg.value(index));
}
}
owned_string.join(sep) |
Could also use an iterator + |
|
@doki23 @Dandandan thanks for the advice, I'd try it |
|
@mateuszkj @doki23 @Dandandan PTAL, thanks |
| if !arg.is_null(index) { | ||
| vec![arg.value(index)] | ||
| } else { | ||
| vec![] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if !arg.is_null(index) { | |
| vec![arg.value(index)] | |
| } else { | |
| vec![] | |
| if !arg.is_null(index) { | |
| Some(arg.value(index)) | |
| } else { | |
| None | |
| } |
|
@Dandandan @houqp @alamb PTAL |
doki23
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @WinkerDu
Which issue does this PR close?
Closes #2100.
Rationale for this change
Function concat_ws is not ignoring NULL in last argument and seperator text is added at the end of the result.
To Reproduce
Expected behavior
What changes are included in this PR?
skip adding separator when NULL in last argument.
Are there any user-facing changes?
No.