You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2019/04/09 21:41:18 UTC

[GitHub] [incubator-druid] justinborromeo commented on a change in pull request #7388: Support LPAD and RPAD sql function

justinborromeo commented on a change in pull request #7388: Support LPAD and RPAD sql function
URL: https://github.com/apache/incubator-druid/pull/7388#discussion_r273716078
 
 

 ##########
 File path: core/src/main/java/org/apache/druid/java/util/common/StringUtils.java
 ##########
 @@ -360,4 +360,93 @@ public static String encodeBase64String(byte[] input)
   {
     return BASE64_DECODER.decode(input);
   }
+
+  /**
+   * Returns the string left-padded with the string pad to a length of len characters.
+   * If str is longer than len, the return value is shortened to len characters. 
+   *
+   * @param base The base string to be padded
+   * @param len The length of padded string
+   * @param pad The pad string
+   * @return the string left-padded with pad to a lenght of len
+   */
+  public static String lpad(String base, Integer len, String pad)
+  {
+    if (len < 0) {
+      return null;
+    } else if (len == 0) {
+      return "";
+    }
+
+    char[] data = new char[len];
+    char[] baseChars = base.toCharArray();
 
 Review comment:
   Is there a reason you copy `base` and `pad` to their own char arrays instead of just calling `charAt(index)` on the original strings?  

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org