HappenLee commented on code in PR #16841:
URL: https://github.com/apache/doris/pull/16841#discussion_r1108545211


##########
fe/java-udf/src/main/java/org/apache/doris/udf/BaseExecutor.java:
##########
@@ -380,11 +668,435 @@ protected boolean storeUdfResult(Object obj, long row, 
Class retClass) throws Ud
                 updateOutputOffset(offset);
                 return true;
             }
+            case ARRAY_TYPE: {
+                Type type = retType.getItemType();
+                return arrayTypeOutputData(obj, type, row);
+            }
             default:
                 throw new UdfRuntimeException("Unsupported return type: " + 
retType);
         }
     }
 
+    public boolean arrayTypeOutputData(Object obj, Type type, long row) throws 
UdfRuntimeException {
+        long offset = getCurrentOutputOffset(row);
+        long bufferSize = UdfUtils.UNSAFE.getLong(null, 
outputIntermediateStatePtr);
+        switch (type.getPrimitiveType()) {
+            case BOOLEAN: {
+                ArrayList<Boolean> data = (ArrayList<Boolean>) obj;
+                int num = data.size();
+                if (offset + num > bufferSize) {
+                    return false;
+                }
+                for (int i = 0; i < num; ++i) {
+                    Boolean value = data.get(i);
+                    if (value == null) {
+                        UdfUtils.UNSAFE
+                                .putByte(UdfUtils.UNSAFE.getLong(null, 
outputArrayNullPtr) + (offset + i), (byte) 1);
+                    } else {
+                        UdfUtils.UNSAFE
+                                .putByte(UdfUtils.UNSAFE.getLong(null, 
outputArrayNullPtr) + (offset + i), (byte) 0);
+                        UdfUtils.UNSAFE
+                                .putByte(UdfUtils.UNSAFE.getLong(null, 
outputBufferPtr) + (offset + i),
+                                        value ? (byte) 1 : 0);
+                    }
+                }
+                offset += num;
+                UdfUtils.UNSAFE.putLong(null, UdfUtils.UNSAFE.getLong(null, 
outputOffsetsPtr) + 8L * row,
+                        Long.parseUnsignedLong(String.valueOf(offset)));
+                updateOutputOffset(offset);
+                return true;
+            }
+            case TINYINT: {
+                ArrayList<Byte> data = (ArrayList<Byte>) obj;
+                int num = data.size();
+                if (offset + num > bufferSize) {
+                    return false;
+                }
+                for (int i = 0; i < num; ++i) {
+                    Byte value = data.get(i);
+                    if (value == null) {
+                        UdfUtils.UNSAFE
+                                .putByte(UdfUtils.UNSAFE.getLong(null, 
outputArrayNullPtr) + (offset + i), (byte) 1);
+                    } else {
+                        UdfUtils.UNSAFE
+                                .putByte(UdfUtils.UNSAFE.getLong(null, 
outputArrayNullPtr) + (offset + i), (byte) 0);

Review Comment:
   only call `UdfUtils.UNSAFE.getLong(null, outputArrayNullPtr)` one time
   



-- 
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...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to