Author: pradeepkth
Date: Sat Jan 31 02:04:57 2009
New Revision: 739491

URL: http://svn.apache.org/viewvc?rev=739491&view=rev
Log:
RandomSampleLoader does not handle skipping correctly in getNext()

Modified:
    hadoop/pig/trunk/CHANGES.txt
    hadoop/pig/trunk/src/org/apache/pig/impl/builtin/RandomSampleLoader.java

Modified: hadoop/pig/trunk/CHANGES.txt
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/CHANGES.txt?rev=739491&r1=739490&r2=739491&view=diff
==============================================================================
--- hadoop/pig/trunk/CHANGES.txt (original)
+++ hadoop/pig/trunk/CHANGES.txt Sat Jan 31 02:04:57 2009
@@ -398,3 +398,6 @@
 
     PIG-648: BinStorage fails when it finds markers unexpectedly in the data
     (pradeepkth)
+
+    PIG-649: RandomSampleLoader does not handle skipping correctly in
+    getNext() (pradeepkth)

Modified: 
hadoop/pig/trunk/src/org/apache/pig/impl/builtin/RandomSampleLoader.java
URL: 
http://svn.apache.org/viewvc/hadoop/pig/trunk/src/org/apache/pig/impl/builtin/RandomSampleLoader.java?rev=739491&r1=739490&r2=739491&view=diff
==============================================================================
--- hadoop/pig/trunk/src/org/apache/pig/impl/builtin/RandomSampleLoader.java 
(original)
+++ hadoop/pig/trunk/src/org/apache/pig/impl/builtin/RandomSampleLoader.java 
Sat Jan 31 02:04:57 2009
@@ -45,8 +45,23 @@
         long finalPos = in.getPosition();
         
         long toSkip = skipInterval - (finalPos - initialPos);
-        if (toSkip > 0)
-            in.skip(toSkip);
+        if (toSkip > 0) {
+            long rc = in.skip(toSkip);
+            
+            // if we did not skip enough
+            // in the first attempt, call
+            // in.skip() repeatedly till we
+            // skip enough
+            long remainingSkip = toSkip - rc;
+            while(remainingSkip > 0) {
+                rc = in.skip(remainingSkip);
+                if(rc == 0) {
+                    // underlying stream saw EOF
+                    break;
+                }
+                remainingSkip -= rc;
+            }
+        }
         return t;
     }
     


Reply via email to