This is an automated email from the ASF dual-hosted git repository.

rskraba pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 7791b34  AVRO-2908: Skip enum using in.readEnum instead of in.readInt 
(#942)
7791b34 is described below

commit 7791b348c979453bb071bcb5189dcd400b5521b8
Author: Samir Khan <[email protected]>
AuthorDate: Thu Aug 13 04:23:34 2020 -0500

    AVRO-2908: Skip enum using in.readEnum instead of in.readInt (#942)
    
    * AVRO-2908: Skip enum using in.readEnum instead of in.readInt
    
    * AVRO-2908: Moved TestSkipEnumSchema to avro.generic
---
 .../apache/avro/generic/GenericDatumReader.java    |  2 +-
 .../apache/avro/generic/TestSkipEnumSchema.java    | 53 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

diff --git 
a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java 
b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
index 0f6cafe..83e5e80 100644
--- 
a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
+++ 
b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader.java
@@ -568,7 +568,7 @@ public class GenericDatumReader<D> implements 
DatumReader<D> {
         skip(field.schema(), in);
       break;
     case ENUM:
-      in.readInt();
+      in.readEnum();
       break;
     case ARRAY:
       Schema elementType = schema.getElementType();
diff --git 
a/lang/java/avro/src/test/java/org/apache/avro/generic/TestSkipEnumSchema.java 
b/lang/java/avro/src/test/java/org/apache/avro/generic/TestSkipEnumSchema.java
new file mode 100644
index 0000000..b05c7b8
--- /dev/null
+++ 
b/lang/java/avro/src/test/java/org/apache/avro/generic/TestSkipEnumSchema.java
@@ -0,0 +1,53 @@
+/*
+ * 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
+ *
+ *     https://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.avro.generic;
+
+import org.apache.avro.Schema;
+import org.apache.avro.SchemaBuilder;
+import org.apache.avro.generic.GenericData.EnumSymbol;
+import org.apache.avro.io.Decoder;
+import org.apache.avro.io.DecoderFactory;
+import org.apache.avro.io.Encoder;
+import org.apache.avro.io.EncoderFactory;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+/**
+ * See AVRO-2908
+ */
+public class TestSkipEnumSchema {
+  @Test
+  public void testSkipEnum() throws IOException {
+    Schema enumSchema = 
SchemaBuilder.builder().enumeration("enum").symbols("en1", "en2");
+    EnumSymbol enumSymbol = new EnumSymbol(enumSchema, "en1");
+
+    GenericDatumWriter<EnumSymbol> datumWriter = new 
GenericDatumWriter<>(enumSchema);
+    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+    Encoder encoder = EncoderFactory.get().validatingEncoder(enumSchema,
+        EncoderFactory.get().binaryEncoder(byteArrayOutputStream, null));
+    datumWriter.write(enumSymbol, encoder);
+    encoder.flush();
+
+    Decoder decoder = DecoderFactory.get().validatingDecoder(enumSchema,
+        
DecoderFactory.get().binaryDecoder(byteArrayOutputStream.toByteArray(), null));
+
+    GenericDatumReader.skip(enumSchema, decoder);
+  }
+}

Reply via email to