flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Zhuoluo Yang (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FLINK-5826) UDF/UDTF should support variable types and variable arguments
Date Fri, 17 Feb 2017 10:40:41 GMT

    [ https://issues.apache.org/jira/browse/FLINK-5826?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15871634#comment-15871634

Zhuoluo Yang commented on FLINK-5826:

Thanks [~jiangxw]. After some investigation on "CodeGenerator.scala". I think I can generate
different codes for a Scala "eval()". I'd like to try to do some coding on this.

> UDF/UDTF should support variable types and variable arguments
> -------------------------------------------------------------
>                 Key: FLINK-5826
>                 URL: https://issues.apache.org/jira/browse/FLINK-5826
>             Project: Flink
>          Issue Type: Improvement
>            Reporter: Zhuoluo Yang
>            Assignee: Zhuoluo Yang
> In some cases, UDF/UDTF should support variable types and variable arguments. Many UDF/UDTF
developers wish to make the # of arguments and types flexible to users. They try to make their
functions flexible.
> Thus, we should support the following styles of UDF/UDTFs.
> for example 1, in Java
> {code:java}
> public class SimpleUDF extends ScalarFunction {
> 	public int eval(Object... args) {
> 		// do something
> 	}
> }
> {code}
> for example 2, in Scala
> {code}
> class SimpleUDF extends ScalarFunction {
>   def eval(args: Any*): Int = {
>     // do something
>   }
> }
> {code}
> If we modify the code in UserDefinedFunctionUtils.getSignature() and make both signatures
pass. The first example will work normally. However, the second example will raise an exception.
> {noformat}
> Caused by: org.codehaus.commons.compiler.CompileException: Line 58, Column 0: No applicable
constructor/method found for actual parameters "java.lang.String"; candidates are: "public
java.lang.Object test.SimpleUDF.eval(scala.collection.Seq)"
>   at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:11523) ~[janino-3.0.6.jar:?]
>   at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:8679)
>   at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:8539) ~[janino-3.0.6.jar:?]
> {noformat} 
> The reason is that Scala will do a *sugary* modification to the signature of the method.
The mothod {code} def eval(args: Any*){code} will become {code}def eval(args: scala.collection.Seq<Any>){code}
in the class file. 
> The code generation has been done in Java. If we use java style {code}eval(Object...
args){code} to call the Scala method, it will raise the above exception.
> However, I can't always restrict users to use Java to write a UDF/UDTF. Any ideas in
variable types and variable arguments of Scala UDF/UDTFs to prevent the compilation failure?

This message was sent by Atlassian JIRA

View raw message