[ 
https://issues.apache.org/jira/browse/FLINK-9679?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16571404#comment-16571404
 ] 

ASF GitHub Bot commented on FLINK-9679:
---------------------------------------

dawidwys commented on a change in pull request #6259: [FLINK-9679] Implement 
AvroSerializationSchema
URL: https://github.com/apache/flink/pull/6259#discussion_r208168876
 
 

 ##########
 File path: 
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RegistryAvroSerializationSchema.java
 ##########
 @@ -0,0 +1,76 @@
+/*
+ * 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.formats.avro;
+
+import org.apache.avro.io.Encoder;
+import org.apache.avro.specific.SpecificRecord;
+
+import java.io.IOException;
+
+/**
+ * Serialization schema that serializes from Avro binary format.
+ *
+ * @param <T> type of record it produces
+ */
+public class RegistryAvroSerializationSchema<T> extends 
AvroSerializationSchema<T> {
+
+       private static final long serialVersionUID = -6766681879020862312L;
+
+       /** Provider for schema coder. Used for initializing in each task. */
+       private final SchemaCoder.SchemaCoderProvider schemaCoderProvider;
+
+       /** Class to serialize to. */
+       private final Class<T> recordClazz;
+
+       /**
+        * Creates Avro Serialization schema.
+        *
+        * @param recordClazz         class to which serialize which is
+        *                            {@link SpecificRecord}.
+        * @param schemaCoderProvider schema provider that allows instantiation 
of {@link SchemaCoder} that will be used for
+        *                            schema writing
+        */
+       public RegistryAvroSerializationSchema(Class<T> recordClazz, 
SchemaCoder.SchemaCoderProvider schemaCoderProvider) {
+               super(recordClazz);
+               this.schemaCoderProvider = schemaCoderProvider;
+               this.recordClazz = recordClazz;
+
+       }
+
+       @Override
+       public byte[] serialize(T object) {
+               checkAvroInitialized();
+
+               if (object == null) {
+                       return null;
+               } else {
+                       try {
+                               Encoder encoder = getEncoder();
+                               byte[] bytes = schemaCoderProvider.get()
+                                       .writeSchema(recordClazz, 
getOutputStream());
+                               getDatumWriter().write(object, encoder);
+                               encoder.flush();
+
+                               return bytes;
 
 Review comment:
   `bytes` contain only serialized schema without the object. You should return 
the contents of encoder.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Implement AvroSerializationSchema
> ---------------------------------
>
>                 Key: FLINK-9679
>                 URL: https://issues.apache.org/jira/browse/FLINK-9679
>             Project: Flink
>          Issue Type: Improvement
>    Affects Versions: 1.6.0
>            Reporter: Yazdan Shirvany
>            Assignee: Yazdan Shirvany
>            Priority: Major
>              Labels: pull-request-available
>
> Implement AvroSerializationSchema using Confluent Schema Registry



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to