dawidwys commented on a change in pull request #11280: [FLINK-16377][table] 
Support inline user defined functions in expression dsl
URL: https://github.com/apache/flink/pull/11280#discussion_r397732107
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/plan/QueryOperationConverter.java
 ##########
 @@ -270,36 +273,69 @@ public RelNode visit(SortQueryOperation sort) {
                }
 
                @Override
-               public <U> RelNode visit(CalculatedQueryOperation<U> 
calculatedTable) {
-                       DataType resultType = 
fromLegacyInfoToDataType(calculatedTable.getResultType());
-                       TableFunction<?> tableFunction = 
calculatedTable.getTableFunction();
-                       String[] fieldNames = 
calculatedTable.getTableSchema().getFieldNames();
-
-                       TypedFlinkTableFunction function = new 
TypedFlinkTableFunction(
-                                       tableFunction, fieldNames, resultType);
-
+               public RelNode visit(CalculatedQueryOperation calculatedTable) {
+                       FunctionDefinition functionDefinition = 
calculatedTable.getFunctionDefinition();
+                       List<RexNode> parameters = 
convertToRexNodes(calculatedTable.getParameters());
                        FlinkTypeFactory typeFactory = 
relBuilder.getTypeFactory();
+                       if (functionDefinition instanceof 
TableFunctionDefinition) {
+                               return convertLegacyTableFunction(
+                                       calculatedTable,
+                                       (TableFunctionDefinition) 
functionDefinition,
+                                       parameters,
+                                       typeFactory);
+                       }
 
-                       TableSqlFunction sqlFunction = new TableSqlFunction(
-                                       
FunctionIdentifier.of(tableFunction.functionIdentifier()),
-                                       tableFunction.toString(),
-                                       tableFunction,
-                                       resultType,
+                       DataTypeFactory dataTypeFactory = 
relBuilder.getCluster()
+                               .getPlanner()
+                               .getContext()
+                               .unwrap(FlinkContext.class)
+                               .getCatalogManager()
+                               .getDataTypeFactory();
+                       return relBuilder.functionScan(
+                               BridgingSqlFunction.of(
+                                       dataTypeFactory,
                                        typeFactory,
-                                       function,
-                                       scala.Option.empty());
+                                       SqlKind.OTHER_FUNCTION,
+                                       calculatedTable.getFunctionIdentifier(),
+                                       calculatedTable.getFunctionDefinition(),
+                                       
calculatedTable.getFunctionDefinition().getTypeInference(dataTypeFactory)),
 
 Review comment:
   As far as I understand if we end up here it was already called once in the 
`ResolveCallByArgumentsRule`, so it succeeded at least once.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to