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_r397276251
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/java/org/apache/flink/table/planner/expressions/converter/UserDefinedFunctionConvertRule.java
 ##########
 @@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.expressions.converter;
+
+import org.apache.flink.table.expressions.ApiExpressionUtils;
+import org.apache.flink.table.expressions.CallExpression;
+import org.apache.flink.table.functions.UserDefinedFunction;
+import org.apache.flink.table.planner.functions.bridging.BridgingSqlFunction;
+
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.sql.SqlKind;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * A call expression converter rule that converts calls to user defined 
functions.
+ */
+public class UserDefinedFunctionConvertRule implements 
CallExpressionConvertRule {
+       @Override
+       public Optional<RexNode> convert(
+                       CallExpression call,
+                       ConvertContext context) {
+               if (!(call.getFunctionDefinition() instanceof 
UserDefinedFunction)) {
+                       return Optional.empty();
+               }
+
+               switch (call.getFunctionDefinition().getKind()) {
+                       case SCALAR:
+                       case TABLE:
+                               List<RexNode> args = 
call.getChildren().stream().map(context::toRexNode).collect(Collectors.toList());
+                               return Optional.of(context.getRelBuilder().call(
+                                       BridgingSqlFunction.of(
+                                               context.getDataTypeFactory(),
+                                               context.getTypeFactory(),
+                                               SqlKind.OTHER_FUNCTION,
+                                               
ApiExpressionUtils.getFunctionIdentifier(call),
 
 Review comment:
   It seems wrong to me that we are using ApiUtils in the planner. This should 
be done earlier when constructing the call.

----------------------------------------------------------------
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

Reply via email to