You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by ga...@apache.org on 2008/01/29 01:08:42 UTC

svn commit: r616117 - in /incubator/pig/branches/types/test/org/apache/pig/test: OrdDescNumeric.java TestAlgebraicEval.java TestBuiltin.java TestMapReduce.java TestPigFile.java Util.java

Author: gates
Date: Mon Jan 28 16:08:35 2008
New Revision: 616117

URL: http://svn.apache.org/viewvc?rev=616117&view=rev
Log:
Changes to make more tests compile.  Not all the tests compile yet.


Modified:
    incubator/pig/branches/types/test/org/apache/pig/test/OrdDescNumeric.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestAlgebraicEval.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestMapReduce.java
    incubator/pig/branches/types/test/org/apache/pig/test/TestPigFile.java
    incubator/pig/branches/types/test/org/apache/pig/test/Util.java

Modified: incubator/pig/branches/types/test/org/apache/pig/test/OrdDescNumeric.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/OrdDescNumeric.java?rev=616117&r1=616116&r2=616117&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/OrdDescNumeric.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/OrdDescNumeric.java Mon Jan 28 16:08:35 2008
@@ -1,3 +1,4 @@
+/*
 package org.apache.pig.test;
 
 import java.io.IOException;
@@ -40,3 +41,4 @@
         return 0;
     }
 }
+*/

Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestAlgebraicEval.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestAlgebraicEval.java?rev=616117&r1=616116&r2=616117&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestAlgebraicEval.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestAlgebraicEval.java Mon Jan 28 16:08:35 2008
@@ -28,6 +28,7 @@
 
 import org.apache.pig.PigServer;
 import org.apache.pig.builtin.PigStorage;
+import org.apache.pig.data.DataByteArray;
 import org.apache.pig.data.Tuple;
 
 public class TestAlgebraicEval extends TestCase {
@@ -54,7 +55,8 @@
         tmpFile.delete();
         int count = 0;
         while(it.hasNext()){
-            int sum = it.next().getAtomField(2).numval().intValue();
+            DataByteArray a = (DataByteArray)it.next().get(2);
+            int sum = Double.valueOf(a.toString()).intValue();
             assertEquals(LOOP_COUNT/2, sum);
             count++;
         }
@@ -79,7 +81,8 @@
         Iterator it = pig.openIterator("myid");
         tmpFile.delete();
         Tuple t = (Tuple)it.next();
-        Double count = t.getAtomField(0).numval();
+        DataByteArray a = (DataByteArray)t.get(0);
+        Double count = Double.valueOf(a.toString());
         assertEquals(count, (double)LOOP_COUNT);
     }
 
@@ -99,7 +102,8 @@
         Iterator it = pig.openIterator("myid");
         tmpFile.delete();
         Tuple t = (Tuple)it.next();
-        Double count = t.getAtomField(1).numval();
+        DataByteArray a = (DataByteArray)t.get(1);
+        Double count = Double.valueOf(a.toString());
         assertEquals(count, (double)LOOP_COUNT);
     }
     
@@ -121,7 +125,8 @@
         Iterator it = pig.openIterator("myid");
         tmpFile.delete();
         Tuple t = (Tuple)it.next();
-        Double count = t.getAtomField(0).numval();
+        DataByteArray a = (DataByteArray)t.get(0);
+        Double count = Double.valueOf(a.toString());
         assertEquals(count, (double)LOOP_COUNT);
     }
 
