[
https://issues.apache.org/jira/browse/FLINK-5571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15853872#comment-15853872
]
ASF GitHub Bot commented on FLINK-5571:
---------------------------------------
Github user wuchong commented on a diff in the pull request:
https://github.com/apache/flink/pull/3176#discussion_r99568239
--- Diff:
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/UserDefinedFunction.scala
---
@@ -24,4 +24,19 @@ package org.apache.flink.table.functions
* User-defined functions must have a default constructor and must be
instantiable during runtime.
*/
trait UserDefinedFunction {
--- End diff --
Did you create a Java class which extends `ScalarFunction` or
`TableFunction` ? I tried this in my environment but the compiling is failed.
```java
public class MyScalarFunction extends ScalarFunction {
public int eval(int a) {
return a + 1;
}
}
```
```
Error:(25, 8) java:
org.apache.flink.table.examples.java.MyScalarFunction不是抽象的,
并且未覆盖org.apache.flink.table.functions.UserDefinedFunction中的抽象方法close()
```
> add open and close methods for UserDefinedFunction in TableAPI & SQL
> --------------------------------------------------------------------
>
> Key: FLINK-5571
> URL: https://issues.apache.org/jira/browse/FLINK-5571
> Project: Flink
> Issue Type: New Feature
> Components: Table API & SQL
> Reporter: godfrey he
> Assignee: godfrey he
>
> Currently, a User Defined Function (UDF) in table API & SQL works on zero,
> one, or multiple values in custom evaluation method. Many UDFs need more
> complex features, e.g. report metrics, get parameters from job configuration,
> or get extra data from distribute cache file, etc. Adding open and close
> methods in UserDefinedFunction class can solve this problem. The code cloud
> look like:
> {code}
> trait UserDefinedFunction {
> def open(context: UDFContext): Unit = {}
> def close(): Unit = {}
> }
> {code}
> UDFContext contains the information about metric reporters, job parameters,
> distribute cache, etc. The code cloud look like:
> {code}
> class UDFContext(context: RuntimeContext) {
> def getMetricGroup: MetricGroup = ???
> def getDistributedCacheFile(name: String): File = ???
> def getJobParameter(key: String, default: String): String = ???
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)