You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/30 20:14:48 UTC

[GitHub] [arrow-datafusion] WinkerDu opened a new pull request #2128: MINOR: fix concat_ws corner bug

WinkerDu opened a new pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128


   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #2100.
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   Function concat_ws is not ignoring NULL in last argument and seperator text is added at the end of the result.
   To Reproduce
   ```
   SELECT concat_ws('|', 'a', NULL);
   -- Result: a|
   ```
   Expected behavior
   ```
   SELECT concat_ws('|', 'a', NULL);
   -- Result: a
   ```
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   skip adding separator when NULL in last argument.
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   No.
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337


   How about
   ```rust
     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)
   ```
   Or may there is a way to use [kernel concat](https://docs.rs/arrow/11.0.0/arrow/compute/kernels/concat/index.html)?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337


   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)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] WinkerDu commented on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1086469438


   @Dandandan  @houqp @alamb PTAL


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] mateuszkj edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
mateuszkj edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083606926


   Now it's failing with two NULLs at last arguments.
   
   To Reproduce
   ```sql
   SELECT concat_ws('|','a',NULL, NULL);
   -- Result: a|
   ```
   Expected behavior
   ```sql
   SELECT concat_ws('|','a',NULL, NULL);
   -- Result: a
   ```
   
   I would suggest to append separator before pushing value. E.g.
   
   ```rust
   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));
       }
   }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] mateuszkj commented on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
mateuszkj commented on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083606926


   Now it's failing with two NULLs at last arguments.
   
   To Reproduce
   ```sql
   SELECT concat_ws('|','a',NULL, NULL);
   -- Result: a|
   ```
   Expected behavior
   ```sql
   SELECT concat_ws('|','a',NULL, NULL);
   -- Result: a
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] mateuszkj edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
mateuszkj edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083606926


   Now it's failing with two NULLs at last arguments.
   
   To Reproduce
   ```sql
   SELECT concat_ws('|','a',NULL, NULL);
   -- Result: a|
   ```
   Expected behavior
   ```sql
   SELECT concat_ws('|','a',NULL, NULL);
   -- Result: a
   ```
   
   I would suggest to append separator before pushing value. E.g.
   
   ```rust
           .map(|(index, x)| {
               x.map(|sep: &str| {
                   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));
                       }
                   }
                   owned_string
               })
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337


   How about
   ```rust
     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)
   ```
   Or may be there a way to use [kernel concat](https://docs.rs/arrow/11.0.0/arrow/compute/kernels/concat/index.html)?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 commented on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 commented on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337


   How about
   ```
     let mut owned_string = Vec::with_capacity(args.len());
     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)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] Dandandan commented on a change in pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
Dandandan commented on a change in pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#discussion_r840891530



##########
File path: datafusion/physical-expr/src/string_expressions.rs
##########
@@ -343,18 +343,17 @@ pub fn concat_ws(args: &[ArrayRef]) -> Result<ArrayRef> {
         .enumerate()
         .map(|(index, x)| {
             x.map(|sep: &str| {
-                let mut owned_string: String = "".to_owned();
-                for arg_index in 1..args.len() {
-                    let arg = &args[arg_index];
-                    if !arg.is_null(index) {
-                        owned_string.push_str(arg.value(index));
-                        // if not last push separator
-                        if arg_index != args.len() - 1 {
-                            owned_string.push_str(sep);
+                let string_vec = args[1..]
+                    .iter()
+                    .flat_map(|arg| {
+                        if !arg.is_null(index) {
+                            vec![arg.value(index)]
+                        } else {
+                            vec![]

Review comment:
       ```suggestion
                           if !arg.is_null(index) {
                               Some(arg.value(index))
                           } else {
                               None
                           }
   ```
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] WinkerDu commented on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1086285090


   @mateuszkj @doki23 @Dandandan PTAL, thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337


   How about
   ```rust
     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)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] WinkerDu commented on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
WinkerDu commented on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1085378430


   @doki23 @Dandandan thanks for the advice, I'd try it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337


   How about
   ```rust
     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)
   ```
   Or there may be a way to use [https://docs.rs/arrow/11.0.0/arrow/compute/kernels/concat/index.html](arrow kernel concat)?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] doki23 edited a comment on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
doki23 edited a comment on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1083964337


   How about
   ```rust
     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)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] Dandandan commented on pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
Dandandan commented on pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128#issuecomment-1084330984


   > How about
   > ```rust
   >   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 + `flat_map` + `collect` (into `Vec<String>`) for a rusty version.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [arrow-datafusion] yjshen merged pull request #2128: MINOR: fix concat_ws corner bug

Posted by GitBox <gi...@apache.org>.
yjshen merged pull request #2128:
URL: https://github.com/apache/arrow-datafusion/pull/2128


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org