avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From th...@apache.org
Subject [avro] 09/14: Advancer and GenericDatumeReader2 now compile
Date Wed, 01 May 2019 19:11:19 GMT
This is an automated email from the ASF dual-hosted git repository.

thiru pushed a commit to branch fast-decoder-thiru
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 3fe8df68990f145380c3acee237c5d7539a21a0f
Author: rstata <rstata@yahoo.com>
AuthorDate: Tue Apr 30 12:24:47 2019 -0700

    Advancer and GenericDatumeReader2 now compile
---
 .../java/org/apache/avro/generic/Advancer.java     |  8 +++----
 .../apache/avro/generic/GenericDatumReader2.java   | 28 ++++++++++++++++++----
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/Advancer.java b/lang/java/avro/src/main/java/org/apache/avro/generic/Advancer.java
index 4fe3d7b..8f2b010 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/Advancer.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/Advancer.java
@@ -223,7 +223,7 @@ abstract class Advancer {
     * to use to read an array of int:
     *
     * <pre>
-    *   Advancer.Container c = advancer.getContainerAdvancer(in);
+    *   Advancer c = advancer.getContainerAdvancer(in);
     *   Advancer.Container ec = c.getElementAdvancer(in);
     *   for(long i = c.firstChunk(in); i != 0; i = c.nextChunk(in)) {
     *     for (long j = 0; j < i; j++) {
@@ -244,8 +244,7 @@ abstract class Advancer {
   }
 
   private static class ArrayContainer extends Container {
-    private final Advancer elementAdvancer;
-    public ArrayContainer(Advancer elementAdvancer) { super(elementAdvancer); }
+    public ArrayContainer(Advancer ea) { super(ea); }
     public long firstChunk(Decoder in) throws IOException
       { return in.readArrayStart(); }
     public long nextChunk(Decoder in) throws IOException
@@ -253,8 +252,7 @@ abstract class Advancer {
   }
 
   private static class MapContainer extends Container {
-    private final Advancer elementAdvancer;
-    public MapContainer(Advancer elementAdvancer) { super(elementAdvancer); }
+    public MapContainer(Advancer ea) { super(ea); }
     public long firstChunk(Decoder in) throws IOException
       { return in.readMapStart(); }
     public long nextChunk(Decoder in) throws IOException
diff --git a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader2.java
b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader2.java
index d86b038..46506c2 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader2.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/generic/GenericDatumReader2.java
@@ -19,17 +19,21 @@ package org.apache.avro.generic;
 
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.util.List;
 
 import org.apache.avro.Resolver;
 import org.apache.avro.Schema;
 import org.apache.avro.io.DatumReader;
 import org.apache.avro.io.Decoder;
 
-public class GenericDatumReader2<D> implements DatumReader<D> {
+public class GenericDatumReader2<D extends IndexedRecord> implements DatumReader<D>
{
+  private final Schema reader, writer;
   private final Advancer.Record advancer;
   private final GenericData data;
 
-  private GenericDatumReader2(Advancer.Record a, GenericData d) {
+  private GenericDatumReader2(Schema writer, Schema reader, Advancer.Record a, GenericData
d) {
+    this.writer = writer;
+    this.reader = reader;
     advancer = a;
     data = d;
   }
@@ -38,15 +42,18 @@ public class GenericDatumReader2<D> implements DatumReader<D>
{
     // TODO: add caching
     Resolver.Action a = Resolver.resolve(writer, reader, data);
     Advancer.Record r = (Advancer.Record)Advancer.from(a);
-    return new GenericDatumReader2(r, data);
+    return new GenericDatumReader2(writer, reader, r, data);
   }
 
   public D read(D reuse, Decoder in) throws IOException {
+    List<Schema.Field> wf = writer.getFields();
+    if (reuse == null) reuse = null; // FIXME
     for (int i = 0; i < advancer.advancers.length; i++) {
       int p = advancer.readerOrder[i].pos();
-      reuse.set(p, read(in, null, advancer.advancers[i]));
+      reuse.put(p, read(null, wf.get(i).schema(), advancer.advancers[i], in));
     }
     advancer.done(in);
+    return reuse;
   }
 
   public Object read(Object reuse, Schema expected, Advancer a, Decoder in)
@@ -62,7 +69,18 @@ public class GenericDatumReader2<D> implements DatumReader<D>
{
     case STRING: return (String) a.nextString(in);
     case BYTES: return a.nextBytes(in, (ByteBuffer)reuse);
     case FIXED:
-    case ARRAY:
+    case ARRAY: {
+      List result = null; // FIXME -- use GenericData methods here...
+      Advancer.Container c = advancer.getContainerAdvancer(in);
+      Advancer ec = c.getElementAdvancer(in);
+      Schema es = expected.getElementType();
+      for(long i = c.firstChunk(in); i != 0; i = c.nextChunk(in)) {
+        for (long j = 0; j < i; j++) {
+          result.add(read(null, es, ec, in));
+        }
+      }
+    }
+        
     case MAP:
     case RECORD:
     case UNION:


Mime
View raw message