You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2019/06/21 17:33:58 UTC

[GitHub] [calcite] vlsi commented on a change in pull request #800: [CALCITE-2460][CALCITE-2459] Add implementation of To_Base64 and From_Base64 to SqlFunctions

vlsi commented on a change in pull request #800: [CALCITE-2460][CALCITE-2459] Add implementation of To_Base64 and  From_Base64 to SqlFunctions
URL: https://github.com/apache/calcite/pull/800#discussion_r296328565
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
 ##########
 @@ -123,6 +126,48 @@
   private SqlFunctions() {
   }
 
+  /** SQL TO_BASE64(string) function. */
+  public static String toBase64(String string) {
+    String base64 = Base64.getEncoder().encodeToString(string.getBytes(UTF_8));
+    StringBuilder str = new StringBuilder(base64.length() + base64.length() / 76);
+    int i;
+    if (base64.length() > 76) {
+      for (i = 0; i + 76 < base64.length(); i += 76) {
+        str.append(base64, i, i + 76);
+        str.append("\n");
+      }
+      str.append(base64, i, base64.length());
+      return str.toString();
+    }
+    return base64;
+  }
+
+  /** SQL TO_BASE64(string) function for binary string. */
+  public static String toBase64(ByteString string) {
+    String base64 = Base64.getEncoder().encodeToString(string.getBytes());
+    StringBuilder str = new StringBuilder(base64.length() + base64.length() / 76);
+    int i;
+    if (base64.length() > 76) {
+      for (i = 0; i + 76 < base64.length(); i += 76) {
+        str.append(base64, i, i + 76);
+        str.append("\n");
+      }
+      str.append(base64, i, base64.length());
+      return str.toString();
+    }
+    return base64;
+  }
+
+  /** SQL FROM_BASE64(string) function. */
+  public static ByteString fromBase64(String base64) {
+    try {
+      base64 = base64.replaceAll("[\\t\\n\\r\\s]", "");
 
 Review comment:
   Please cache the regexp in question.

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