twalthr 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_r397278876
##########
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:
Same comment as in `UserDefinedFunctionConverterRule`. I think we should get
the inference earlier in the API. Otherwise a wrong implemented UDF fails quite
late.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services