dianfu commented on a change in pull request #9977: [FLINK-14497][python] 
Support primitive data types in Python user-defined functions
URL: https://github.com/apache/flink/pull/9977#discussion_r338916249
 
 

 ##########
 File path: flink-python/pyflink/fn_execution/coder_impl.py
 ##########
 @@ -74,3 +77,109 @@ def read_null_mask(field_count, in_stream):
 
     def __repr__(self):
         return 'RowCoderImpl[%s]' % ', '.join(str(c) for c in 
self._field_coders)
+
+
+class LongCoderImpl(StreamCoderImpl):
+    def encode_to_stream(self, value, out_stream, nested):
+        out_stream.write_bigendian_int64(value)
+
+    def decode_from_stream(self, in_stream, nested):
+        return in_stream.read_bigendian_int64()
+
+
+class ByteCoderImpl(StreamCoderImpl):
+
+    def encode_to_stream(self, value, out_stream, nested):
+        out_stream.write_byte(value)
+
+    def decode_from_stream(self, in_stream, nested):
+        return int(in_stream.read_byte())
+
+
+class ShortCoderImpl(StreamCoderImpl):
+
+    def encode_to_stream(self, value, out_stream, nested):
+        out_stream.write(struct.pack('>h', value))
+
+    def decode_from_stream(self, in_stream, nested):
+        return struct.unpack('>h', in_stream.read(2))[0]
+
+
+class IntCoderImpl(StreamCoderImpl):
+    def encode_to_stream(self, value, out_stream, nested):
+        out_stream.write_bigendian_int32(value)
+
+    def decode_from_stream(self, in_stream, nested):
+        return in_stream.read_bigendian_int32()
+
+
+class BooleanCoderImpl(StreamCoderImpl):
+
+    def encode_to_stream(self, value, out_stream, nested):
+        out_stream.write_byte(value)
+
+    def decode_from_stream(self, in_stream, nested):
+        return not not in_stream.read_byte()
+
+
+class FloatCoderImpl(StreamCoderImpl):
+
+    def encode_to_stream(self, value, out_stream, nested):
+        out_stream.write(struct.pack('>f', value))
+
+    def decode_from_stream(self, in_stream, nested):
+        return struct.unpack('>f', in_stream.read(4))[0]
+
+
+class DoubleCoderImpl(StreamCoderImpl):
+
+    def encode_to_stream(self, value, out_stream, nested):
+        out_stream.write_bigendian_double(value)
+
+    def decode_from_stream(self, in_stream, nested):
+        return in_stream.read_bigendian_double()
+
+
+class BinaryCoderImpl(StreamCoderImpl):
+
+    def encode_to_stream(self, value, out_stream, nested):
+        if value is None:
+            raise ValueError("Serialized byte array value should not be None")
+        out_stream.write_bigendian_int32(len(value))
+        out_stream.write(value, False)
+
+    def decode_from_stream(self, in_stream, nested):
+        size = in_stream.read_bigendian_int32()
+        return in_stream.read(size)
+
+
+class StringCoderImpl(StreamCoderImpl):
+
+    def encode_to_stream(self, value, out_stream, nested):
+        if value is None:
 
 Review comment:
   Remove the null check

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