macroguo-ghy commented on code in PR #3373:
URL: https://github.com/apache/calcite/pull/3373#discussion_r1299376267


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -1804,6 +1804,28 @@ void testCastToBoolean(CastType castType, 
SqlOperatorFixture f) {
         consumer);
   }
 
+  @Test void testCodePointsToBytes() {
+    final SqlOperatorFixture f = fixture()
+        .setFor(SqlLibraryOperators.CODE_POINTS_TO_BYTES, VM_FENNEL, VM_JAVA)
+        .withLibrary(SqlLibrary.BIG_QUERY);
+    f.checkFails("^code_points_to_bytes('abc')^",
+        "Cannot apply 'CODE_POINTS_TO_BYTES' to arguments of type "
+            + "'CODE_POINTS_TO_BYTES\\(<CHAR\\(3\\)>\\)'\\. "
+            + "Supported form\\(s\\): 'CODE_POINTS_TO_BYTES\\(<ARRAY>\\)'", 
false);
+    f.checkFails("code_points_to_bytes(array[-1])",
+        "Input arguments of CODE_POINTS_TO_BYTES out of range: -1", true);
+    f.checkFails("code_points_to_bytes(array[2147483648, 1])",
+        "Input arguments of CODE_POINTS_TO_BYTES out of range: 2147483648", 
true);
+
+    f.checkString("code_points_to_bytes(array[65,66,67,68])", "41424344", 
"VARBINARY NOT NULL");

Review Comment:
   Done.



##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -831,6 +831,30 @@ public static String charFromUtf8(int n) {
     return String.valueOf(Character.toChars(n));
   }
 
+  /**
+   * SQL CODE_POINTS_TO_BYTES function.
+   */
+  public static @Nullable ByteString codePointsToBytes(List codePoints) {
+    int length = codePoints.size();
+    byte[] bytes = new byte[length];
+    for (int i = 0; i < length; i++) {
+      Object codePoint = codePoints.get(i);
+      if (codePoint == null) {
+        return null;
+      }
+      if (codePoint instanceof Number) {
+        long cp = ((Number) codePoint).longValue();
+        if (cp < 0 || cp > 255) {
+          throw new IllegalArgumentException(

Review Comment:
   Done.



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

Reply via email to