rubenada commented on code in PR #3237:
URL: https://github.com/apache/calcite/pull/3237#discussion_r1227642472


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -4102,6 +4102,45 @@ public static List reverse(List list) {
     return list;
   }
 
+  /** SQL {@code ARRAY_TO_STRING(array, delimiter)} function. */
+  public static String arrayToString(List list, String delimiter) {
+    return arrayToString(list, delimiter, null);
+  }
+
+  /** SQL {@code ARRAY_TO_STRING(array, delimiter, nullText)} function. */
+  public static String arrayToString(List list, String delimiter, @Nullable 
String nullText) {
+    StringBuilder sb = new StringBuilder();
+    boolean isFirst = true;
+    for (Object item : list) {
+      String str;
+      if (item == null) {
+        str = null;
+      } else if (item instanceof String) {
+        str = (String) item;
+      } else if (item instanceof ByteString) {
+        str = item.toString();
+      } else {
+        throw new IllegalStateException(
+            "arrayToString supports only String or ByteString, but got "
+                + item.getClass().getName());
+      }
+      if (str == null) {

Review Comment:
   sorry @zoudan , just one last thing before the merge. I realized we could 
remove this `if` block and move its content to the first `if`, in order to make 
the code more compact:
   ```
   for (Object item : list) {
     String str;
     if (item == null) {
       if (nullText == null) {
         continue;
       } else {
         str = nullText;
       }
     } else if (item instanceof String) { 
     ...
   ```
   wdyt?
   



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