flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "sunjincheng (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (FLINK-4781) Add User Defined Function(UDF) API for Table API
Date Mon, 10 Oct 2016 02:12:20 GMT

    [ 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 2:11 AM:
--------------------------------------------------------------

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 Power:

{code}
public class PowerUDF extends UDF {

    public double eval(double t, double v) {
        return Math.pow(t, v);
    }

    public double eval(long t, long v) {
        return Math.pow(t, v);
    }

    public double eval(long t, int v) {
        return Math.pow(t, v);
    }
And in Scala Table API , we can use power like this : 

val mypower = new PowerUDF()
val res = tab.select(‘a, mypower('a, 4) , ‘c)

And in Java Table API, we can use power like this:

tableEnv.registerFunction("mypower", new PowerUDF())
table.select("a, mypower(b, 4)")

And in SQL:

tableEnv.registerFunction("mypower", new PowerUDF())
tableEnv.sql("SELECT a, mypower(b,4) FROM MyTable")
{code}
 **have the same goal with FLINK-3097**


was (Author: sunjincheng121):
**This issue is blocked by CALCITE-1309, so we need to wait Calcite fix this and release.**

> 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)

Mime
View raw message