@@ -146,9 +151,11 @@
         tmpFile.delete();
         while(it.hasNext()) {
             Tuple t = (Tuple)it.next();
-            Double group = t.getAtomField(0).numval();
+            DataByteArray a = (DataByteArray)t.get(0);
+            Double group = Double.valueOf(a.toString());
             if(group == 0.0) {
-                Double count = t.getAtomField(1).numval();
+                DataByteArray b = (DataByteArray)t.get(1);
+                Double count = Double.valueOf(b.toString());
                 assertEquals(count, (double)groupsize);
                 break;
             }
@@ -174,9 +181,11 @@
         tmpFile.delete();
         while(it.hasNext()) {
             Tuple t = (Tuple)it.next();
-            Double group = t.getAtomField(0).numval();
+            DataByteArray a = (DataByteArray)t.get(0);
+            Double group = Double.valueOf(a.toString());
             if(group == 0.0) {
-                Double count = t.getAtomField(1).numval();
+                DataByteArray b = (DataByteArray)t.get(1);
+                Double count = Double.valueOf(b.toString());
                 assertEquals(count, (double)groupsize);
                 break;
             }

Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java?rev=616117&r1=616116&r2=616117&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestBuiltin.java Mon Jan 28 16:08:35 2008
@@ -52,12 +52,11 @@
         int input[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
         double expected = 5.5;
 
-        EvalFunc<DataAtom> avg = new AVG();
-        Tuple tup = Util.loadNestTuple(new Tuple(1), input);
-        DataAtom output = new DataAtom();
-        avg.exec(tup, output);
+        EvalFunc<Double> avg = new AVG();
+        Tuple tup =
+            Util.loadNestTuple(TupleFactory.getInstance().newTuple(1), input);
+        Double output = avg.exec(tup);
         
-        double actual = (new Double(output.strval())).doubleValue();
         assertTrue(actual == expected);
     }
 
@@ -66,84 +65,80 @@
         int input[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
         EvalFunc<Tuple> avg = new AVG.Initial();
-        Tuple tup = Util.loadNestTuple(new Tuple(1), input);
-        Tuple output = new Tuple();
-        avg.exec(tup, output);
-
-        assertEquals("Expected sum to be 55.0", 55.0,
-            output.getAtomField(0).numval());
-        assertEquals("Expected count to be 10", 10,
-            output.getAtomField(1).longVal());
+        Tuple tup = Util.loadNestTuple(TupleFactory.getInstance().newTuple(1), input);
+        Tuple output = avg.exec(tup);
+
+        DataByteArray a = output.get(0);
+        Double f1 = Double.valueOf(a.toString());
+        assertEquals("Expected sum to be 55.0", 55.0, f1);
+        a = output.get(1);
+        Long f2 = Long.valueOf(a.toString());
+        assertEquals("Expected count to be 10", 10, f2);
     }
 
     @Test
     public void testAVGFinal() throws Exception {
-        Tuple t1 = new Tuple(2);
-        t1.setField(0, 55.0);
-        t1.setField(1, 10);
-        Tuple t2 = new Tuple(2);
-        t2.setField(0, 28.0);
-        t2.setField(1, 7);
-        Tuple t3 = new Tuple(2);
-        t3.setField(0, 82.0);
-        t3.setField(1, 17);
+        Tuple t1 = TupleFactory.getInstance().newTuple(2);
+        t1.set(0, 55.0);
+        t1.set(1, 10);
+        Tuple t2 = TupleFactory.getInstance().newTuple(2);
+        t2.set(0, 28.0);
+        t2.set(1, 7);
+        Tuple t3 = TupleFactory.getInstance().newTuple(2);
+        t3.set(0, 82.0);
+        t3.set(1, 17);
         DataBag bag = BagFactory.getInstance().newDefaultBag();
         bag.add(t1);
         bag.add(t2);
         bag.add(t3);
         
-        Tuple tup = new Tuple(bag);
+        Tuple tup = TupleFactory.getInstance().newTuple(bag);
 
-        EvalFunc<DataAtom> avg = new AVG.Final();
-        DataAtom output = new DataAtom();
-        avg.exec(tup, output);
+        EvalFunc<Double> avg = new AVG.Final();
+        Double output = avg.exec(tup);
 
         assertEquals("Expected average to be 4.852941176470588",
-            4.852941176470588, output.numval());
+            4.852941176470588, output);
     }
 
 
     @Test
     public void testCOUNT() throws Exception {
         int input[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-        double expected = input.length;
+        long expected = input.length;
 
-        EvalFunc<DataAtom> count = new COUNT();
-        Tuple tup = Util.loadNestTuple(new Tuple(1), input);
-        DataAtom output = new DataAtom();
-        count.exec(tup, output);
+        EvalFunc<Long> count = new COUNT();
+        Tuple tup = Util.loadNestTuple(TupleFactory.getInstance().newTuple(1), input);
+        Long output = count.exec(tup);
 
-        double actual = (new Double(output.strval())).doubleValue();
         assertTrue(actual == expected);
     }
 
     @Test
     public void testCOUNTMap() throws Exception {
-        DataMap map = new DataMap();
-        
-        Tuple tup = new Tuple();
-        tup.appendField(map);
-        DataAtom output = new DataAtom();
+        Map<Object, Object> map = new Map<Object, Object>();
         
+        Tuple tup = TupleFactory.getInstance().newTuple();
+        tup.append(map);
         
-        EvalFunc<DataAtom> count = new COUNT();
+        EvalFunc<Long> count = new COUNT();
         FilterFunc isEmpty = new IsEmpty();
         
         assertTrue(isEmpty.exec(tup));
-        count.exec(tup,output);
-        assertTrue(output.numval() == 0);
+        Long output = count.exec(tup);
+        assertTrue(output == 0);
         
-        map.put("a", new DataAtom("a"));
+        map.put("a", "a");
 
         assertFalse(isEmpty.exec(tup));
-        count.exec(tup,output);
-        assertTrue(output.numval() == 1);
+        output = count.exec(tup);
+        assertTrue(output == 1);
 
         
-        map.put("b", new Tuple());
+        map.put("b", Tuple.getInstance().newTuple());
 
         assertFalse(isEmpty.exec(tup));
-        count.exec(tup,output);
+        output = count.exec(tup);
         assertTrue(output.numval() == 2);
         
     }
@@ -153,24 +148,23 @@
         int input[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 
         EvalFunc<Tuple> count = new COUNT.Initial();
-        Tuple tup = Util.loadNestTuple(new Tuple(1), input);
-        Tuple output = new Tuple();
-        count.exec(tup, output);
+        Tuple tup = Util.loadNestTuple(TupleFactory.getInstance().newTuple(1), input);
+        Tuple output = count.exec(tup);
 
-        assertEquals("Expected count to be 10", 10,
-            output.getAtomField(0).longVal());
+        DataByteArray a = output.get(0);
+        Long f1 = Long.valueOf(a.toString());
+        assertEquals("Expected count to be 10", 10, f1);
     }
 
     @Test
     public void testCOUNTFinal() throws Exception {
         int input[] = { 23, 38, 39 };
-        Tuple tup = Util.loadNestTuple(new Tuple(1), input);
+        Tuple tup = Util.loadNestTuple(TupleFactory.getInstance().newTuple(1), input);
 
         EvalFunc<DataAtom> count = new COUNT.Final();
-        DataAtom output = new DataAtom();
-        count.exec(tup, output);
+        Long output = count.exec(tup);
 
-        assertEquals("Expected count to be 100", 100, output.longVal());
+        assertEquals("Expected count to be 100", 100, output);
     }
 
     @Test

Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestMapReduce.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestMapReduce.java?rev=616117&r1=616116&r2=616117&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestMapReduce.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestMapReduce.java Mon Jan 28 16:08:35 2008
@@ -38,9 +38,7 @@
 import org.apache.pig.StoreFunc;
 import org.apache.pig.PigServer.ExecType;
 import org.apache.pig.builtin.COUNT;
-import org.apache.pig.data.DataAtom;
 import org.apache.pig.data.DataBag;
-import org.apache.pig.data.Datum;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.impl.io.FileLocalizer;
 import org.apache.pig.impl.io.BufferedPositionedInputStream;

Modified: incubator/pig/branches/types/test/org/apache/pig/test/TestPigFile.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/TestPigFile.java?rev=616117&r1=616116&r2=616117&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/TestPigFile.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/TestPigFile.java Mon Jan 28 16:08:35 2008
@@ -22,6 +22,7 @@
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Random;
 
 import junit.framework.TestCase;
@@ -98,7 +99,7 @@
         new File(initialdata).delete();
     }
 
-    private Datum getRandomDatum(int nestingLevel) throws IOException{
+    private Object getRandomDatum(int nestingLevel) throws IOException{
     	if (nestingLevel>3)
     		return getRandomDataAtom();
     	int i = rand.nextInt(4);
@@ -112,8 +113,8 @@
     	throw new RuntimeException("Shouldn't reach here.");
     }
     
-    private DataAtom getRandomDataAtom(){
-    	return new DataAtom(rand.nextInt());
+    private Integer getRandomDataAtom(){
+    	return new Integer(rand.nextInt());
     }
     
     private Tuple getRandomTuple(int nestingLevel) throws IOException{
@@ -136,9 +137,9 @@
     	
     }
     
-    private DataMap getRandomMap(int nestingLevel) throws IOException{
+    private Map<Object, Object> getRandomMap(int nestingLevel) throws IOException{
     	int cardinality = rand.nextInt(2)+1;
-    	DataMap m = new DataMap();
+    	Map<Object, Object> m = new Map<Object, Object>();
     	for (int i=0; i<cardinality; i++){
     		m.put(getRandomDataAtom().strval(),getRandomDatum(nestingLevel+1));
     	}

Modified: incubator/pig/branches/types/test/org/apache/pig/test/Util.java
URL: http://svn.apache.org/viewvc/incubator/pig/branches/types/test/org/apache/pig/test/Util.java?rev=616117&r1=616116&r2=616117&view=diff
==============================================================================
--- incubator/pig/branches/types/test/org/apache/pig/test/Util.java (original)
+++ incubator/pig/branches/types/test/org/apache/pig/test/Util.java Mon Jan 28 16:08:35 2008
@@ -20,8 +20,6 @@
 import java.io.IOException;
 
 import org.apache.pig.data.*;
-import org.apache.pig.data.Datum;
-import org.apache.pig.data.DataAtom;
 
 public class Util {
     // Helper Functions