JingsongLi commented on a change in pull request #7906: 
[FLINK-11830][table-planner-blink] Introduce CodeGeneratorContext to maintain 
reusable statements
URL: https://github.com/apache/flink/pull/7906#discussion_r262782592
 
 

 ##########
 File path: 
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/codegen/CodeGenUtils.scala
 ##########
 @@ -0,0 +1,248 @@
+/*
+ * 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.codegen
+
+import org.apache.flink.api.common.typeinfo.PrimitiveArrayTypeInfo._
+import org.apache.flink.api.common.typeinfo.TypeInformation
+import org.apache.flink.table.`type`._
+import org.apache.flink.table.dataformat._
+import org.apache.flink.table.typeutils.TypeCheckUtils
+
+import java.lang.reflect.Method
+import java.lang.{Boolean => JBoolean, Byte => JByte, Character => JChar, 
Double => JDouble, Float => JFloat, Integer => JInt, Long => JLong, Short => 
JShort}
+import java.util.concurrent.atomic.AtomicInteger
+
+object CodeGenUtils {
+
+  // ------------------------------- DEFAULT TERMS 
------------------------------------------
+
+  val DEFAULT_TIMEZONE_TERM = "timeZone"
+
+  // -------------------------- CANONICAL CLASS NAMES 
---------------------------------------
+
+  val BINARY_ROW: String = className[BinaryRow]
+  val BINARY_STRING: String = className[BinaryString]
+  val BASE_ROW: String = className[BaseRow]
+  val GENERIC_ROW: String = className[GenericRow]
+
+  // 
----------------------------------------------------------------------------------------
+
+  private val nameCounter = new AtomicInteger
+
+  def newName(name: String): String = {
+    s"$name$$${nameCounter.getAndIncrement}"
+  }
+
+  def newNames(names: String*): Seq[String] = {
+    require(names.toSet.size == names.length, "Duplicated names")
+    val newId = nameCounter.getAndIncrement
+    names.map(name => s"$name$$$newId")
+  }
+
+  /**
+    * Retrieve the canonical name of a class type.
+    */
+  def className[T](implicit m: Manifest[T]): String = 
m.runtimeClass.getCanonicalName
+
+  def needCopyForType(t: InternalType): Boolean = t match {
+    case InternalTypes.STRING => true
+    case _: ArrayType => true
+    case _: MapType => true
+    case _: RowType => true
+    case _: GenericType[_] => true
+    case _ => false
+  }
+
+  def needCloneRefForType(t: InternalType): Boolean = t match {
+    case InternalTypes.STRING => true
+    case _ => false
+  }
+
+  // when casting we first need to unbox Primitives, for example,
+  // float a = 1.0f;
+  // byte b = (byte) a;
+  // works, but for boxed types we need this:
+  // Float a = 1.0f;
+  // Byte b = (byte)(float) a;
+  def primitiveTypeTermForType(t: InternalType): String = t match {
+    case InternalTypes.INT => "int"
+    case InternalTypes.LONG => "long"
+    case InternalTypes.SHORT => "short"
+    case InternalTypes.BYTE => "byte"
+    case InternalTypes.FLOAT => "float"
+    case InternalTypes.DOUBLE => "double"
+    case InternalTypes.BOOLEAN => "boolean"
+    case InternalTypes.CHAR => "char"
+
+    case InternalTypes.DATE => "int"
+    case InternalTypes.TIME => "int"
+    case InternalTypes.TIMESTAMP => "long"
+
+    // TODO: support INTERVAL_MONTHS and INTERVAL_MILLIS in the future
+
+    case _ => boxedTypeTermForType(t)
+  }
+
+  def boxedTypeTermForType(t: InternalType): String = t match {
+    case InternalTypes.INT => classOf[JInt].getCanonicalName
+    case InternalTypes.LONG => classOf[JLong].getCanonicalName
+    case InternalTypes.SHORT => classOf[JShort].getCanonicalName
+    case InternalTypes.BYTE => classOf[JByte].getCanonicalName
+    case InternalTypes.FLOAT => classOf[JFloat].getCanonicalName
+    case InternalTypes.DOUBLE => classOf[JDouble].getCanonicalName
+    case InternalTypes.BOOLEAN => classOf[JBoolean].getCanonicalName
+    case InternalTypes.CHAR => classOf[JChar].getCanonicalName
+
+    case InternalTypes.DATE => boxedTypeTermForType(InternalTypes.INT)
+    case InternalTypes.TIME => boxedTypeTermForType(InternalTypes.INT)
+    case InternalTypes.TIMESTAMP => boxedTypeTermForType(InternalTypes.LONG)
+
+    case InternalTypes.STRING => BINARY_STRING
+    case InternalTypes.BINARY => "byte[]"
 
 Review comment:
   InternalTypes.BINARY is ArrayType, remove it, let ArrayType do.

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