JingsongLi commented on a change in pull request #8762: 
[FLINK-12844][table-planner-blink] Use default conversion class 
LocalDate/LocalTime/LocalDateTime for DateType/TimeType/TimestampType in blink
URL: https://github.com/apache/flink/pull/8762#discussion_r300576303
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/codegen/CodeGeneratorContext.scala
 ##########
 @@ -457,19 +456,44 @@ class CodeGeneratorContext(val tableConfig: TableConfig) 
{
     fieldTerm
   }
 
+  /**
+    * Adds a reusable local date time to the beginning of the SAM of the 
generated class.
+    */
+  def addReusableLocalDateTime(): String = {
+    val fieldTerm = s"localtimestamp"
+
+    val timeZone = addReusableTimeZone()
+    val timestamp = addReusableTimestamp()
+
+    // declaration
+    reusableMemberStatements.add(s"private long $fieldTerm;")
+
+    // assignment
+    val field =
+      s"""
+         |$fieldTerm = $timestamp + $timeZone.getOffset($timestamp);
+         |""".stripMargin
+    reusablePerRecordStatements.add(field)
+    fieldTerm
+  }
+
   /**
     * Adds a reusable local time to the beginning of the SAM of the generated 
class.
     */
   def addReusableLocalTime(): String = {
     val fieldTerm = s"localtime"
-    val timeZone = addReusableTimeZone()
-    val localtimestamp = addReusableLocalTimestamp()
+
+    val localtimestamp = addReusableLocalDateTime()
+
+    // declaration
+    reusableMemberStatements.add(s"private int $fieldTerm;")
+
+    // assignment
     // adopted from org.apache.calcite.runtime.SqlFunctions.localTime()
     val field =
-      s"""
-         |final int $fieldTerm = (int) ( ($localtimestamp + 
$timeZone.getOffset($localtimestamp))
-         |                              % ${DateTimeUtils.MILLIS_PER_DAY});
-         |""".stripMargin
+    s"""
+       |$fieldTerm = (int) ($localtimestamp % ${DateTimeUtils.MILLIS_PER_DAY});
+       |""".stripMargin
 
 Review comment:
   It is come from `System.currentTimeMillis`, I think it will never be 
negative.

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