HappenLee commented on code in PR #21388: URL: https://github.com/apache/doris/pull/21388#discussion_r1251437490
########## fe/be-java-extensions/java-udf/src/main/java/org/apache/doris/udf/UdfExecutor.java: ########## @@ -107,6 +111,407 @@ public void evaluate() throws UdfRuntimeException { } } + public Object[] convertBasicArguments(int argIdx, boolean isNullable, int numRows, long nullMapAddr, + long columnAddr, long strOffsetAddr) { + switch (argTypes[argIdx]) { + case BOOLEAN: + return UdfConvert.convertBooleanArg(isNullable, numRows, nullMapAddr, columnAddr); + case TINYINT: + return UdfConvert.convertTinyIntArg(isNullable, numRows, nullMapAddr, columnAddr); + case SMALLINT: + return UdfConvert.convertSmallIntArg(isNullable, numRows, nullMapAddr, columnAddr); + case INT: + return UdfConvert.convertIntArg(isNullable, numRows, nullMapAddr, columnAddr); + case BIGINT: + return UdfConvert.convertBigIntArg(isNullable, numRows, nullMapAddr, columnAddr); + case LARGEINT: + return UdfConvert.convertLargeIntArg(isNullable, numRows, nullMapAddr, columnAddr); + case FLOAT: + return UdfConvert.convertFloatArg(isNullable, numRows, nullMapAddr, columnAddr); + case DOUBLE: + return UdfConvert.convertDoubleArg(isNullable, numRows, nullMapAddr, columnAddr); + case CHAR: + case VARCHAR: + case STRING: + return UdfConvert.convertStringArg(isNullable, numRows, nullMapAddr, columnAddr, strOffsetAddr); + case DATE: // udaf maybe argClass[i + argClassOffset] need add +1 + return UdfConvert.convertDateArg(argClass[argIdx], isNullable, numRows, nullMapAddr, columnAddr); + case DATETIME: + return UdfConvert.convertDateTimeArg(argClass[argIdx], isNullable, numRows, nullMapAddr, columnAddr); + case DATEV2: + return UdfConvert.convertDateV2Arg(argClass[argIdx], isNullable, numRows, nullMapAddr, columnAddr); + case DATETIMEV2: + return UdfConvert.convertDateTimeV2Arg(argClass[argIdx], isNullable, numRows, nullMapAddr, columnAddr); + case DECIMALV2: + case DECIMAL128: + return UdfConvert.convertDecimalArg(argTypes[argIdx].getScale(), 16L, isNullable, numRows, nullMapAddr, + columnAddr); + case DECIMAL32: + return UdfConvert.convertDecimalArg(argTypes[argIdx].getScale(), 4L, isNullable, numRows, nullMapAddr, + columnAddr); + case DECIMAL64: + return UdfConvert.convertDecimalArg(argTypes[argIdx].getScale(), 8L, isNullable, numRows, nullMapAddr, + columnAddr); + default: + Preconditions.checkState(false, "Not support type: " + argTypes[argIdx].toString()); + LOG.info("Not support type: " + argTypes[argIdx].toString()); + break; + } + return null; + } + + + public Object[] convertArrayArguments(int argIdx, boolean isNullable, int numRows, long nullMapAddr, + long offsetsAddr, long nestedNullMapAddr, long dataAddr, long strOffsetAddr) { + Object[] argument = (Object[]) Array.newInstance(ArrayList.class, numRows); + for (int row = 0; row < numRows; ++row) { + long offsetStart = UdfUtils.UNSAFE.getLong(null, offsetsAddr + 8L * (row - 1)); + long offsetEnd = UdfUtils.UNSAFE.getLong(null, offsetsAddr + 8L * (row)); + int currentRowNum = (int) (offsetEnd - offsetStart); + switch (argTypes[argIdx].getItemType().getPrimitiveType()) { + case BOOLEAN: { + UdfConvert + .convertArrayBooleanArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case TINYINT: { + UdfConvert + .convertArrayTinyIntArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case SMALLINT: { + UdfConvert + .convertArraySmallIntArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case INT: { + UdfConvert.convertArrayIntArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case BIGINT: { + UdfConvert.convertArrayBigIntArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case LARGEINT: { + UdfConvert + .convertArrayLargeIntArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case FLOAT: { + UdfConvert.convertArrayFloatArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case DOUBLE: { + UdfConvert.convertArrayDoubleArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case CHAR: + case VARCHAR: + case STRING: { + UdfConvert.convertArrayStringArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr, strOffsetAddr); + break; + } + case DATE: { + UdfConvert.convertArrayDateArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case DATETIME: { + UdfConvert + .convertArrayDateTimeArg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case DATEV2: { + UdfConvert.convertArrayDateV2Arg(argument, row, currentRowNum, offsetStart, isNullable, nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case DATETIMEV2: { + UdfConvert.convertArrayDateTimeV2Arg(argument, row, currentRowNum, offsetStart, isNullable, + nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case DECIMALV2: + case DECIMAL128: { + UdfConvert.convertArrayDecimalArg(argTypes[argIdx].getScale(), 16L, argument, row, currentRowNum, + offsetStart, isNullable, + nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case DECIMAL32: { + UdfConvert.convertArrayDecimalArg(argTypes[argIdx].getScale(), 4L, argument, row, currentRowNum, + offsetStart, isNullable, + nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + case DECIMAL64: { + UdfConvert.convertArrayDecimalArg(argTypes[argIdx].getScale(), 8L, argument, row, currentRowNum, + offsetStart, isNullable, + nullMapAddr, + nestedNullMapAddr, dataAddr); + break; + } + default: { + Preconditions.checkState(false, "Not support type " + argTypes[argIdx].toString()); + LOG.info("Not support: " + argTypes[argIdx]); + break; + } + } + } + return argument; + } + + /** + * Evaluates the UDF with 'args' as the input to the UDF. + */ + public Object[] evaluate(int numRows, Object[] column) throws UdfRuntimeException { + try { + Object[] result = (Object[]) Array.newInstance(method.getReturnType(), numRows); + Object[][] inputs = (Object[][]) column; + Object[] parameters = new Object[inputs.length]; + for (int i = 0; i < numRows; ++i) { + for (int j = 0; j < column.length; ++j) { + parameters[j] = inputs[j][i]; + } + result[i] = method.invoke(udf, parameters); + } + return result; + } catch (Exception e) { + LOG.info("evaluate2 Exception" + e.toString()); Review Comment: evaluate2 ? -- 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