NobiGo commented on code in PR #3320: URL: https://github.com/apache/calcite/pull/3320#discussion_r1285482457
########## 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: I get it. Thanks for your explanation. How about we use the `System.arraycopy()` and `Arrays.fill()` to implement this? Others are good to me. ########## site/_docs/reference.md: ########## @@ -2658,6 +2658,7 @@ BigQuery's type system uses confusingly different names for types and functions: | s | ARRAY_CONTAINS(array, element) | Returns true if the *array* contains the *element* | s | ARRAY_DISTINCT(array) | Removes duplicate values from the *array* that keeps ordering of elements | s | ARRAY_EXCEPT(array1, array2) | Returns an array of the elements in *array1* but not in *array2*, without duplicates +| s | ARRAY_INSERT(array, pos, element) | Places *element* into index *pos* of *array*. Array index start at 1, or start from the end if index is negative. Index above array size appends the array, or prepends the array if index is negative, with 'null' elements. Review Comment: `NULL` value is better? -- 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: commits-unsubscr...@calcite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org