hanyuzheng7 commented on code in PR #22834:
URL: https://github.com/apache/flink/pull/22834#discussion_r1253617456


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/functions/scalar/ArraySliceFunction.java:
##########
@@ -74,4 +74,32 @@ public 
ArraySliceFunction(SpecializedFunction.SpecializedContext context) {
             throw new FlinkRuntimeException(t);
         }
     }
+
+    public @Nullable ArrayData eval(ArrayData array, Integer start) {
+        try {
+            if (array == null || start == null) {
+                return null;
+            }
+            if (array.size() == 0) {
+                return array;
+            }
+            int startIndex = start;
+            int endIndex = array.size();
+            startIndex += startIndex < 0 ? array.size() + 1 : 0;
+            startIndex = Math.max(1, startIndex);
+            if (endIndex < startIndex) {
+                return new GenericArrayData(new Object[0]);
+            }
+            if (startIndex == 1 && endIndex == array.size()) {
+                return array;
+            }
+            List<Object> slicedArray = new ArrayList<>();
+            for (int i = startIndex - 1; i <= endIndex - 1; i++) {
+                slicedArray.add(elementGetter.getElementOrNull(array, i));
+            }
+            return new GenericArrayData(slicedArray.toArray());
+        } catch (Throwable t) {
+            throw new FlinkRuntimeException(t);
+        }
+    }

Review Comment:
   so you mean like this, at first I write like this, but I through we can 
concise.



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