Hi, Tucker.

Could you provide some examples of how you use lambda expressions? 

Currently, if you try to use a lambda expression as a member variable of a UDF 
class, it will fail because UDF

classes are required to be serializable, and lambda expressions are not 
serializable.




However, there are workarounds, such as marking the lambda member variable 
function with the transient modifier

to prevent it from being serialized, and initializing the function in the 
overridden open method.




I've provided an example below:




```

public class JavaFunc22 extends ScalarFunction {




    transient Function<String, String> f;




    @Override

    public void open(FunctionContext context) throws Exception {

        f = str -> str + ":test";

    }




    public String eval(String s) {

        return f.apply(s);

    }

}




```




--

    Best!
    Xuyang





在 2024-05-15 23:49:50,"Tucker Harvey" <thar...@pinterest.com.INVALID> 写道:
>Hi Flink Community,
>
>I’m writing to confirm whether lambda expressions are supported with User 
>Defined Functions (UDFs) in FlinkSQL and the Table API. My current 
>understanding is that they are not supported.
>Can anyone verify this, or let me know if there have been any recent changes 
>regarding this?
>Thanks for your help.
>
>Best regards,
>Tucker

Reply via email to