-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add support for Base64 Encode/Decode Scalar Functions #9114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
05c8e99
c23e635
92e3451
10ad711
6991e74
33ec4d5
03046ff
372e13e
7a40588
bc8173f
541aa6a
17410d7
9774236
ef0f3d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import java.net.URLEncoder; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.text.Normalizer; | ||
| import java.util.Base64; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
@@ -393,6 +394,15 @@ public static byte[] toUtf8(String input) { | |
| return input.getBytes(StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| /** | ||
| * @param input bytes | ||
| * @return UTF8 encoded string | ||
| */ | ||
| @ScalarFunction | ||
| public static String fromUtf8(byte[] input) { | ||
| return new String(input, StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| /** | ||
| * @see StandardCharsets#US_ASCII#encode(String) | ||
| * @param input | ||
|
|
@@ -560,4 +570,22 @@ 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 toBase64(byte[] input) { | ||
| return Base64.getEncoder().encodeToString(input); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the expectation on charset of input bytes / binary data ? Looks like we assume it is UTF8. What if the input bytes provided here was encoded using UTF16
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved - we will not have a fixed charset of input bytes now with the new implementation. For example, if user wants to encode the String "hello!", he/she can choose to do
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we error if the user passes a string to the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved - added tests for calling toBase64 on a string. Will add in documentation that BYTES col will be represented in HEX string(also link:https://docs.pinot.apache.org/users/user-guide-query/querying-pinot#bytes-column). |
||
| } | ||
|
|
||
| /** | ||
| * @param input Base64 encoded String | ||
| * @return decoded binary data | ||
| */ | ||
| @ScalarFunction | ||
| public static byte[] fromBase64(String input) { | ||
| return Base64.getDecoder().decode(input); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.