siddharthteotia commented on code in PR #9114:
URL: https://github.com/apache/pinot/pull/9114#discussion_r932946962


##########
pinot-common/src/main/java/org/apache/pinot/common/function/scalar/StringFunctions.java:
##########
@@ -560,4 +562,42 @@ public static String decodeUrl(String input)
       throws UnsupportedEncodingException {
     return URLDecoder.decode(input, StandardCharsets.UTF_8.toString());
   }
+
+  /**
+   * @param input binary data
+   * @return Base64 encoded String
+   */
+  @ScalarFunction
+  public static String binaryToBase64(byte[] input) {
+    return Base64.getEncoder().encodeToString(input);
+  }
+
+  /**
+   * @param input string to be encoded
+   * @return Base64 encoded String
+   */
+  @ScalarFunction
+  public static String toBase64(String input) {
+    return toBase64(input, "UTF-8");
+  }
+
+  /**
+   * @param input String encoded with user specified encodeScheme
+   * @return Base64 encoded String
+   */
+  @ScalarFunction
+  public static String toBase64(String input, String encodeScheme) {
+    byte[] inputBytes = input.getBytes(Charset.forName(encodeScheme));
+    return Base64.getEncoder().encodeToString(inputBytes);
+  }
+
+  /**
+   * @param input Base64 encoded String
+   * @return decoded string
+   */
+  @ScalarFunction
+  public static String fromBase64(String input) {

Review Comment:
   If we are providing a `toBase64` with a user specified charset encoding and 
a default utf8 charset flavor then shouldn't we also provide `fromBase64` in 
both flavors as well ?
   
   What if someone calls `toBase64("blahblah", "UTF16")` to get "something" and 
then `fromBase64("something")` - this will convert "something" to bytes and 
then to String using UTF8 which can be wrong because "something" was created 
from "blahblah" using UTF16.



-- 
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: commits-unsubscr...@pinot.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to