You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by cu...@apache.org on 2010/09/03 01:13:07 UTC

svn commit: r992151 - in /avro/branches/branch-1.4: ./ CHANGES.txt lang/java/src/java/org/apache/avro/file/DataFileReader.java lang/java/src/test/java/org/apache/avro/TestDataFile.java

Author: cutting
Date: Thu Sep  2 23:13:07 2010
New Revision: 992151

URL: http://svn.apache.org/viewvc?rev=992151&view=rev
Log:
Merge r992149 from trunk to 1.4 branch.  Fixes: AVRO-652.

Modified:
    avro/branches/branch-1.4/   (props changed)
    avro/branches/branch-1.4/CHANGES.txt
    avro/branches/branch-1.4/lang/java/src/java/org/apache/avro/file/DataFileReader.java
    avro/branches/branch-1.4/lang/java/src/test/java/org/apache/avro/TestDataFile.java

Propchange: avro/branches/branch-1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Sep  2 23:13:07 2010
@@ -1 +1 @@
-/avro/trunk:990852,990860,990867,990871,990878,991031,991423,992146
+/avro/trunk:990852,990860,990867,990871,990878,991031,991423,992146,992149

Modified: avro/branches/branch-1.4/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.4/CHANGES.txt?rev=992151&r1=992150&r2=992151&view=diff
==============================================================================
--- avro/branches/branch-1.4/CHANGES.txt (original)
+++ avro/branches/branch-1.4/CHANGES.txt Thu Sep  2 23:13:07 2010
@@ -161,6 +161,9 @@ Avro 1.4.0 (31 August 2010)
 
     AVRO-644: PHP: Add requirements to README. (Michael Glaesemann via cutting)
 
+    AVRO-652. Java: Expose sync points in DataFileReader.
+    (Stu Hood via cutting)
+
   BUG FIXES
 
     AVRO-622. python avro.ipc doesn't work with python2.4 (philz)

Modified: avro/branches/branch-1.4/lang/java/src/java/org/apache/avro/file/DataFileReader.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.4/lang/java/src/java/org/apache/avro/file/DataFileReader.java?rev=992151&r1=992150&r2=992151&view=diff
==============================================================================
--- avro/branches/branch-1.4/lang/java/src/java/org/apache/avro/file/DataFileReader.java (original)
+++ avro/branches/branch-1.4/lang/java/src/java/org/apache/avro/file/DataFileReader.java Thu Sep  2 23:13:07 2010
@@ -44,6 +44,7 @@ public class DataFileReader<D> extends D
     super(reader);
     this.sin = new SeekableInputStream(sin);
     initialize(this.sin);
+    blockFinished();
   }
 
   /** Move to a specific, known synchronization point, one returned from {@link
@@ -52,6 +53,7 @@ public class DataFileReader<D> extends D
   public void seek(long position) throws IOException {
     sin.seek(position);
     vin = DecoderFactory.defaultFactory().createBinaryDecoder(this.sin, vin);
+    datumIn = null;
     blockRemaining = 0;
     blockStart = position;
   }
@@ -93,6 +95,11 @@ public class DataFileReader<D> extends D
     blockStart = sin.tell() - vin.inputStream().available();
   }
 
+  /** Return the last synchronization point before our current position. */
+  public long previousSync() {
+    return blockStart;
+  }
+
   /** Return true if past the next synchronization point after a position. */ 
   public boolean pastSync(long position) throws IOException {
     return ((blockStart >= position+SYNC_SIZE)||(blockStart >= sin.length()));

Modified: avro/branches/branch-1.4/lang/java/src/test/java/org/apache/avro/TestDataFile.java
URL: http://svn.apache.org/viewvc/avro/branches/branch-1.4/lang/java/src/test/java/org/apache/avro/TestDataFile.java?rev=992151&r1=992150&r2=992151&view=diff
==============================================================================
--- avro/branches/branch-1.4/lang/java/src/test/java/org/apache/avro/TestDataFile.java (original)
+++ avro/branches/branch-1.4/lang/java/src/test/java/org/apache/avro/TestDataFile.java Thu Sep  2 23:13:07 2010
@@ -152,6 +152,35 @@ public class TestDataFile {
   }
 
   @Test
+  public void testSyncDiscovery() throws IOException {
+    File file = makeFile();
+    DataFileReader<Object> reader =
+      new DataFileReader<Object>(file, new GenericDatumReader<Object>());
+    try {
+      // discover the sync points
+      ArrayList<Long> syncs = new ArrayList<Long>();
+      long previousSync = -1;
+      while (reader.hasNext()) {
+        if (reader.previousSync() != previousSync) {
+          previousSync = reader.previousSync();
+          syncs.add(previousSync);
+        }
+        reader.next();
+      }
+      // confirm that the first point is the one reached by sync(0)
+      reader.sync(0);
+      assertEquals((long)reader.previousSync(), (long)syncs.get(0));
+      // and confirm that all points are reachable
+      for (Long sync : syncs) {
+        reader.seek(sync);
+        assertNotNull(reader.next());
+      }
+    } finally {
+      reader.close();
+    }
+  }
+
+  @Test
   public void testGenericAppend() throws IOException {
     File file = makeFile();
     long start = file.length();