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_r288689267
##########
File path: core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
##########
@@ -121,6 +124,36 @@
private SqlFunctions() {
}
+ /** SQL TO_BASE64(string) function*/
+ public static String toBase64(String string) {
+ if (string == null) {
+ return null;
+ }
+ String base64 = new
String(Base64.getEncoder().encode(string.getBytes(UTF_8)), UTF_8);
+ String temp = base64;
+ StringBuilder str = new StringBuilder();
+ while ((temp.length() / 76) > 0) {
+ str.append(temp.substring(0, 76));
+ str.append("\n");
+ temp = temp.substring(76, temp.length());
+ }
+ base64 = str.append(temp).toString();
+ return base64;
+ }
+
+ /** SQL FROM_BASE64(string) function*/
+ public static String fromBase64(String base64) {
+ if (base64 == null) {
+ return null;
+ }
+ try {
+ base64 = base64.replaceAll("[\\t\\n\\r ]", "");
Review comment:
Probably `\s` is better:
From docs
> \s A whitespace character: [ \t\n\x0B\f\r]
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services