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


##########
fe/be-java-extensions/java-udf/src/main/java/org/apache/doris/udf/UdfConvert.java:
##########
@@ -0,0 +1,1762 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.udf;
+
+import org.apache.doris.common.jni.utils.JNINativeMethod;
+import org.apache.doris.common.jni.utils.OffHeap;
+import org.apache.doris.common.jni.utils.UdfUtils;
+
+import com.google.common.base.Preconditions;
+import org.apache.log4j.Logger;
+
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.math.RoundingMode;
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+public class UdfConvert {
+    private static final Logger LOG = Logger.getLogger(UdfConvert.class);
+
+    public static Object[] convertBooleanArg(boolean isNullable, int numRows, 
long nullMapAddr, long columnAddr) {
+        Boolean[] argument = new Boolean[numRows];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    argument[i] = UdfUtils.UNSAFE.getBoolean(null, columnAddr 
+ i);
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                argument[i] = UdfUtils.UNSAFE.getBoolean(null, columnAddr + i);
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertTinyIntArg(boolean isNullable, int numRows, 
long nullMapAddr, long columnAddr) {
+        Byte[] argument = new Byte[numRows];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    argument[i] = UdfUtils.UNSAFE.getByte(null, columnAddr + 
i);
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                argument[i] = UdfUtils.UNSAFE.getByte(null, columnAddr + i);
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertSmallIntArg(boolean isNullable, int numRows, 
long nullMapAddr, long columnAddr) {
+        Short[] argument = new Short[numRows];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    argument[i] = UdfUtils.UNSAFE.getShort(null, columnAddr + 
(i * 2L));
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                argument[i] = UdfUtils.UNSAFE.getShort(null, columnAddr + (i * 
2L));
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertIntArg(boolean isNullable, int numRows, long 
nullMapAddr, long columnAddr) {
+        Integer[] argument = new Integer[numRows];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    argument[i] = UdfUtils.UNSAFE.getInt(null, columnAddr + (i 
* 4L));
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                argument[i] = UdfUtils.UNSAFE.getInt(null, columnAddr + (i * 
4L));
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertBigIntArg(boolean isNullable, int numRows, 
long nullMapAddr, long columnAddr) {
+        Long[] argument = new Long[numRows];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    argument[i] = UdfUtils.UNSAFE.getLong(null, columnAddr + 
(i * 8L));
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                argument[i] = UdfUtils.UNSAFE.getLong(null, columnAddr + (i * 
8L));
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertFloatArg(boolean isNullable, int numRows, 
long nullMapAddr, long columnAddr) {
+        Float[] argument = new Float[numRows];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    argument[i] = UdfUtils.UNSAFE.getFloat(null, columnAddr + 
(i * 4L));
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                argument[i] = UdfUtils.UNSAFE.getFloat(null, columnAddr + (i * 
4L));
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertDoubleArg(boolean isNullable, int numRows, 
long nullMapAddr, long columnAddr) {
+        Double[] argument = new Double[numRows];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    argument[i] = UdfUtils.UNSAFE.getDouble(null, columnAddr + 
(i * 8L));
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                argument[i] = UdfUtils.UNSAFE.getDouble(null, columnAddr + (i 
* 8L));
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertDateArg(Class argTypeClass, boolean 
isNullable, int numRows, long nullMapAddr,
+            long columnAddr) {
+        Object[] argument = (Object[]) Array.newInstance(argTypeClass, 
numRows);
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    long value = UdfUtils.UNSAFE.getLong(null, columnAddr + (i 
* 8L));
+                    argument[i] = UdfUtils.convertDateToJavaDate(value, 
argTypeClass);
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                long value = UdfUtils.UNSAFE.getLong(null, columnAddr + (i * 
8L));
+                argument[i] = UdfUtils.convertDateToJavaDate(value, 
argTypeClass);
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertDateTimeArg(Class argTypeClass, boolean 
isNullable, int numRows, long nullMapAddr,
+            long columnAddr) {
+        Object[] argument = (Object[]) Array.newInstance(argTypeClass, 
numRows);
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    long value = UdfUtils.UNSAFE.getLong(null, columnAddr + (i 
* 8L));
+                    argument[i] = UdfUtils
+                            .convertDateTimeToJavaDateTime(value, 
argTypeClass);
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                long value = UdfUtils.UNSAFE.getLong(null, columnAddr + (i * 
8L));
+                argument[i] = UdfUtils.convertDateTimeToJavaDateTime(value, 
argTypeClass);
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertDateV2Arg(Class argTypeClass, boolean 
isNullable, int numRows, long nullMapAddr,
+            long columnAddr) {
+        Object[] argument = (Object[]) Array.newInstance(argTypeClass, 
numRows);
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    int value = UdfUtils.UNSAFE.getInt(null, columnAddr + (i * 
4L));
+                    argument[i] = UdfUtils.convertDateV2ToJavaDate(value, 
argTypeClass);
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                int value = UdfUtils.UNSAFE.getInt(null, columnAddr + (i * 
4L));
+                argument[i] = UdfUtils.convertDateV2ToJavaDate(value, 
argTypeClass);
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertDateTimeV2Arg(Class argTypeClass, boolean 
isNullable, int numRows, long nullMapAddr,
+            long columnAddr) {
+        Object[] argument = (Object[]) Array.newInstance(argTypeClass, 
numRows);
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(null, nullMapAddr + i) == 0) {
+                    long value = UdfUtils.UNSAFE.getLong(columnAddr + (i * 
8L));
+                    argument[i] = UdfUtils
+                            .convertDateTimeV2ToJavaDateTime(value, 
argTypeClass);
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                long value = UdfUtils.UNSAFE.getLong(null, columnAddr + (i * 
8L));
+                argument[i] = UdfUtils
+                        .convertDateTimeV2ToJavaDateTime(value, argTypeClass);
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertLargeIntArg(boolean isNullable, int numRows, 
long nullMapAddr, long columnAddr) {
+        BigInteger[] argument = new BigInteger[numRows];
+        byte[] bytes = new byte[16];
+        if (isNullable) {
+            for (int i = 0; i < numRows; ++i) {
+                if (UdfUtils.UNSAFE.getByte(nullMapAddr + i) == 0) {
+                    UdfUtils.copyMemory(null, columnAddr + (i * 16L), bytes, 
UdfUtils.BYTE_ARRAY_OFFSET, 16);
+                    argument[i] = new 
BigInteger(UdfUtils.convertByteOrder(bytes));
+                } // else is the current row is null
+            }
+        } else {
+            for (int i = 0; i < numRows; ++i) {
+                UdfUtils.copyMemory(null, columnAddr + (i * 16L), bytes, 
UdfUtils.BYTE_ARRAY_OFFSET, 16);
+                argument[i] = new BigInteger(UdfUtils.convertByteOrder(bytes));
+            }
+        }
+        return argument;
+    }
+
+    public static Object[] convertDecimalArg(int scale, long typeLen, boolean 
isNullable, int numRows, long nullMapAddr,
+            long columnAddr) {
+        BigDecimal[] argument = new BigDecimal[numRows];
+        byte[] bytes = new byte[(int) typeLen];
+        LOG.info("convertDecimalArg: " + scale + " " + typeLen + " " + 
isNullable + " " + numRows + " " + nullMapAddr

Review Comment:
   delete the info log



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