[ https://issues.apache.org/jira/browse/FLINK-16414?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jark Wu reassigned FLINK-16414: ------------------------------- Assignee: Terry Wang > create udaf/udtf function using sql casuing ValidationException: SQL > validation failed. null > -------------------------------------------------------------------------------------------- > > Key: FLINK-16414 > URL: https://issues.apache.org/jira/browse/FLINK-16414 > Project: Flink > Issue Type: Bug > Components: Table SQL / API > Affects Versions: 1.10.0 > Reporter: Terry Wang > Assignee: Terry Wang > Priority: Critical > Labels: pull-request-available > Fix For: 1.10.1 > > Time Spent: 10m > Remaining Estimate: 0h > > When using TableEnvironment#sqlupdate to create a udaf or udtf function, > which doesn't override the getResultType() method, it's normal. But when > using this function in later insert sql, some exception like following will > be throwed: > Exception in thread "main" org.apache.flink.table.api.ValidationException: > SQL validation failed. null > at > org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$validate(FlinkPlannerImpl.scala:130) > at > org.apache.flink.table.planner.calcite.FlinkPlannerImpl.validate(FlinkPlannerImpl.scala:105) > at > org.apache.flink.table.planner.operations.SqlToOperationConverter.convert(SqlToOperationConverter.java:127) > at > org.apache.flink.table.planner.operations.SqlToOperationConverter.convertSqlInsert(SqlToOperationConverter.java:342) > at > org.apache.flink.table.planner.operations.SqlToOperationConverter.convert(SqlToOperationConverter.java:142) > at > org.apache.flink.table.planner.delegation.ParserImpl.parse(ParserImpl.java:66) > at > org.apache.flink.table.api.internal.TableEnvironmentImpl.sqlUpdate(TableEnvironmentImpl.java:484) > The reason is in FunctionDefinitionUtil#createFunctionDefinition, we > shouldn't direct call t.getResultType or a.getAccumulatorType() or > a.getResultType() but using > UserDefinedFunctionHelper#getReturnTypeOfTableFunction > UserDefinedFunctionHelper#getAccumulatorTypeOfAggregateFunction > UserDefinedFunctionHelper#getReturnTypeOfAggregateFunction instead. > ``` > if (udf instanceof ScalarFunction) { > return new ScalarFunctionDefinition( > name, > (ScalarFunction) udf > ); > } else if (udf instanceof TableFunction) { > TableFunction t = (TableFunction) udf; > return new TableFunctionDefinition( > name, > t, > t.getResultType() > ); > } else if (udf instanceof AggregateFunction) { > AggregateFunction a = (AggregateFunction) udf; > return new AggregateFunctionDefinition( > name, > a, > a.getAccumulatorType(), > a.getResultType() > ); > } else if (udf instanceof TableAggregateFunction) { > TableAggregateFunction a = (TableAggregateFunction) udf; > return new TableAggregateFunctionDefinition( > name, > a, > a.getAccumulatorType(), > a.getResultType() > ); > ``` -- This message was sent by Atlassian Jira (v8.3.4#803005)