chucheng92 commented on code in PR #3320:
URL: https://github.com/apache/calcite/pull/3320#discussion_r1285699097


##########
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java:
##########
@@ -4107,6 +4113,97 @@ public static List arrayExcept(List list1, List list2) {
     return new ArrayList<>(result);
   }
 
+  /** Support the ARRAY_INSERT(array, pos, val) function. */
+  public static @Nullable List arrayInsert(List baselist, Object pos, Object 
val) {
+    if (baselist == null || pos == null) {
+      return null;
+    }
+    int posInt = (int) pos;
+    if (posInt == 0) {
+      throw new IllegalArgumentException("The index 0 is invalid. "
+          + "An index shall be either < 0 or > 0 (the first element has index 
1)");
+    }
+
+    boolean usePositivePos = posInt > 0;
+
+    if (usePositivePos) {
+      int newArrayLength = Math.max(baselist.size() + 1, posInt);

Review Comment:
   @NobiGo yes. you are right. `System.arraycopy()` may has better performance 
when array is large. I have fixed it. PTAL.



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