You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by rd...@apache.org on 2010/10/04 23:40:39 UTC

svn commit: r1004445 - in /hadoop/pig/branches/branch-0.8: CHANGES.txt src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/partitioners/DiscreteProbabilitySampleGenerator.java

Author: rding
Date: Mon Oct  4 21:40:39 2010
New Revision: 1004445

URL: http://svn.apache.org/viewvc?rev=1004445&view=rev
Log:
PIG-1662: Need better error message for MalFormedProbVecException

Modified:
    hadoop/pig/branches/branch-0.8/CHANGES.txt
    hadoop/pig/branches/branch-0.8/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/partitioners/DiscreteProbabilitySampleGenerator.java

Modified: hadoop/pig/branches/branch-0.8/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/branch-0.8/CHANGES.txt?rev=1004445&r1=1004444&r2=1004445&view=diff
==============================================================================
--- hadoop/pig/branches/branch-0.8/CHANGES.txt (original)
+++ hadoop/pig/branches/branch-0.8/CHANGES.txt Mon Oct  4 21:40:39 2010
@@ -200,6 +200,8 @@ PIG-1309: Map-side Cogroup (ashutoshc)
 
 BUG FIXES
 
+PIG-1662: Need better error message for MalFormedProbVecException (rding)
+
 PIG-1658: ORDER BY does not work properly on integer/short keys that are -1 (yanz)
 
 PIG-1638: sh output gets mixed up with the grunt prompt (nrai via daijy)

Modified: hadoop/pig/branches/branch-0.8/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/partitioners/DiscreteProbabilitySampleGenerator.java
URL: http://svn.apache.org/viewvc/hadoop/pig/branches/branch-0.8/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/partitioners/DiscreteProbabilitySampleGenerator.java?rev=1004445&r1=1004444&r2=1004445&view=diff
==============================================================================
--- hadoop/pig/branches/branch-0.8/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/partitioners/DiscreteProbabilitySampleGenerator.java (original)
+++ hadoop/pig/branches/branch-0.8/src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/partitioners/DiscreteProbabilitySampleGenerator.java Mon Oct  4 21:40:39 2010
@@ -26,22 +26,7 @@ public class DiscreteProbabilitySampleGe
     Random rGen;
     float[] probVec;
     float epsilon = 0.00001f;
-    
-    public DiscreteProbabilitySampleGenerator(long seed, float[] probVec) throws MalFormedProbVecException{
-        rGen = new Random(seed);
-        float sum = 0.0f;
-        for (float f : probVec) {
-            sum += f;
-        }
-        if(1-epsilon<=sum && sum<=1+epsilon) 
-            this.probVec = probVec;
-        else {
-            int errorCode = 2122;
-            String message = "Sum of probabilities should be one";
-            throw new MalFormedProbVecException(message, errorCode, PigException.BUG);
-        }
-    }
-    
+        
     public DiscreteProbabilitySampleGenerator(float[] probVec) throws MalFormedProbVecException{
         rGen = new Random();
         float sum = 0.0f;
@@ -52,7 +37,7 @@ public class DiscreteProbabilitySampleGe
             this.probVec = probVec;
         else {
             int errorCode = 2122;
-            String message = "Sum of probabilities should be one";
+            String message = "Sum of probabilities should be one: " + Arrays.toString(probVec);
             throw new MalFormedProbVecException(message, errorCode, PigException.BUG);
         }
     }
@@ -78,7 +63,7 @@ public class DiscreteProbabilitySampleGe
     
     public static void main(String[] args) throws MalFormedProbVecException {
         float[] vec = { 0, 0.3f, 0.2f, 0, 0, 0.5f };
-        DiscreteProbabilitySampleGenerator gen = new DiscreteProbabilitySampleGenerator(11317, vec);
+        DiscreteProbabilitySampleGenerator gen = new DiscreteProbabilitySampleGenerator(vec);
         CountingMap<Integer> cm = new CountingMap<Integer>();
         for(int i=0;i<100;i++){
             cm.put(gen.getNext(), 1);