You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Jingsong Lee (Jira)" <ji...@apache.org> on 2020/01/02 02:56:00 UTC
[jira] [Comment Edited] (FLINK-15452) Missing type coercion when
generating code with ScalarFunctionCallGen
[ https://issues.apache.org/jira/browse/FLINK-15452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17006545#comment-17006545 ]
Jingsong Lee edited comment on FLINK-15452 at 1/2/20 2:55 AM:
--------------------------------------------------------------
Hi [~Pie-He], thanks for your reporting. so this one is duplicated with FLINK-10965 ? Why just use it?
I think this is an improvement more than bug, so I change it to 1.11.
was (Author: lzljs3620320):
Hi [~Pie-He], so this one is duplicated with FLINK-10965 ? Why just use it?
I think this is an improvement more than bug, so I change it to 1.11.
> Missing type coercion when generating code with ScalarFunctionCallGen
> ---------------------------------------------------------------------
>
> Key: FLINK-15452
> URL: https://issues.apache.org/jira/browse/FLINK-15452
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Affects Versions: 1.9.0
> Reporter: Peijian He
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.9.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> I defined a UDF as follows:
> {code:java}
> class ScalarFunction1(val udfs: UDF1[Any, Any]) extends ScalarFunction {
> def eval(t1: Any): Any = {
> udfs.eval(t1)
> }
> override def open(context: FunctionContext): Unit = {
> udfs.open()
> }
> override def close(): Unit = {
> udfs.close()
> }
> override def getResultType(signature: Array[Class[_]]): typeinfo.TypeInformation[_] = {
> toDataType(udfs.getReturnType)
> }
> }
> {code}
>
> An examples of the parameter udfs is as follows:
>
> {code:java}
> public class IsNumber extends UDF1<String, Boolean> {
> @Override
> public void open() {
> }
> @Override
> public void close() {
> }
> @Override
> public Boolean eval(String str) {
> for (int i = 0; i < str.length(); i++){
> if (!Character.isDigit(str.charAt(i))){
> return false;
> }
> }
> return true;
> }
> }{code}
>
> In this case, function getResultType return Boolean, but I get error as follows:
> {code:java}
> Caused by: org.codehaus.commons.compiler.CompileException: Line 118, Column 10: Assignment conversion not possible from type "java.lang.Object" to type "java.lang.Boolean" at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:12124) at org.codehaus.janino.UnitCompiler.assignmentConversion(UnitCompiler.java:10975) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2578) at org.codehaus.janino.UnitCompiler.access$2700(UnitCompiler.java:215) at org.codehaus.janino.UnitCompiler$6.visitLocalVariableDeclarationStatement(UnitCompiler.java:1503) at org.codehaus.janino.UnitCompiler$6.visitLocalVariableDeclarationStatement(UnitCompiler.java:1487) at org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.java:3511) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487) at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357) at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822) at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:432) at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:215) at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:411) at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:406) at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1414) at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406) at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:378) at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237) at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465) at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:216) at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:207) at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:80) at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:75) at org.apache.flink.table.codegen.Compiler$class.compile(Compiler.scala:33) ... 10 more
> {code}
>
> Another case:
> if I remove getResultType method, it cause an error when using nested udf as follows,
> nested UDF:
> {code:java}
> CastBoolToString(IsNumber(topic))
> {code}
> CastBoolToString required Boolean type parameter, but got Object type.
> So caused error:
> {code:java}
> Caused by: org.codehaus.commons.compiler.CompileException: Line 118, Column 10: Assignment conversion not possible from type "java.lang.Object" to type "java.lang.Boolean"
> at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:12124)
> at org.codehaus.janino.UnitCompiler.assignmentConversion(UnitCompiler.java:10975)
> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:2578)
> at org.codehaus.janino.UnitCompiler.access$2700(UnitCompiler.java:215)
> at org.codehaus.janino.UnitCompiler$6.visitLocalVariableDeclarationStatement(UnitCompiler.java:1503)
> at org.codehaus.janino.UnitCompiler$6.visitLocalVariableDeclarationStatement(UnitCompiler.java:1487)
> at org.codehaus.janino.Java$LocalVariableDeclarationStatement.accept(Java.java:3511)
> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1487)
> at org.codehaus.janino.UnitCompiler.compileStatements(UnitCompiler.java:1567)
> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:3388)
> at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1357)
> at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:1330)
> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:822)
> at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:432)
> at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:215)
> at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:411)
> at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:406)
> at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1414)
> at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:406)
> at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:378)
> at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:237)
> at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:465)
> at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:216)
> at org.codehaus.janino.SimpleCompiler.cook(SimpleCompiler.java:207)
> at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:80)
> at org.codehaus.commons.compiler.Cookable.cook(Cookable.java:75)
> at org.apache.flink.table.codegen.Compiler$class.compile(Compiler.scala:33)
> ... 10 more
> {code}
>
>
> I found that the following code in org.apache.flink.table.codegen.calls.ScalarFunctionCallGen caused the error:
> {code:java}
> val functionCallCode =
> s"""
> |${parameters.map(_.code).mkString("\n")}
> |$resultTypeTerm $resultTerm = $functionReference.eval(
> | ${parameters.map(_.resultTerm).mkString(", ")});
> |""".stripMargin{code}
> if return type of $functionReference.eval is Object and $resultTypeTerm is Boolean, above error occurs.
> So add type coercion to solve the problem.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)