wuchong commented on a change in pull request #11512:
URL: https://github.com/apache/flink/pull/11512#discussion_r411966790



##########
File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/codegen/GenerateUtils.scala
##########
@@ -204,39 +204,47 @@ object GenerateUtils {
   // --------------------------- General Generate Utils 
----------------------------------
 
   /**
-    * Generates a record declaration statement. The record can be any type of 
BaseRow or
-    * other types.
+    * Generates a record declaration statement, and add it to reusable member. 
The record
+    * can be any type of BaseRow or other types.
     * @param t  the record type
     * @param clazz  the specified class of the type (only used when RowType)
     * @param recordTerm the record term to be declared
     * @param recordWriterTerm the record writer term (only used when BinaryRow 
type)
-    * @return the record declaration statement
+    * @param ctx the code generator context
+    * @return the record initialization statement
     */
   def generateRecordStatement(
       t: LogicalType,
       clazz: Class[_],
       recordTerm: String,
-      recordWriterTerm: Option[String] = None): String = {
+      recordWriterTerm: Option[String] = None,
+      ctx: CodeGeneratorContext): String = {
     t match {
       case rt: RowType if clazz == classOf[BinaryRow] =>
         val writerTerm = recordWriterTerm.getOrElse(
           throw new CodeGenException("No writer is specified when writing 
BinaryRow record.")
         )
         val binaryRowWriter = className[BinaryRowWriter]
         val typeTerm = clazz.getCanonicalName
+        ctx.addReusableMember(s"final $typeTerm $recordTerm = new 
$typeTerm(${rt.getFieldCount});")
+        ctx.addReusableMember(
+          s"final $binaryRowWriter $writerTerm = new 
$binaryRowWriter($recordTerm);")
         s"""
-           |final $typeTerm $recordTerm = new $typeTerm(${rt.getFieldCount});
-           |final $binaryRowWriter $writerTerm = new 
$binaryRowWriter($recordTerm);
+           |$recordTerm = new $typeTerm(${rt.getFieldCount});
+           |$writerTerm = new $binaryRowWriter($recordTerm);

Review comment:
       If we always put it in member variables, we don't need the 
initialization statements anymore? 




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


Reply via email to