You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/06/27 07:18:55 UTC

[GitHub] [flink] Vancior commented on a diff in pull request #20040: [FLINK-28182][python][format] Support Avro generic record decoder

Vancior commented on code in PR #20040:
URL: https://github.com/apache/flink/pull/20040#discussion_r907051932


##########
flink-python/pyflink/fn_execution/coder_impl_slow.py:
##########
@@ -834,3 +837,26 @@ def _filter_data_views(self, row):
                 row[i][spec.field_index] = None
             i += 1
         return row
+
+
+class AvroCoderImpl(FieldCoderImpl):
+
+    def __init__(self, schema_string: str):
+        self._bytes_io = io.BytesIO()
+        self._decoder = FlinkAvroDecoder(self._bytes_io)
+        self._schema = avro_schema.parse(schema_string)
+        self._reader = FlinkAvroDatumReader(writer_schema=self._schema, reader_schema=self._schema)
+
+    def encode_to_stream(self, value, out_stream: OutputStream):
+        raise NotImplementedError()
+
+    def decode_from_stream(self, in_stream: InputStream, length: int = 0):
+        length = in_stream.read_int32()
+        if length <= 0:
+            return None
+        data = in_stream.read(length)
+        self._bytes_io.seek(0)
+        self._bytes_io.truncate(0)
+        self._bytes_io.write(data)
+        self._bytes_io.seek(0)

Review Comment:
   `_bytes_io` needs to set to start before passing it to avro reader, or the reader will only get no bytes, so this is necessary.



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

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org