aljoscha commented on a change in pull request #9916: 
[FLINK-14408][Table-Planner]UDF's open method is invoked to initialize when sql 
is optimized in oldPlanner
URL: https://github.com/apache/flink/pull/9916#discussion_r335913580
 
 

 ##########
 File path: 
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/codegen/ExpressionReducer.scala
 ##########
 @@ -117,8 +128,18 @@ class ExpressionReducer(config: TableConfig)
       generatedFunction.code)
     val function = clazz.newInstance()
 
-    // execute
-    val reduced = function.map(EMPTY_ROW)
+    val richMapFunction = function match {
+      case r: RichMapFunction[Row, Row] => r
+      case _ => throw new TableException("RichMapFunction[Row, Row] required 
here")
+    }
+
+    val reduced = try {
+      richMapFunction.open(parameters)
+      // execute
+      richMapFunction.map(EMPTY_ROW)
+    } finally {
+      richMapFunction.close()
+    }
 
 Review comment:
   This can be simplified to
   ```
     val reduced = try {
         FunctionUtils.openFunction(function, parameters)
         function.map(EMPTY_ROW)
       } finally {
         FunctionUtils.closeFunction(function)
       }
   ```

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