You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hop.apache.org by "dave-csc (via GitHub)" <gi...@apache.org> on 2024/11/26 15:35:32 UTC

[I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

dave-csc opened a new issue, #4624:
URL: https://github.com/apache/hop/issues/4624

   ### Apache Hop version?
   
   2.10.0
   
   ### Java version?
   
   17.0.2
   
   ### Operating system
   
   Linux
   
   ### What happened?
   
   Undocumented behaviours:
   - Set Cut from = 0 or lower, Cut to = a value greater than the string length: the entire string will be returned
   - Set Cut from = greater than 0, Cut to = a value greater than the string length: the substring from the "Cut from" index (+1) to the end of the original string will be returned
   - Set Cut from = 0, Cut to = a negative number (e.g. -10): the substring composed of the last (10) characters will be returned
   
   Unexpected behaviour:
   - Set Cut from and Cut to both negative (e.g. -10 and -5): NULL will be returned, even if Cut to is greater (lower absolute value) than Cut from -> probably a better choice should be returning the substring from length - (10) to length - (5)
   
   ### Issue Priority
   
   Priority: 3
   
   ### Issue Component
   
   Component: Documentation, Component: Transforms


-- 
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: issues-unsubscribe@hop.apache.org.apache.org

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


Re: [I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva commented on issue #4624:
URL: https://github.com/apache/hop/issues/4624#issuecomment-3107711389

   After thinking about it and looking at the code, that flip would cause extra complexity to the code for something that actually works.
   
   It would also cause a regression issue for the people who are already using it. I originally thought the code did not allow 2 negative numbers. The explanation could be as simple as the `from` location should always be closest to 0 


-- 
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: issues-unsubscribe@hop.apache.org

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


Re: [I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

Posted by "dave-csc (via GitHub)" <gi...@apache.org>.
dave-csc commented on issue #4624:
URL: https://github.com/apache/hop/issues/4624#issuecomment-3106604637

   Back on this issue, before updating the documentation in the wild 😅 
   
   The counter-intuitive part is actually in these lines:
   ```
         } else if ((cutFrom < 0 && cutTo < 0) && (cutFrom < cutTo)) {
           rcode = null;
   ...
           } else if (cutFrom < 0 && cutTo < 0) {
             rcode = rcode.substring(rcode.length() + cutTo, lenCode + cutFrom);
   ```
   
   I think the roles of `cutFrom` and `cutTo` should be swapped here: if I need to get `abcde` from the string `...vwxyzabcdefghij`, it has more sense to specify `cutFrom = -10` and `cutTo = -5`, rather than the opposite.
   
   With the code above, the `rcode` variable is valued to `null` since `cutFrom < cutTo`, whereas it has the intended string if `cutFrom >= cutTo` instead.


-- 
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: issues-unsubscribe@hop.apache.org

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


Re: [I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva commented on issue #4624:
URL: https://github.com/apache/hop/issues/4624#issuecomment-3106664649

   .take-issue
   
   Yes, that sounds like a valid change.
   Let me update that real quick and run some tests


-- 
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: issues-unsubscribe@hop.apache.org

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


Re: [I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva commented on issue #4624:
URL: https://github.com/apache/hop/issues/4624#issuecomment-2503354339

   The cutString logic:
   
   ```
   private String cutString(String string, int cutFrom, int cutTo) {
       String rcode = string;
   
       if (!Utils.isEmpty(rcode)) {
         int lenCode = rcode.length();
   
         if ((cutFrom >= 0 && cutTo >= 0) && cutFrom > lenCode) {
           rcode = null;
         } else if ((cutFrom >= 0 && cutTo >= 0) && (cutTo < cutFrom)) {
           rcode = null;
         } else if ((cutFrom < 0 && cutTo < 0) && cutFrom < -lenCode) {
           rcode = null;
         } else if ((cutFrom < 0 && cutTo < 0) && (cutFrom < cutTo)) {
           rcode = null;
         } else {
           if (cutTo > lenCode) {
             cutTo = lenCode;
           }
           if (cutTo < 0 && cutFrom == 0 && (-cutTo) > lenCode) {
             cutTo = -(lenCode);
           }
           if (cutTo < 0 && cutFrom < 0 && (-cutTo) > lenCode) {
             cutTo = -(lenCode);
           }
   
           if (cutFrom >= 0 && cutTo > 0) {
             rcode = rcode.substring(cutFrom, cutTo);
           } else if (cutFrom < 0 && cutTo < 0) {
             rcode = rcode.substring(rcode.length() + cutTo, lenCode + cutFrom);
           } else if (cutFrom == 0 && cutTo < 0) {
             int intFrom = rcode.length() + cutTo;
             rcode = rcode.substring(intFrom, lenCode);
           }
         }
       }
   
       return rcode;
     }
   ```


-- 
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: issues-unsubscribe@hop.apache.org

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


Re: [I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

Posted by "dave-csc (via GitHub)" <gi...@apache.org>.
dave-csc commented on issue #4624:
URL: https://github.com/apache/hop/issues/4624#issuecomment-3112836554

   Added some examples in the docs (see [pull request](https://github.com/apache/hop/pull/5565)).
   
   All the examples have been tested with Hop 2.14: anyway, I still find some of them kinda weird... 🤪


-- 
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: issues-unsubscribe@hop.apache.org

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


Re: [I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva commented on issue #4624:
URL: https://github.com/apache/hop/issues/4624#issuecomment-3112900558

   Yeah, discussions could be had about some of the returned results and null vs empty string.
   But having the current behaviour documented is a great step forward!
   
   thanks for the work @dave-csc 


-- 
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: issues-unsubscribe@hop.apache.org

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


Re: [I] [Bug]: Strings cut - unplanned/undocumented behaviours (hop)

Posted by "hansva (via GitHub)" <gi...@apache.org>.
hansva closed issue #4624: [Bug]: Strings cut - unplanned/undocumented behaviours
URL: https://github.com/apache/hop/issues/4624


-- 
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: issues-unsubscribe@hop.apache.org

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