dianfu commented on a change in pull request #14401:
URL: https://github.com/apache/flink/pull/14401#discussion_r545551111



##########
File path: flink-python/pyflink/common/typeinfo.py
##########
@@ -91,66 +73,117 @@ def from_internal_type(self, obj):
         return obj
 
 
-class BasicTypeInfo(TypeInformation, ABC):
+class BasicTypes(Enum):
+    STRING = "String"
+    BYTE = "Byte"
+    BOOLEAN = "Boolean"
+    SHORT = "Short"
+    INT = "Integer"
+    LONG = "Long"
+    FLOAT = "Float"
+    DOUBLE = "Double"
+    CHAR = "Char"
+    BIG_INT = "BigInteger"
+    BIG_DEC = "BigDecimal"
+
+
+class BasicTypeInformation(TypeInformation, ABC):
     """
     Type information for primitive types (int, long, double, byte, ...), 
String, BigInteger,
     and BigDecimal.
     """
 
+    def __init__(self, basic_type: BasicTypes):
+        self._basic_type = basic_type
+        super(BasicTypeInformation, self).__init__()
+
+    def get_java_type_info(self) -> JavaObject:

Review comment:
       Could we refactor it a bit to make it more simple, e.g. introducing 
JBasicTypeInfo?
   ```
   JBasicTypeInfo = 
get_gateway().jvm.org.apache.flink.api.common.typeinfo.BasicTypeInfo
   ```

##########
File path: flink-python/pyflink/common/typeinfo.py
##########
@@ -431,45 +430,47 @@ def from_internal_type(self, obj):
         return tuple(values)
 
 
-class TupleTypeInfo(WrapperTypeInfo):
+class TupleTypeInfo(TypeInformation):
     """
     TypeInformation for Tuple.
     """
 
     def __init__(self, types: List[TypeInformation]):
         self.types = types
+        super(TupleTypeInfo, self).__init__()
+
+    def get_field_types(self) -> List[TypeInformation]:
+        return self.types
+
+    def get_java_type_info(self) -> JavaObject:
         j_types_array = get_gateway().new_array(
-            
get_gateway().jvm.org.apache.flink.api.common.typeinfo.TypeInformation, 
len(types))
+            
get_gateway().jvm.org.apache.flink.api.common.typeinfo.TypeInformation, 
len(self.types))
 
-        for i in range(len(types)):
-            field_type = types[i]
-            if isinstance(field_type, WrapperTypeInfo):
+        for i in range(len(self.types)):
+            field_type = self.types[i]
+            if isinstance(field_type, TypeInformation):
                 j_types_array[i] = field_type.get_java_type_info()
 
-        j_typeinfo = get_gateway().jvm \
+        self._j_typeinfo = get_gateway().jvm \
             .org.apache.flink.api.java.typeutils.TupleTypeInfo(j_types_array)
-        super(TupleTypeInfo, self).__init__(j_typeinfo=j_typeinfo)
-
-    def get_field_types(self) -> List[TypeInformation]:
-        return self.types
+        return self._j_typeinfo
 
     def __eq__(self, other) -> bool:
-        return self._j_typeinfo.equals(other._j_typeinfo)
-
-    def __hash__(self) -> int:
-        return self._j_typeinfo.hashCode()
+        if isinstance(other, TupleTypeInfo):
+            return self.types == other.types
+        return False
 
     def __str__(self) -> str:
-        return "TupleTypeInfo(%s)" % ', '.join([field_type.__str__() for 
field_type in self.types])
+        return "TupleTypeInfo(%s)" % ', '.join([str(field_type) for field_type 
in self.types])
 
 
-class DateTypeInfo(WrapperTypeInfo):
+class DateTypeInformation(TypeInformation):

Review comment:
       Why rename it?

##########
File path: flink-python/pyflink/common/typeinfo.py
##########
@@ -484,17 +485,25 @@ def from_internal_type(self, v):
         if v is not None:
             return datetime.date.fromordinal(v + self.EPOCH_ORDINAL)
 
+    def get_java_type_info(self) -> JavaObject:
+        self._j_typeinfo = get_gateway().jvm\

Review comment:
       I guess it could be cached to avoid computed again if called multiple 
times?

##########
File path: flink-python/pyflink/common/typeinfo.py
##########
@@ -48,30 +48,12 @@ class acts as the tool to generate serializers and 
comparators, and to perform s
     nested types).
     """
 
-
-class WrapperTypeInfo(TypeInformation):
-    """
-    A wrapper class for java TypeInformation Objects.
-    """
-
-    def __init__(self, j_typeinfo):
-        self._j_typeinfo = j_typeinfo
+    def __init__(self):
+        self._j_typeinfo = None
 
     def get_java_type_info(self) -> JavaObject:

Review comment:
       +1. I have the same feeling.

##########
File path: flink-python/pyflink/common/typeinfo.py
##########
@@ -91,66 +73,117 @@ def from_internal_type(self, obj):
         return obj
 
 
-class BasicTypeInfo(TypeInformation, ABC):
+class BasicTypes(Enum):
+    STRING = "String"
+    BYTE = "Byte"
+    BOOLEAN = "Boolean"
+    SHORT = "Short"
+    INT = "Integer"
+    LONG = "Long"
+    FLOAT = "Float"
+    DOUBLE = "Double"
+    CHAR = "Char"
+    BIG_INT = "BigInteger"
+    BIG_DEC = "BigDecimal"
+
+
+class BasicTypeInformation(TypeInformation, ABC):

Review comment:
       Why rename it to BasicTypeInformation?




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


Reply via email to