You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@flink.apache.org by "1095193290@qq.com" <10...@qq.com> on 2021/08/03 17:02:28 UTC

How to use 'CREATE FUNCTION' statements to create parameterize functions?

Hi community,
For parameterize function, like 
public static class SubstringFunction extends ScalarFunction {
 
  private boolean endInclusive;
 
  public SubstringFunction(boolean endInclusive) {
    this.endInclusive = endInclusive;
  }
 
  public String eval(String s, Integer begin, Integer end) {
    return s.substring(begin, endInclusive ? end + 1 : end);
  }
}
we can register this function by pass function instance instead of function classes.
env.createTemporarySystemFunction("SubstringFunction", new SubstringFunction(true));
How to register or create this parameterize  function with 'CREATE FUNTION' statements.
With standard 'CREATE FUNCTION' statement in Flink doc.[1]
CREATE [TEMPORARY|TEMPORARY SYSTEM] FUNCTION 
  [IF NOT EXISTS] [catalog_name.][db_name.]function_name 
  AS identifier [LANGUAGE JAVA|SCALA|PYTHON]
We can only pass function_name in CREATE FUNCTION statement, is there way to pass function_instance ( parameterize function ) in this statement. 

[1]https://ci.apache.org/projects/flink/flink-docs-release-1.13/docs/dev/table/sql/create/#create-function 



1095193290@qq.com

Re: How to use 'CREATE FUNCTION' statements to create parameterize functions?

Posted by Ingo Bürk <in...@ververica.com>.
Hi,

SQL only offers DDL to register function classes, not instances. Such
functions must have a default constructor. You can create a class extending
your function and calling the super constructor with the respective
arguments and then use that class through the DDL.


Best
Ingo

On Tue, Aug 3, 2021, 19:02 1095193290@qq.com <10...@qq.com> wrote:

> Hi community,
>
> For parameterize function, like
>
> *public* *static* *class* *SubstringFunction* *extends* ScalarFunction *{*
>
>
>
>   *private* *boolean* endInclusive*;*
>
>
>
>   *public* *SubstringFunction**(**boolean* endInclusive*)* *{*
>
>     *this.*endInclusive *=* endInclusive*;*
>
>   *}*
>
>
>
>   *public* String *eval**(*String s*,* Integer begin*,* Integer end*)* *{*
>
>     *return* s*.*substring*(*begin*,* endInclusive *?* end *+* 1 *:* end
> *);*
>
>   *}*
>
> *}*
>
> we can register this function by pass function instance instead of
> function classes.
>
> *env**.**createTemporarySystemFunction**(**"SubstringFunction"**,* *new*
> *SubstringFunction**(true));*
>
> How to register or create this parameterize  function with 'CREATE
> FUNTION' statements.
>
> With standard 'CREATE FUNCTION' statement in Flink doc.[1]
>
> *CREATE [TEMPORARY|TEMPORARY SYSTEM] FUNCTION *
>
> *  [IF NOT EXISTS] [catalog_name.][db_name.]function_name *
>
> *  AS identifier [LANGUAGE JAVA|SCALA|PYTHON]*
>
> We can only pass function_name in CREATE FUNCTION statement, is there way
> to pass function_instance ( parameterize function ) in this statement.
>
>
> *[1]*
> https://ci.apache.org/projects/flink/flink-docs-release-1.13/docs/dev/table/sql/create/#create-function
>
>
>
> ------------------------------
> 1095193290@qq.com
>