Hi, Tucker



IIUC, this way is unsupported. You may try other way to work around it.




--

    Best!
    Xuyang





At 2024-05-17 00:22:57, "Tucker Harvey" <thar...@pinterest.com.INVALID> wrote:
>Hi Xuyang, 
>
>Thanks for your response. I can provide some better context, we are migrating 
>a use case to FlinkSQL and they want to do some query that has a UDF like 
>
>SELECT user_id,  
>       ARRAY_MAP(transactions, x -> x * 1.1) AS taxed_transactions  
>FROM users;
>
>Based on my understanding of the API for UDFs in Flink, this will not be 
>possible with the current framework?
>
>Best, 
>Tucker
>
>
>> On May 15, 2024, at 7:42 PM, Xuyang <xyzhong...@163.com> wrote:
>> 
>> 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