[
https://issues.apache.org/jira/browse/FLINK-4781?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15560958#comment-15560958
]
sunjincheng edited comment on FLINK-4781 at 10/10/16 1:40 AM:
--------------------------------------------------------------
see https://github.com/apache/flink/pull/2265
was (Author: sunjincheng121):
User can define own functions to apply on fields. Build-in UDFs includes md5,
length, concatWs, hash and so on.
To defind your own user defined function,
inherit from UDF class
define one or more evel function.
NOTE:
the eval method must be public and non-static.
eval should never be a void method.
eval method can be overload. Flink will choose the best match eval method to
call according to parameter types and number.
The following is a example of ABS:
{code}
public class UDFAbs extends UDF {
public Double eval(Double n) {
if (n == null) {
return null;
}
return Math.abs(n);
}
public Long eval(Long n) {
if (n == null) {
return null;
}
return Math.abs(n);
}
public Integer eval(Integer n) {
if (n == null) {
return null;
}
return Math.abs(n);
}
}
And in Scala Table API , we can use abs like this :
val abs = new UDFAbs()
val res = tab.select(‘a, abs(‘b), ‘c)
And in Java Table API, we can use abs like this:
tableEnv.registerFunction("abs", new UDFAbs())
table.select("a, abs(b)")
And in SQL:
tableEnv.registerFunction("abs", new UDFAbs())
tableEnv.sql("SELECT a, abs(b) FROM MyTable")
{code}
reference design:
https://docs.google.com/document/d/15iVc1781dxYWm3loVQlESYvMAxEzbbuVFPZWBYuY1Ek/edit#heading=h.ejqlg7wd1ea
> Add User Defined Function(UDF) API for Table API
> ------------------------------------------------
>
> Key: FLINK-4781
> URL: https://issues.apache.org/jira/browse/FLINK-4781
> Project: Flink
> Issue Type: New Feature
> Components: Table API & SQL
> Reporter: Shaoxuan Wang
> Assignee: sunjincheng
>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)