tanclary commented on code in PR #3373:
URL: https://github.com/apache/calcite/pull/3373#discussion_r1297489523
##########
babel/src/test/resources/sql/big-query.iq:
##########
@@ -3593,5 +3593,61 @@ FROM items;
!ok
+#####################################################################
+# CODE_POINTS_TO_BYTES(array<integer>)
+#
+# Takes an array of extended ASCII code points as ARRAY<INT64>
+# and returns BYTES.
+#
+SELECT CODE_POINTS_TO_BYTES(array[65, 66, 67, 68]) as result;
++----------+
+| result |
++----------+
+| 41424344 |
++----------+
+(1 row)
+
+!ok
+
+SELECT CODE_POINTS_TO_BYTES(array[255, 254, 65, 64]) as result;
++----------+
+| result |
++----------+
+| fffe4140 |
++----------+
+(1 row)
+
+!ok
+SELECT CODE_POINTS_TO_BYTES(null) as result;
++--------+
+| result |
++--------+
+| |
++--------+
+(1 row)
+
+!ok
+
+SELECT CODE_POINTS_TO_BYTES(array[65, null]) as result;
++--------+
+| result |
++--------+
+| |
++--------+
+(1 row)
+
+!ok
+
+SELECT CODE_POINTS_TO_BYTES('abc') as result;
+Cannot apply 'CODE_POINTS_TO_BYTES' to arguments of type
'CODE_POINTS_TO_BYTES(<CHAR(3)>)'. Supported form(s):
'CODE_POINTS_TO_BYTES(<ARRAY>)'
+!error
+
+SELECT CODE_POINTS_TO_BYTES(array[-1]) as result;
+Input arguments of CODE_POINTS_TO_BYTES out of range: -1
+!error
+
Review Comment:
Would you mind moving this to somewhere other than the end of the file?
Adding to the end of files can create merge conflict headaches later
##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -816,6 +816,33 @@ public static String charFromUtf8(int n) {
return String.valueOf(Character.toChars(n));
}
+ /**
+ * SQL CODE_POINTS_TO_BYTES function.
+ */
+ public static @Nullable ByteString codePointsToBytes(@Nullable List
codePoints) {
+ if (codePoints == null) {
+ return null;
+ }
+ int length = codePoints.size();
+ byte[] bytes = new byte[length];
+ for (int i = 0; i < length; i++) {
+ Object codePoint = codePoints.get(i);
Review Comment:
Is there a reason to not do `for(Object codePoint : codepoints)`?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]