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/03/07 05:43:19 UTC

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

asereda-gs 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_r263243361
 
 

 ##########
 File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
 ##########
 @@ -107,6 +108,35 @@
   private SqlFunctions() {
   }
 
+  /** SQL TO_BASE64(string) function*/
+  public static String toBase64(String s) {
+    if (s == null) {
+      return null;
+    }
+    try {
+      return Base64.getEncoder().encodeToString(s.getBytes("UTF-8"));
+    } catch (Exception e) {
+      return null;
+    }
+  }
+
+  /** SQL FROM_BASE64(string) function*/
+  public static  String fromBase64(String s) {
+    if (s == null) {
+      return null;
+    }
+    try {
+      StringBuilder builder = new StringBuilder();
+      byte[] afterDecode = Base64.getDecoder().decode(s);
+      for (byte b : afterDecode) {
 
 Review comment:
   why not use `new String(...)` instead of loop ? 

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