YennyQ opened a new issue, #24647: URL: https://github.com/apache/doris/issues/24647
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no similar issues. ### Version The versions I have tried before: 1.2.3 2.0.1 ### What's Wrong? It seems that Doris' loading mechanism has some issues in both version 1.2.3 and 2.0.1. In version 1.2.3, the Java UDF function, after registration, gets reinitialized with every call, but after several restarts, it seems to suddenly stabilize and behaves as if loaded only once. In version 2.0.1, the Java UDF function consistently throws a 'ClassNotFoundException' after registration, even after several restarts, but sometimes it works correctly. When it works correctly, its behavior is consistent with version 1.2.3, where it gets reinitialized with every call. ### What You Expected? The expected outcome is that regardless of the version, the JAVA UDF function should register successfully and only initialize the UDF class once, ensuring stable calls. ### How to Reproduce? 1. Use the following code as a UDF JAR.: `package org.apache.doris.udf; import java.io.FileOutputStream; import java.io.IOException; import org.apache.hadoop.hive.ql.exec.UDF; public class AddOne extends UDF { static int needShareInt = 0; static { String data = "load "; try (FileOutputStream fos = new FileOutputStream("/tmp/udftest/output.txt")) { byte[] bytes = data.getBytes(); fos.write(bytes); } catch (IOException e) { e.printStackTrace(); } } public Integer evaluate(Integer value) { needShareInt += 1; try (FileOutputStream fos = new FileOutputStream("/tmp/udftest/output.txt", true)) { byte[] bytes = Integer.toString(needShareInt).getBytes(); fos.write(bytes); } catch (IOException e) { e.printStackTrace(); } return value == null ? null : value + needShareInt; } } ` 2. Register the above JAR package in Doris as a JAVA UDF function. For example: ` CREATE FUNCTION java_udf_add_one(int) RETURNS int PROPERTIES ( "file"="file:///root/java-udf-demo-jar-with-dependencies.jar", "symbol"="org.apache.doris.udf.AddOne", "always_nullable"="true", "type"="JAVA_UDF" ); ` 3. Repeatedly calling the Java UDF like `SELECT java_udf_add_one(1);` in version 1.2.3, you will notice that the needShareInt variable remains 1 with each call, and the output.txt file is also overwritten with each call. However, in version 2.0.1, it will throw a 'UdfRuntimeException: Unable to find class. CAUSED BY: ClassNotFoundException: org.apache.doris.udf.AddOne' error directly." 4. After several restarts (or some unknown conditions that I am not aware of, but I only performed restart actions) in version 1.2.3, this UDF suddenly started behaving as if it were loaded only once. It's evident that the needShareInt variable continues to increase persistently, and the content in the output.txt file keeps getting appended. However, in version 2.0.1, it still continues to throw the 'UdfRuntimeException: Unable to find class. CAUSED BY: ClassNotFoundException: org.apache.doris.udf.AddOne' error (perhaps I haven't restarted it enough times?). ### Anything Else? The correct behavior in version 1.2.3:   The behavior of being repeatedly initialized in both version 1.2.3 and 2.0.1:  The behavior of encountering errors in version 2.0.1:  ### Are you willing to submit PR? - [ ] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
