XU Nuo
06/28/2024, 3:25 AMCREATE in sql, and it seems like you can only define the name of UDFs. What I want to do is to initialize some objects at the start with parameters and access them in the eval without creating them everytime the function gets called. Do you have any advice on it? Maybe use SET or job parameters? Thank you in advanceD. Draco O'Brien
06/28/2024, 6:21 AM// Define a UDF with parameters
public static class MyParameterizedUDF extends ScalarFunction {
private final int param;
public MyParameterizedUDF(int param) {
this.param = param;
}
public Integer eval(Integer input) {
return input + param;
}
}
// In a TableEnvironment
TableEnvironment tableEnv = ...;
tableEnv.createTemporarySystemFunction("MyUDF", new MyParameterizedUDF(10)); // Parameter here
// Use in SQL
tableEnv.sqlQuery("SELECT MyUDF(column) FROM myTable");D. Draco O'Brien
06/28/2024, 6:22 AMflink-conf.yaml or passed programmatically) to set values that your UDF can access via getRuntimeContext().getExecutionConfig().getGlobalJobParameters(). This requires designing your UDF to fetch these parameters at runtime.XU Nuo
07/01/2024, 2:02 AM