dawidwys commented on a change in pull request #12591:
URL: https://github.com/apache/flink/pull/12591#discussion_r439263035



##########
File path: 
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerGenericRecordTest.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.typeutils;
+
+import org.apache.flink.api.common.typeutils.SerializerTestBase;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.GenericRecordBuilder;
+
+/**
+ * Test for {@link AvroSerializer} that test GenericRecord.
+ */
+public class AvroSerializerGenericRecordTest extends 
SerializerTestBase<GenericRecord> {
+
+       static final Schema SCHEMA = new org.apache.avro.Schema.Parser()
+               
.parse("{\"type\":\"record\",\"name\":\"Dummy\",\"namespace\":\"dummy\",\"fields\":[{\"name\":\"afield\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}]}");

Review comment:
       Could you split the schema to keep a 120 characters line limit.

##########
File path: 
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerGenericRecordTest.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.typeutils;
+
+import org.apache.flink.api.common.typeutils.SerializerTestBase;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.GenericRecordBuilder;
+
+/**
+ * Test for {@link AvroSerializer} that test GenericRecord.
+ */
+public class AvroSerializerGenericRecordTest extends 
SerializerTestBase<GenericRecord> {
+
+       static final Schema SCHEMA = new org.apache.avro.Schema.Parser()
+               
.parse("{\"type\":\"record\",\"name\":\"Dummy\",\"namespace\":\"dummy\",\"fields\":[{\"name\":\"afield\",\"type\":{\"type\":\"string\",\"avro.java.string\":\"String\"}}]}");
+
+       @Override
+       protected TypeSerializer<GenericRecord> createSerializer() {
+               return new AvroSerializer<>(GenericRecord.class, SCHEMA);
+       }
+
+       @Override
+       protected int getLength() {
+               return -1;
+       }
+
+       @Override
+       protected Class<GenericRecord> getTypeClass() {
+               return GenericRecord.class;
+       }
+
+       @Override
+       protected GenericRecord[] getTestData() {
+               GenericRecord[] records = { new GenericRecordBuilder(SCHEMA)

Review comment:
       How about:
   
   ```
        @Override
        protected GenericRecord[] getTestData() {
                return new GenericRecord[]{
                        new GenericRecordBuilder(SCHEMA)
                                .set("afield", "foo bar")
                                .build()};
        }
   ```

##########
File path: 
flink-formats/flink-avro/src/test/java/org/apache/flink/formats/avro/typeutils/AvroSerializerGenericRecordTest.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.typeutils;
+
+import org.apache.flink.api.common.typeutils.SerializerTestBase;
+import org.apache.flink.api.common.typeutils.TypeSerializer;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.generic.GenericRecordBuilder;
+
+/**
+ * Test for {@link AvroSerializer} that test GenericRecord.
+ */
+public class AvroSerializerGenericRecordTest extends 
SerializerTestBase<GenericRecord> {
+
+       static final Schema SCHEMA = new org.apache.avro.Schema.Parser()

Review comment:
       It can be private.

##########
File path: 
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroSerializer.java
##########
@@ -170,7 +170,11 @@ public int getLength() {
 
        @Override
        public T createInstance() {
-               return InstantiationUtil.instantiate(type);
+               if (!isGenericRecord(type)) {

Review comment:
       Sorry, I have not run the code I posted before and I used the wrong 
field for schema. I think we can use the approach from the beginning of the 
discussion if we use the `runtimeSchema`:
   
   ```
        @Override
        @SuppressWarnings("unchecked")
        public T createInstance() {
                checkAvroInitialized();
                return (T) avroData.newRecord(null, runtimeSchema);
        }
   ```
   
   The `schema` field may not always be set as it is used for checkpointing and 
for `Specific/ReflectData` it will not be set from the beginning. The 
`runtimeSchema` is always set though.




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