wjfsdbd opened a new issue, #49995:
URL: https://github.com/apache/doris/issues/49995

   ### 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
   
   v3.0.4 docker images
   - apache/doris:fe-3.0.4
   - apache/doris:be-3.0.4
   
   ### What's Wrong?
   
   If `log.info()` called in functions of class `SimpleDemo`, result goes wrong 
due to disorder of functions.
   
   
![Image](https://github.com/user-attachments/assets/fc73a6c3-b383-4cc0-8d2a-d9877f09f05d)
   
   
![Image](https://github.com/user-attachments/assets/10c25fd1-3c36-4e01-998b-229e51a5fd40)
   
   ### What You Expected?
   
   Function calling chain should be in order.
   
   ### How to Reproduce?
   
   sql: 
   
   ```mysql
   
   CREATE GLOBAL AGGREGATE FUNCTION test_udwf(int) RETURNS int PROPERTIES (
     "file" = "file:///opt/udf/metrics-udf-1.0-SNAPSHOT.jar",
     "symbol" = "cn.uos.metrics.TestUDWF",
     "always_nullable" = "false",
     "type" = "JAVA_UDF"
   );
   
   with data(to_group, to_order, value) as (
     select
       distinct round(rand() * 2),
       round(rand() * 100),
       round(rand() * 10)
     from
       numbers("number" = "50")
   ),
   temp as (
     select
       *
     from
       data
     order by
       to_group,
       to_order,
       value
   )
   select
     *,
     test_udwf(value) over (
       partition by to_group
       order by
         to_order
     ) as test
   from
     temp;
   
   ``` 
   
   UDWF:
   
   ```java
   
   public class TestUDWF {
       Logger log = Logger.getLogger("SimpleDemo");
   
       //Need an inner class to store data
       /*required*/
       public static class State {
           /*some variables if you need */
           public int sum = 0;
       }
   
       /*required*/
       public State create() {
           /* here could do some init work if needed */
           log.info("Creating new state");
           return new State();
       }
   
       /*required*/
       public void destroy(State state) {
           /* here could do some destroy work if needed */
           log.info("Destroying state");
       }
   
       /*Not Required*/
       public void reset(State state) {
           /*if you want this udaf function can work with window function.*/
           /*Must impl this, it will be reset to init state after calculate 
every window frame*/
           log.info("Reseting state");
           state.sum = 0;
       }
   
       /*required*/
       //first argument is State, then other types your input
       public void add(State state, Integer val) throws Exception {
           log.info("Adding state: " + state.sum + ", val: " + val);
           /* here doing update work when input data*/
           if (val != null) {
               state.sum += val;
           }
       }
   
       /*required*/
       public void serialize(State state, DataOutputStream out) throws 
IOException {
           log.info("Serializing state: " + state.sum);
           /* serialize some data into buffer */
           out.writeInt(state.sum);
       }
   
       /*required*/
       public void deserialize(State state, DataInputStream in) throws 
IOException {
           /* deserialize get data from buffer before you put */
           log.info("Deserializing state before: " + state.sum);
           state.sum = in.readInt();
           log.info("Deserializing state after: " + state.sum);
       }
   
       /*required*/
       public void merge(State state, State rhs) throws Exception {
           log.info("Merging state: " + state.sum + ", rhs: " + rhs.sum);
           /* merge data from state */
           state.sum += rhs.sum;
       }
   
       /*required*/
       //return Type you defined
       public Integer getValue(State state) throws Exception {
           log.info("Getting value for state: " + state.sum);
           /* return finally result */
           return state.sum;
       }
   
   }
   ``` 
   
   ### Anything Else?
   
   _No response_
   
   ### 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: commits-unsubscr...@doris.apache.org.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