You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pig.apache.org by gd...@apache.org on 2012/09/13 16:55:38 UTC

svn commit: r1384352 [4/4] - in /pig/trunk: ./ contrib/piggybank/java/src/main/java/org/apache/pig/piggybank/storage/avro/ src/org/apache/pig/backend/hadoop/executionengine/mapReduceLayer/ src/org/apache/pig/backend/hadoop/executionengine/physicalLayer...

Modified: pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java?rev=1384352&r1=1384351&r2=1384352&view=diff
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java (original)
+++ pig/trunk/test/org/apache/pig/test/TestLogicalPlanBuilder.java Thu Sep 13 14:55:36 2012
@@ -28,31 +28,28 @@ import java.util.Properties;
 import junit.framework.Assert;
 import junit.framework.AssertionFailedError;
 
-import org.junit.Before;
-import org.junit.Test;
-
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapreduce.InputFormat;
 import org.apache.hadoop.mapreduce.Job;
 import org.apache.hadoop.mapreduce.RecordReader;
+import org.apache.pig.ExecType;
+import org.apache.pig.FuncSpec;
 import org.apache.pig.LoadCaster;
 import org.apache.pig.LoadFunc;
-import org.apache.pig.FuncSpec;
 import org.apache.pig.PigException;
 import org.apache.pig.PigServer;
 import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigSplit;
 import org.apache.pig.builtin.PigStorage;
 import org.apache.pig.data.BagFactory;
 import org.apache.pig.data.DataBag;
+import org.apache.pig.data.DataType;
 import org.apache.pig.data.Tuple;
 import org.apache.pig.data.TupleFactory;
 import org.apache.pig.impl.PigContext;
-import org.apache.pig.ExecType;
 import org.apache.pig.impl.builtin.GFAny;
 import org.apache.pig.impl.logicalLayer.schema.Schema;
 import org.apache.pig.impl.util.LogUtils;
 import org.apache.pig.impl.util.Utils;
-import org.apache.pig.data.DataType;
 import org.apache.pig.newplan.Operator;
 import org.apache.pig.newplan.logical.expression.ConstantExpression;
 import org.apache.pig.newplan.logical.expression.LogicalExpressionPlan;
@@ -65,11 +62,13 @@ import org.apache.pig.newplan.logical.re
 import org.apache.pig.newplan.logical.relational.LogicalPlan;
 import org.apache.pig.newplan.logical.relational.LogicalSchema;
 import org.apache.pig.test.utils.Identity;
+import org.junit.Before;
+import org.junit.Test;
 
 public class TestLogicalPlanBuilder {
     PigContext pigContext = new PigContext(ExecType.LOCAL, new Properties());
     private PigServer pigServer = null;
-    
+
     @Before
     public void setUp() throws Exception {
     	pigServer = new PigServer( pigContext );
@@ -107,21 +106,21 @@ public class TestLogicalPlanBuilder {
         buildPlan(query);
     }
 
-    
+
     @Test
     public void testQuery6() throws Exception {
         String query = "foreach (group (load 'a') by $1) generate group, '1' ;";
         buildPlan(query);
     }
 
-    
+
     @Test
     public void testQuery7() throws Exception {
         String query = "foreach (load 'a' using " + PigStorage.class.getName() + "()) generate $1 ;";
         buildPlan(query);
     }
 
-    
+
     @Test
     public void testQuery10() throws Exception {
         String query = "foreach (cogroup (load 'a') by ($1), (load 'b') by ($1)) generate $1.$1, $2.$1 ;";
@@ -134,7 +133,7 @@ public class TestLogicalPlanBuilder {
         String query = " foreach (group (load 'a' as (u:int)) by $0, (load 'b' as (v:long)) by $0) generate group, AVG($1) ;";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery12() throws Exception {
         String query = "foreach (load 'a' using " + PigStorage.class.getName() + "() as (v: long, u:bag{T:tuple(t:double)} ) ) generate AVG($1) ;";
@@ -158,7 +157,7 @@ public class TestLogicalPlanBuilder {
         String query = " foreach (load 'a') generate $1, 'hello', $3 ;";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery100() throws Exception {
         // test define syntax
@@ -199,7 +198,7 @@ public class TestLogicalPlanBuilder {
         }
         Assert.fail("Test case should fail" );
     }
-    
+
     @Test
     public void testQueryFail4() throws Exception {
         String query = "A = generate [ORDER BY $0][$3, $4] foreach (load 'a');";
@@ -221,11 +220,11 @@ public class TestLogicalPlanBuilder {
         }
         Assert.fail("Test case should fail" );
     }
-    
+
     /**
      * User generate functions must be in default package Bug 831620 - fixed
      */
- 
+
     // TODO FIX Query17
     @Test
     public void testQuery17() throws Exception {
@@ -240,7 +239,7 @@ public class TestLogicalPlanBuilder {
             return output;
         }
     }
-    
+
     /**
      * Validate that parallel is parsed correctly Bug 831714 - fixed
      */
@@ -248,30 +247,30 @@ public class TestLogicalPlanBuilder {
     public void testQuery18() throws Exception {
         String query = "store (FOREACH (group (load 'a') ALL PARALLEL 16) generate group ) into 'y';";
         LogicalPlan lp = buildPlan(query);
-        Operator root = lp.getSources().get(0);   
+        Operator root = lp.getSources().get(0);
         List<Operator> listOp = lp.getSuccessors(root);
         Operator lo = listOp.get(0);
-        
+
         if (lo instanceof LOCogroup) {
             Assert.assertEquals( 1, ((LOCogroup) lo).getRequestedParallelism() );//Local mode, paraallel = 1
         } else {
             Assert.fail("Error: Unexpected Parse Tree output");
-        }  
     }
-    
+    }
+
     @Test
     public void testQuery19() throws Exception {
         String query = "a = load 'a';" +
                        "b = filter a by $1 == '3';";
         buildPlan( query );
     }
-    
+
     @Test
     public void testQuery20() throws Exception {
         String query = "foreach (load 'a') generate ($1 == '3'? $2 : $3) ;";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery21() throws Exception {
         String query = "A = load 'a';" +
@@ -279,7 +278,7 @@ public class TestLogicalPlanBuilder {
                        "foreach (cogroup A by ($1), B by ($1)) generate A, flatten(B.($1, $2, $3));";
         buildPlan( query );
     }
-    
+
     @Test
     public void testQuery22() throws Exception {
         String query = "A = load 'a';" +
@@ -290,7 +289,7 @@ public class TestLogicalPlanBuilder {
                        "generate FLATTEN(A), B.($1, $2, $3) ;" + "};" ;
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery22Fail() throws Exception {
         String query = "A = load 'a' as (a:int, b: double);" +
@@ -301,14 +300,14 @@ public class TestLogicalPlanBuilder {
             Assert.assertTrue(e.getMessage().contains("Grouping attributes can either be star (*"));
         }
     }
-    
+
     @Test
     public void testQuery23() throws Exception {
-        String query = "A = load 'a';" + 
+        String query = "A = load 'a';" +
                        "B = load 'b';" +
-        
+
                        "C = cogroup A by ($1), B by ($1);" +
-        
+
                        "foreach C { " +
                        "A = Distinct A; " +
                        "B = FILTER A BY $1 < 'z'; " +
@@ -353,7 +352,7 @@ public class TestLogicalPlanBuilder {
         }
         Assert.assertTrue(exceptionThrown);
     }
-    
+
     @Test
     public void testQuery23Fail3() throws Exception {
         String query = "A = load 'a' as (a: int, b:double);" +
@@ -369,7 +368,7 @@ public class TestLogicalPlanBuilder {
         }
         Assert.assertTrue(exceptionThrown);
     }
-    
+
     @Test
     public void testQuery24() throws Exception {
         String query = "a = load 'a';" + "foreach a generate (($0 == $1) ? 'a' : $2), $4 ;";
@@ -384,13 +383,13 @@ public class TestLogicalPlanBuilder {
                 "};";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery26() throws Exception {
         String query = "foreach (load 'a') generate  ((NOT (($1 == $2) OR ('a' < 'b'))) ? 'a' : $2), 'x' ;";
         buildPlan(query);
     }
-    
+
     // TODO FIX Query27 and Query28
     @Test
     public void testQuery27() throws Exception {
@@ -400,13 +399,13 @@ public class TestLogicalPlanBuilder {
                         "};";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery28() throws Exception {
         String query = "foreach (load 'a') generate " + TestApplyFunc.class.getName() + "($2, " + TestApplyFunc.class.getName() + "($2.$3));";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery29() throws Exception {
         String query = "load 'myfile' using " + TestStorageFunc.class.getName() + "() as (col1);";
@@ -418,9 +417,9 @@ public class TestLogicalPlanBuilder {
         String query = "load 'myfile' using " + TestStorageFunc.class.getName() + "() as (col1, col2);";
         buildPlan(query);
     }
-    
+
     public static class TestStorageFunc extends LoadFunc{
-        
+
         public Tuple getNext() throws IOException {
             return null;
         }
@@ -438,7 +437,7 @@ public class TestLogicalPlanBuilder {
         @Override
         public void prepareToRead(RecordReader reader, PigSplit split)
                 throws IOException {
-            
+
         }
 
         @Override
@@ -449,22 +448,22 @@ public class TestLogicalPlanBuilder {
 
         @Override
         public void setLocation(String location, Job job) throws IOException {
- 
+
         }
     }
-    
+
     @Test
     public void testQuery31() throws Exception {
         String query = "load 'myfile' as (col1, col2);";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery32() throws Exception {
         String query = "foreach (load 'myfile' as (col1, col2 : tuple(sub1, sub2), col3 : tuple(bag1))) generate col1 ;";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery33() throws Exception {
         String query = "A = load 'a' as (aCol1, aCol2);" +
@@ -473,7 +472,7 @@ public class TestLogicalPlanBuilder {
                        "foreach C generate group, A.aCol1;";
         buildPlan(query);
     }
-    
+
     @Test
     //TODO: Nested schemas don't work now. Probably a bug in the new parser.
     public void testQuery34() throws Exception {
@@ -483,19 +482,19 @@ public class TestLogicalPlanBuilder {
         "foreach (cogroup A by (aCol1), B by bCol1 ) generate A.aCol2, B.bCol2 ;";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery35() throws Exception {
         String query = "foreach (load 'a' as (col1, col2)) generate col1, col2 ;";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQuery36() throws Exception {
         String query = "foreach (cogroup ( load 'a' as (col1, col2)) by col1) generate $1.(col2, col1);";
         buildPlan(query);
     }
-    
+
     @Test
     public void testQueryFail37() throws Exception {
         String query = "A = load 'a'; asdasdas";
@@ -506,30 +505,30 @@ public class TestLogicalPlanBuilder {
         }
         Assert.fail( "Query should fail." );
     }
-    
+
     @Test
     public void testQuery38() throws Exception {
         String query = "c = cross (load 'a'), (load 'b');";
         buildPlan(query);
     }
-    
+
     // TODO FIX Query39 and Query40
     @Test
     public void testQuery39() throws Exception{
-        String query = "a = load 'a' as (url, host, rank:double);" +
+        String query = "a = load 'a' as (url, host, ranking:double);" +
                        "b = group a by (url,host); " +
-                       "c = foreach b generate flatten(group.url), SUM(a.rank) as totalRank;";
+        "c = foreach b generate flatten(group.url), SUM(a.ranking) as totalRank;";
         buildPlan(query);
         query += "d = filter c by totalRank > 10;" +
                  "e = foreach d generate totalRank;";
         buildPlan( query );
     }
-    
+
     @Test
     public void testQueryFail39() throws Exception{
-        String query = "a = load 'a' as (url, host, rank);" +
+        String query = "a = load 'a' as (url, host, ranking);" +
                        "b = group a by (url,host); " +
-             "c = foreach b generate flatten(group.url), SUM(a.rank) as totalRank;" +
+        "c = foreach b generate flatten(group.url), SUM(a.ranking) as totalRank;" +
                        "d = filter c by totalRank > '10';" +
                        "e = foreach d generate url;";
         try {
@@ -538,13 +537,13 @@ public class TestLogicalPlanBuilder {
             Assert.assertTrue(e.getMessage().contains("Exception"));
         }
     }
-    
+
     @Test
     public void testQuery40() throws Exception {
         String query = "a = FILTER (load 'a') BY IsEmpty($2);";
         buildPlan( query +"a = FILTER (load 'a') BY (IsEmpty($2) AND ($3 == $2));" );
     }
-    
+
     @Test
     public void testQueryFail41() throws Exception {
         try {
@@ -560,11 +559,11 @@ public class TestLogicalPlanBuilder {
         //buildPlan("foreach b generate host;");
         Assert.fail( "Query should fail." );
     }
-    
+
     @Test
     public void testQuery42() throws Exception {
         String q = "a = load 'a';" +
-        "b = foreach a generate $0 as url, $1 as rank;" +
+        "b = foreach a generate $0 as url, $1 as ranking;" +
         "foreach b generate url;";
         buildPlan( q );
     }
@@ -572,10 +571,10 @@ public class TestLogicalPlanBuilder {
     @Test
     public void testQuery43() throws Exception {
         String q = "a = load 'a' as (url,hitCount);" +
-        "b = load 'a' as (url,rank);" +
+        "b = load 'a' as (url,ranking);" +
         "c = cogroup a by url, b by url;" +
         "d = foreach c generate group,flatten(a),flatten(b);" +
-        "e = foreach d generate group, a::url, b::url, b::rank;";
+        "e = foreach d generate group, a::url, b::url, b::ranking;";
         buildPlan( q );
     }
 
@@ -590,13 +589,13 @@ public class TestLogicalPlanBuilder {
             return;
         }
         Assert.fail( "Query should fail." );
-    } 
+    }
 
     @Test
     public void testQuery44() throws Exception {
         String q = "a = load 'a' as (url, pagerank);" +
-        "b = load 'b' as (url, query, rank);" +
-        "c = cogroup a by (pagerank#'nonspam', url) , b by (rank, url) ;" +
+        "b = load 'b' as (url, query, ranking);" +
+        "c = cogroup a by (pagerank#'nonspam', url) , b by (ranking, url) ;" +
         "foreach c generate group.url;";
         buildPlan( q );
     }
@@ -618,7 +617,7 @@ public class TestLogicalPlanBuilder {
         }
         Assert.assertTrue(false);
     }
-    
+
     @Test
     public void testQuery57() throws Exception {
         String query = "foreach (load 'a' as (u:int, v:long, w:int)) generate ($1+$2), ($1-$2), ($1*$2), ($1/$2), ($1%$2), -($1) ;";
@@ -631,14 +630,14 @@ public class TestLogicalPlanBuilder {
         "b = group a by name;" +
         "foreach b {d = a.name; generate group, d;};";
         buildPlan(query);
-    } 
+    }
 
 	@Test
     public void testQueryFail58() throws Exception{
-        String query = "a = load 'a' as (url, host, rank);" +
+        String query = "a = load 'a' as (url, host, ranking);" +
         "b = group a by url; ";
         try {
-        	LogicalPlan lp = buildPlan(query + "c = foreach b generate group.url;");
+            buildPlan(query + "c = foreach b generate group.url;");
         } catch (AssertionFailedError e) {
             Assert.assertTrue(e.getMessage().contains("Exception"));
         }
@@ -650,15 +649,15 @@ public class TestLogicalPlanBuilder {
         "b = load 'b' as (name, height);" +
         "c = join a by name, b by name;";
         buildPlan(query);
-    } 
-    
+    }
+
     @Test
     public void testQuery60() throws Exception {
          String query = "a = load 'a' as (name, age, gpa);" +
         "b = load 'b' as (name, height);" +
        "c = cross a,b;";
         buildPlan(query);
-    } 
+    }
 
     @Test
     public void testQuery61() throws Exception {
@@ -713,7 +712,7 @@ public class TestLogicalPlanBuilder {
             Assert.assertTrue(e.getMessage().contains("Exception"));
         }
     }
-    
+
     @Test
     public void testQuery64() throws Exception {
         String query = "a = load 'a' as (name: chararray, details: tuple(age, gpa), mymap: map[]);" +
@@ -735,7 +734,7 @@ public class TestLogicalPlanBuilder {
         }
         Assert.fail( "query should fail" );
     }
-    
+
     @Test
     public void testQuery65() throws Exception {
         String q = "a = load 'a' as (name, age, gpa);" +
@@ -793,7 +792,7 @@ public class TestLogicalPlanBuilder {
         " b = foreach a generate age, age * 10L, gpa/0.2f, {16, 4.0e-2, 'hello'};";
         buildPlan(q);
     }
-    
+
     @Test
     public void testQueryFail68() throws Exception {
         String q = " a = load 'input1' as (name, age, gpa);";
@@ -805,7 +804,7 @@ public class TestLogicalPlanBuilder {
         }
         Assert.fail( "query should fail" );
     }
-    
+
     @Test
     public void testQuery71() throws Exception {
         String q = "split (load 'a') into x if $0 > '7', y if $0 < '7';" +
@@ -874,7 +873,7 @@ public class TestLogicalPlanBuilder {
     public void testQuery77() throws Exception {
         buildPlan("limit (load 'a') 100;");
     }
-    
+
     @Test
     public void testLimitWithLong() throws Exception {
         buildPlan("limit (load 'a') 100L;");
@@ -885,7 +884,7 @@ public class TestLogicalPlanBuilder {
         String q = "a = union (load 'a'), (load 'b'), (load 'c');";
         buildPlan( q + "b = foreach a {generate $0;};");
     }
-    
+
     @Test
     public void testQuery76() throws Exception {
     	String q = "split (load 'a') into x if $0 > '7', y if $0 < '7';" +
@@ -929,14 +928,14 @@ public class TestLogicalPlanBuilder {
         }
         Assert.fail( "Query should fail." );
     }
-    
+
     @Test
     public void testQuery82() throws Exception {
         String q = "a = load 'myfile';" +
-        "b = group a by $0;" + 
+        "b = group a by $0;" +
         "c = foreach b {"
-            + "c1 = order $1 by *;" 
-            + "c2 = $1.$0;" 
+        + "c1 = order $1 by *;"
+        + "c2 = $1.$0;"
             + "generate flatten(c1), c2;"
             + "};";
         buildPlan(q);
@@ -987,16 +986,16 @@ public class TestLogicalPlanBuilder {
             + "};";
         buildPlan(q);
     }
-    
+
     @Test
     public void testQuery85() throws Exception {
         LogicalPlan lp;
-        String query = "a = load 'myfile' as (name, age, gpa);" + 
+        String query = "a = load 'myfile' as (name, age, gpa);" +
 		               "b = group a by (name, age);";
         lp = buildPlan( query + "store b into 'output';");
         Operator store = lp.getSinks().get(0);
         LOCogroup cogroup = (LOCogroup) lp.getPredecessors(store).get(0);
-        
+
         LogicalSchema actual = cogroup.getSchema();
         System.out.println( actual.toString( false ) );
 
@@ -1066,9 +1065,9 @@ public class TestLogicalPlanBuilder {
         LogicalPlan lp = buildPlan( query );
         Operator store = lp.getSinks().get(0);
         LOSort sort = (LOSort) lp.getPredecessors(store).get(0);
-//        LOProject project1 = (LOProject) sort.getSortColPlans().get(0).getSinks().get(0) ;
-//        LOCogroup cogroup = (LOCogroup) lp.getPredecessors(sort).get(0) ;
-//        assertEquals(project1.getExpression(), cogroup) ;
+        //        LOProject project1 = (LOProject) sort.getSortColPlans().get(0).getSinks().get(0) ;
+        //        LOCogroup cogroup = (LOCogroup) lp.getPredecessors(sort).get(0) ;
+        //        assertEquals(project1.getExpression(), cogroup) ;
     }
 
     @Test
@@ -1128,7 +1127,7 @@ public class TestLogicalPlanBuilder {
         store = lp.getSinks().get(0);
         foreach = (LOForEach)lp.getPredecessors(store).get(0);
         Assert.assertTrue(foreach.getSchema().toString( false ).equals("mygroup:tuple(myname:chararray,myage:int),mycount:long"));
-/*
+        /*
         //setting the schema of flattened bag that has no schema with the user defined schema
         String q = "a = load 'myfile' as (name:Chararray, age:Int, gpa:Float);" +
                    "c = load 'another_file';" +
@@ -1167,7 +1166,7 @@ public class TestLogicalPlanBuilder {
         store = lp.getSinks().get(0);
         foreach = (LOForEach)lp.getPredecessors(store).get(0);
         Assert.assertTrue(foreach.getSchema().equals(Util.getSchemaFromString("x: int, mycount: long")));
-*/
+         */
     }
 
     @Test
@@ -1205,7 +1204,7 @@ public class TestLogicalPlanBuilder {
             Assert.assertTrue(e.getMessage().contains("Incompatable schema"));
         }
     }
-        
+
     @Test
     public void testQuery91() throws Exception {
         String query = "a = load 'myfile' as (name:Chararray, age:Int, gpa:Float);" +
@@ -1236,7 +1235,7 @@ public class TestLogicalPlanBuilder {
                        "e = foreach d generate name;";
         buildPlan( query );
     }
-    
+
     @Test
     public void testQueryFail93() throws Exception {
         String query = "a = load 'one' as (name, age, gpa);" +
@@ -1247,7 +1246,7 @@ public class TestLogicalPlanBuilder {
         "e = foreach d generate a::name;";
         buildPlan( query );
     }
-    
+
     @Test
     public void testQuery94() throws Exception {
         String query = "a = load 'one' as (name, age, gpa);" +
@@ -1261,7 +1260,7 @@ public class TestLogicalPlanBuilder {
         "f = foreach d generate gpa, somethingelse;";
         buildPlan( query );
     }
-    
+
     @Test
     public void testQueryFail94() throws Exception {
         String query = "a = load 'one' as (name, age, gpa);" +
@@ -1309,31 +1308,31 @@ public class TestLogicalPlanBuilder {
         Operator store = lp.getSinks().get(0);
         LOForEach foreach = (LOForEach)lp.getPredecessors(store).get(0);
         LogicalPlan foreachPlans = foreach.getInnerPlan();
-//        LogicalPlan flattenPlan = foreachPlans.get(1);
-//        LogicalOperator project = flattenPlan.getLeaves().get(0);
-//        Assert.assertTrue(project instanceof LOProject);
-//        LogicalOperator sort = flattenPlan.getPredecessors(project).get(0);
-//        Assert.assertTrue(sort instanceof LOSort);
-//        LogicalOperator distinct = flattenPlan.getPredecessors(sort).get(0);
-//        Assert.assertTrue(distinct instanceof LODistinct);
-//
-//        //testing the presence of the nested foreach
-//        LogicalOperator nestedForeach = flattenPlan.getPredecessors(distinct).get(0);
-//        Assert.assertTrue(nestedForeach instanceof LOForEach);
-//        LogicalPlan nestedForeachPlan = ((LOForEach)nestedForeach).getForEachPlans().get(0);
-//        LogicalOperator nestedProject = nestedForeachPlan.getRoots().get(0);
-//        Assert.assertTrue(nestedProject instanceof LOProject);
-//        Assert.assertTrue(((LOProject)nestedProject).getCol() == 2);
-//
-//        //testing the filter inner plan for the absence of the project connected to project
-//        LogicalOperator filter = flattenPlan.getPredecessors(nestedForeach).get(0);
-//        Assert.assertTrue(filter instanceof LOFilter);
-//        LogicalPlan comparisonPlan = ((LOFilter)filter).getComparisonPlan();
-//        LOLesserThan lessThan = (LOLesserThan)comparisonPlan.getLeaves().get(0);
-//        LOProject filterProject = (LOProject)lessThan.getLhsOperand();
-//        Assert.assertTrue(null == comparisonPlan.getPredecessors(filterProject));
+        //        LogicalPlan flattenPlan = foreachPlans.get(1);
+        //        LogicalOperator project = flattenPlan.getLeaves().get(0);
+        //        Assert.assertTrue(project instanceof LOProject);
+        //        LogicalOperator sort = flattenPlan.getPredecessors(project).get(0);
+        //        Assert.assertTrue(sort instanceof LOSort);
+        //        LogicalOperator distinct = flattenPlan.getPredecessors(sort).get(0);
+        //        Assert.assertTrue(distinct instanceof LODistinct);
+        //
+        //        //testing the presence of the nested foreach
+        //        LogicalOperator nestedForeach = flattenPlan.getPredecessors(distinct).get(0);
+        //        Assert.assertTrue(nestedForeach instanceof LOForEach);
+        //        LogicalPlan nestedForeachPlan = ((LOForEach)nestedForeach).getForEachPlans().get(0);
+        //        LogicalOperator nestedProject = nestedForeachPlan.getRoots().get(0);
+        //        Assert.assertTrue(nestedProject instanceof LOProject);
+        //        Assert.assertTrue(((LOProject)nestedProject).getCol() == 2);
+        //
+        //        //testing the filter inner plan for the absence of the project connected to project
+        //        LogicalOperator filter = flattenPlan.getPredecessors(nestedForeach).get(0);
+        //        Assert.assertTrue(filter instanceof LOFilter);
+        //        LogicalPlan comparisonPlan = ((LOFilter)filter).getComparisonPlan();
+        //        LOLesserThan lessThan = (LOLesserThan)comparisonPlan.getLeaves().get(0);
+        //        LOProject filterProject = (LOProject)lessThan.getLhsOperand();
+        //        Assert.assertTrue(null == comparisonPlan.getPredecessors(filterProject));
     }
-/*
+    /*
     @Test
     public void testQuery97() throws FrontendException, ParseException {
         LogicalPlan lp;
@@ -1459,7 +1458,7 @@ public class TestLogicalPlanBuilder {
         query = "foreach (load 'data') generate FUNC($0);";
         buildPlan(query);
     }
-*/
+     */
     @Test
     public void testQuery102() throws Exception {
         // test basic store
@@ -1472,21 +1471,21 @@ public class TestLogicalPlanBuilder {
         buildPlan("a = load 'a';" + "store a into 'out' using PigStorage();");
     }
 
-//    @Test // Commented out due to PIG-2037
-//    public void testQuery104() throws Exception {
-//        // check that a field alias can be referenced
-//        // by unambiguous free form alias, fully qualified alias
-//        // and partially qualified unambiguous alias
-//        String query = "a = load 'st10k' as (name, age, gpa);\n"  +
-//         "b = group a by name;\n"  +
-//        "c = foreach b generate flatten(a);\n"  +
-//        "d = filter c by name != 'fred';\n"  +
-//        "e = group d by name;\n"  +
-//        "f = foreach e generate flatten(d);\n"  +
-//        "g = foreach f generate name, d::a::name, a::name;\n" +
-//        "store g into 'output';";
-//        buildPlan( query );
-//    }
+    //    @Test // Commented out due to PIG-2037
+    //    public void testQuery104() throws Exception {
+    //        // check that a field alias can be referenced
+    //        // by unambiguous free form alias, fully qualified alias
+    //        // and partially qualified unambiguous alias
+    //        String query = "a = load 'st10k' as (name, age, gpa);\n"  +
+    //         "b = group a by name;\n"  +
+    //        "c = foreach b generate flatten(a);\n"  +
+    //        "d = filter c by name != 'fred';\n"  +
+    //        "e = group d by name;\n"  +
+    //        "f = foreach e generate flatten(d);\n"  +
+    //        "g = foreach f generate name, d::a::name, a::name;\n" +
+    //        "store g into 'output';";
+    //        buildPlan( query );
+    //    }
 
     @Test
     public void testQuery105() throws Exception {
@@ -1857,10 +1856,10 @@ public class TestLogicalPlanBuilder {
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals("bag_of_tokenTuples_from_f1:bag{tuple_of_tokens:tuple(token:chararray)}"));
     }
-    
+
     @Test
     public void testTokenizeSchema2()  throws Exception {
-        String query = "a = load 'one' as (f1: chararray, f2: chararray);" + 
+        String query = "a = load 'one' as (f1: chararray, f2: chararray);" +
         "b = foreach a generate TOKENIZE(f1), TOKENIZE(f2);" +
         "store b into 'output';";
         LogicalPlan lp = buildPlan(query);
@@ -1881,12 +1880,12 @@ public class TestLogicalPlanBuilder {
         LogicalExpressionPlan exprPlan = gen.getOutputPlans().get(0);
         Operator logOp = exprPlan.getSources().get(0);
         Assert.assertTrue( logOp instanceof ConstantExpression);
-        
+
         ConstantExpression loConst = (ConstantExpression)logOp;
         Assert.assertTrue(loConst.getType() == DataType.TUPLE);
         Assert.assertTrue(loConst.getValue() instanceof Tuple);
         Assert.assertTrue(loConst.getValue().equals(TupleFactory.getInstance().newTuple()));
- 
+
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals(":tuple()"));
     }
@@ -1901,16 +1900,16 @@ public class TestLogicalPlanBuilder {
         LogicalExpressionPlan exprPlan = gen.getOutputPlans().get(0);
         Operator logOp = exprPlan.getSources().get(0);
         Assert.assertTrue( logOp instanceof ConstantExpression);
-        
+
         ConstantExpression loConst = (ConstantExpression)logOp;
         Assert.assertTrue(loConst.getType() == DataType.MAP);
         Assert.assertTrue(loConst.getValue() instanceof Map);
         Assert.assertTrue(loConst.getValue().equals(new HashMap<String,Object>()));
-	
+
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals(":map"));
     }
-   
+
     @Test
     public void testEmptyBagConst() throws Exception{
         String query = "a = foreach (load 'b') generate {};" +
@@ -1922,12 +1921,12 @@ public class TestLogicalPlanBuilder {
         LogicalExpressionPlan exprPlan = gen.getOutputPlans().get(0);
         Operator logOp = exprPlan.getSources().get(0);
         Assert.assertTrue( logOp instanceof ConstantExpression);
-        
+
         ConstantExpression loConst = (ConstantExpression)logOp;
         Assert.assertTrue(loConst.getType() == DataType.BAG);
         Assert.assertTrue(loConst.getValue() instanceof DataBag);
         Assert.assertTrue(loConst.getValue().equals(BagFactory.getInstance().newDefaultBag()));
-        
+
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals(":bag{}") );
     }
@@ -1939,11 +1938,11 @@ public class TestLogicalPlanBuilder {
         LogicalPlan lp = buildPlan(query);
         Operator store = lp.getSinks().get(0);
         LOForEach foreach = (LOForEach) lp.getPredecessors(store).get(0);
-       
+
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals(":tuple(:tuple())") );
     }
-   
+
     @Test
     public void testEmptyTupConstRecursive2() throws Exception{
         String query = "a = foreach (load 'b') generate ([]);" +
@@ -1955,7 +1954,7 @@ public class TestLogicalPlanBuilder {
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals(":tuple(:map)") );
     }
-   
+
     @Test
     public void testEmptyTupConstRecursive3() throws Exception{
         String query = "a = foreach (load 'b') generate ({});" +
@@ -1963,11 +1962,11 @@ public class TestLogicalPlanBuilder {
         LogicalPlan lp = buildPlan(query);
         Operator op = lp.getSinks().get(0);
         LOForEach foreach = (LOForEach)lp.getPredecessors(op).get(0);
- 
+
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals(":tuple(:bag{})") );
     }
-   
+
     @Test
     public void testEmptyBagConstRecursive() throws Exception{
     	String query = "a = foreach (load 'b') generate {()};" +
@@ -1975,15 +1974,15 @@ public class TestLogicalPlanBuilder {
         LogicalPlan lp = buildPlan(query);
         Operator op = lp.getSinks().get(0);
         LOForEach foreach = (LOForEach)lp.getPredecessors(op).get(0);
-        
+
         String s = foreach.getSchema().toString(false);
         Assert.assertTrue( s.equals(":bag{:tuple()}") );
     }
-   
+
     @Test
     public void testRandomEmptyConst() throws Exception{
         // Various random scripts to test recursive nature of parser with empty constants.
-       
+
         buildPlan("a = foreach (load 'b') generate {({})}; store a into 'output';");
         buildPlan("a = foreach (load 'b') generate ({()}); store a into 'output';");
         buildPlan("a = foreach (load 'b') generate {(),()}; store a into 'output';");
@@ -1995,7 +1994,7 @@ public class TestLogicalPlanBuilder {
         buildPlan("a = foreach (load 'b') generate (({},{})); store a into 'output';");
         buildPlan("a = foreach (load 'b') generate (([],[])); store a into 'output';");
     }
-    
+
     @Test
     // See PIG-1024, shall not throw exception
     public void testLimitMultipleOutput() throws Exception {
@@ -2040,7 +2039,7 @@ public class TestLogicalPlanBuilder {
         Assert.assertEquals("An exception was expected but did " +
                 "not occur", true, exceptionThrown);
     }
-    
+
     @Test
     public void testMissingSemicolon() throws Exception {
         try {
@@ -2055,7 +2054,7 @@ public class TestLogicalPlanBuilder {
         }
         Assert.fail("An exception was expected but did not occur");
     }
-    
+
     @Test
     public void testCogroupByIncompatibleSchemaFailure() throws Exception {
         boolean exceptionThrown = false;
@@ -2076,7 +2075,7 @@ public class TestLogicalPlanBuilder {
         Assert.assertEquals("An exception was expected but did " +
                 "not occur", true, exceptionThrown);
     }
-    
+
     @Test
     public void testLoaderSignature() throws Exception {
     	String query = "a = load '1.txt' using org.apache.pig.test.PigStorageWithSchema() as (a0:int, a1:int);" +
@@ -2087,7 +2086,7 @@ public class TestLogicalPlanBuilder {
         // the signature is now a unique string of the format "{alias}_{scope id}-{id}" example: "a_12-0"
         String udfContextSignature = ((PigStorageWithSchema)(load).getLoadFunc()).getUDFContextSignature();
         Assert.assertTrue(udfContextSignature, udfContextSignature.matches("a_[0-9]*-[0-9]*"));
-        
+
         query = " b = load '1.txt' using org.apache.pig.test.PigStorageWithSchema();" +
                 "store b into 'output';";
         plan = buildPlan(query);
@@ -2096,14 +2095,14 @@ public class TestLogicalPlanBuilder {
         udfContextSignature = ((PigStorageWithSchema)(load).getLoadFunc()).getUDFContextSignature();
         Assert.assertTrue(udfContextSignature, udfContextSignature.matches("b_[0-9]*-[0-9]*"));
     }
-    
+
     @Test
     public void testLastAlias() throws Exception {
         try {
             String query = "B = load '2.txt' as (b0:int, b1:int);\n" +
             		"C = ORDER B by b0;" ;
             buildPlan( query );
-            
+
         } catch (AssertionFailedError e) {
             // Ignore the exception
         }
@@ -2113,7 +2112,7 @@ public class TestLogicalPlanBuilder {
     private void printPlan(LogicalExpressionPlan lp) {
         System.err.println( lp.toString() );
     }
-    
+
     private boolean checkPlanForProjectStar(LogicalExpressionPlan lp) {
         List<Operator> leaves = lp.getSinks();
 
@@ -2143,5 +2142,5 @@ public class TestLogicalPlanBuilder {
     	    throw new AssertionFailedError( msg );
     	}
     }
-    
+
 }

Added: pig/trunk/test/org/apache/pig/test/TestOrderBy3.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestOrderBy3.java?rev=1384352&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestOrderBy3.java (added)
+++ pig/trunk/test/org/apache/pig/test/TestOrderBy3.java Thu Sep 13 14:55:36 2012
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.test;
+
+import static org.apache.pig.builtin.mock.Storage.resetData;
+import static org.apache.pig.builtin.mock.Storage.tuple;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pig.ExecType;
+import org.apache.pig.PigServer;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.builtin.mock.Storage.Data;
+import org.apache.pig.data.DataType;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.apache.pig.impl.io.FileLocalizer;
+import org.apache.pig.test.utils.GenRandomData;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class TestOrderBy3 extends TestCase {
+
+    private final Log log = LogFactory.getLog(getClass());
+
+    private static PigServer pigServer;
+    private Data data;
+
+    private static final int MAX = 10;
+
+    private PigServer pig;
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        ArrayList<Tuple> tuples = new ArrayList<Tuple>();
+
+        try {
+            log.info("Setting up");
+
+            pigServer = new PigServer("local");
+            data = resetData(pigServer);
+
+            Random r = new Random();
+            for (int i = 0; i < MAX; i++) {
+                tuples.add(tuple(i,GenRandomData.genRandString(r)));
+            }
+
+            data.set("test", tuples);
+
+        } catch (ExecException e) {
+            IOException ioe = new IOException("Failed to create Pig Server");
+            ioe.initCause(e);
+            throw ioe;
+        }
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @AfterClass
+    public static void oneTimeTearDown() throws Exception {
+    }
+
+    public void testNames(boolean ascOrdering) throws Exception {
+        String order = (ascOrdering) ? "ASC" : "DESC";
+
+        String query = "A = load 'test' USING mock.Storage() as (index:int, name:chararray);" +
+        "B = order A by name " + order + ";" +
+        "store B into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Iterator<Tuple> it = data.get("result").iterator();
+
+        Tuple t1 = (Tuple) it.next();
+        Tuple t2 = (Tuple) it.next();
+
+        int comparision;
+        boolean resultComparision;
+        String value1, value2;
+
+        while (t2 != null) {
+
+            value1 = (String) t1.get(1);
+            value2 = (String) t2.get(1);
+
+            comparision = DataType.compare(value1, value2);
+            resultComparision = (ascOrdering) ? (comparision <= 0)
+                    : (comparision >= 0);
+
+            System.out.println("RESULT: " + value1 + "," + value2 + " = "
+                    + comparision);
+            assertEquals(true, resultComparision);
+
+            if(!it.hasNext()) break;
+
+            t1 = t2;
+            t2 = (Tuple) it.next();
+        }
+    }
+
+    public void testIndexes(boolean ascOrdering) throws Exception {
+
+        String order = (ascOrdering) ? "ASC" : "DESC";
+
+        String query = "A = load 'test' USING mock.Storage() as (index:int, name:chararray);" +
+        "B = order A by index " + order + ";" +
+        "store B into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Iterator<Tuple> it = data.get("result").iterator();
+
+
+        int toCompare, value;
+
+        for (int i = 0; i < MAX; i++) {
+
+            Tuple t = (Tuple) it.next();
+            value = DataType.toInteger(t.get(0));
+            toCompare = (ascOrdering) ? i : MAX - i - 1;
+
+            System.out.println("RESULT: " + toCompare + "," + value);
+
+            assertEquals(toCompare, value);
+        }
+
+        assertFalse(it.hasNext());
+    }
+
+    @Test
+    public void testIndexesAsc() throws Exception {
+        testIndexes(true);
+    }
+
+    @Test
+    public void testIndexesDesc() throws Exception {
+        testIndexes(false);
+    }
+
+    @Test
+    public void testValuesASC() throws Exception {
+        testNames(true);
+    }
+
+    @Test
+    public void testValuesDESC() throws Exception {
+        testNames(false);
+    }
+
+}

Added: pig/trunk/test/org/apache/pig/test/TestRank1.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestRank1.java?rev=1384352&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestRank1.java (added)
+++ pig/trunk/test/org/apache/pig/test/TestRank1.java Thu Sep 13 14:55:36 2012
@@ -0,0 +1,332 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.test;
+
+import static org.apache.pig.builtin.mock.Storage.resetData;
+import static org.apache.pig.builtin.mock.Storage.tuple;
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pig.PigServer;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.builtin.mock.Storage.Data;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+public class TestRank1 extends TestCase {
+
+    private final Log log = LogFactory.getLog(getClass());
+    private static TupleFactory tf = TupleFactory.getInstance();
+    private static PigServer pigServer;
+    private Data data;
+
+    @BeforeClass
+    public static void oneTimeSetUp() throws Exception {
+    }
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+
+        try {
+            pigServer = new PigServer("local");
+
+            data = resetData(pigServer);
+            data.set("test01", tuple("A", 1, "N"), tuple("B", 2, "N"),
+                    tuple("C", 3, "M"), tuple("D", 4, "P"), tuple("E", 4, "Q"),
+                    tuple("E", 4, "Q"), tuple("F", 8, "Q"), tuple("F", 7, "Q"),
+                    tuple("F", 8, "T"), tuple("F", 8, "Q"), tuple("G", 10, "V"));
+
+            data.set(
+                    "test02",
+                    tuple("Michael", "Blythe", 1, 1, 1, 1, 4557045.046, 98027),
+                    tuple("Linda", "Mitchell", 2, 1, 1, 1, 5200475.231, 98027),
+                    tuple("Jillian", "Carson", 3, 1, 1, 1, 3857163.633, 98027),
+                    tuple("Garrett", "Vargas", 4, 1, 1, 1, 1764938.986, 98027),
+                    tuple("Tsvi", "Reiter", 5, 1, 1, 2, 2811012.715, 98027),
+                    tuple("Shu", "Ito", 6, 6, 2, 2, 3018725.486, 98055),
+                    tuple("Jose", "Saraiva", 7, 6, 2, 2, 3189356.247, 98055),
+                    tuple("David", "Campbell", 8, 6, 2, 3, 3587378.426, 98055),
+                    tuple("Tete", "Mensa-Annan", 9, 6, 2, 3, 1931620.184, 98055),
+                    tuple("Lynn", "Tsoflias", 10, 6, 2, 3, 1758385.926, 98055),
+                    tuple("Rachel", "Valdez", 11, 6, 2, 4, 2241204.042, 98055),
+                    tuple("Jae", "Pak", 12, 6, 2, 4, 5015682.375, 98055),
+                    tuple("Ranjit", "Varkey Chudukatil", 13, 6, 2, 4,
+                            3827950.238, 98055));
+
+        } catch (ExecException e) {
+            IOException ioe = new IOException("Failed to create Pig Server");
+            ioe.initCause(e);
+            throw ioe;
+        }
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @AfterClass
+    public static void oneTimeTearDown() throws Exception {
+    }
+
+    @Test
+    public void testRank01RowNumber() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "A", 1, "N")),
+                tf.newTuple(ImmutableList.of((long) 2, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 3, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 4, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 5, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 7, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 9, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 10, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 11, "G", 10, "V")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank02RowNumber() throws IOException {
+        String query = "A = LOAD 'test02' USING mock.Storage() AS (firstname:chararray,lastname:chararray,rownumberPrev:int,rankPrev:int,denserankPrev:int,quartilePrev:int,sales:double,postalcode:int);"
+            + "B = rank A;"
+            + "store B into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "Michael", "Blythe", 1,1, 1, 1, 4557045.046, 98027)),
+                tf.newTuple(ImmutableList.of((long) 2, "Linda","Mitchell", 2, 1, 1, 1, 5200475.231, 98027)),
+                tf.newTuple(ImmutableList.of((long) 3, "Jillian", "Carson", 3,1, 1, 1, 3857163.633, 98027)),
+                tf.newTuple(ImmutableList.of((long) 4, "Garrett","Vargas", 4, 1, 1, 1, 1764938.986, 98027)),
+                tf.newTuple(ImmutableList.of((long) 5, "Tsvi", "Reiter",5, 1, 1, 2, 2811012.715, 98027)),
+                tf.newTuple(ImmutableList.of((long) 6, "Shu", "Ito", 6,6, 2, 2, 3018725.486, 98055)),
+                tf.newTuple(ImmutableList.of((long) 7, "Jose", "Saraiva",7, 6, 2, 2, 3189356.247, 98055)),
+                tf.newTuple(ImmutableList.of((long) 8, "David","Campbell", 8, 6, 2, 3, 3587378.426, 98055)),
+                tf.newTuple(ImmutableList.of((long) 9, "Tete", "Mensa-Annan",9, 6, 2, 3, 1931620.184, 98055)),
+                tf.newTuple(ImmutableList.of((long) 10, "Lynn","Tsoflias", 10, 6, 2, 3, 1758385.926, 98055)),
+                tf.newTuple(ImmutableList.of((long) 11, "Rachel", "Valdez", 11,6, 2, 4, 2241204.042, 98055)),
+                tf.newTuple(ImmutableList.of((long) 12, "Jae", "Pak", 12,6, 2, 4, 5015682.375, 98055)),
+                tf.newTuple(ImmutableList.of((long) 13, "Ranjit","Varkey Chudukatil", 13, 6, 2, 4, 3827950.238,98055)));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank01RankBy() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f3;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 2, "A", 1, "N")),
+                tf.newTuple(ImmutableList.of((long) 2, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 4, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 5, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 10, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 11, "G", 10, "V")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank02RankBy() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f2 ASC;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "A", 1, "N")),
+                tf.newTuple(ImmutableList.of((long) 2, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 3, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 4, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 4, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 4, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 7, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 11, "G", 10, "V")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank03RankBy() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f1 DESC;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "G", 10, "V")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 9, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 10, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 11, "A", 1, "N")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank04RankBy() throws IOException {
+        String query = "A = LOAD 'test02' USING mock.Storage() AS (firstname:chararray,lastname:chararray,rownumberPrev:int,rankPrev:int,denserankPrev:int,quartilePrev:int,sales:double,postalcode:int);"
+            + "C = rank A by postalcode;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "Michael", "Blythe", 1,1, 1, 1, 4557045.046, 98027)),
+                tf.newTuple(ImmutableList.of((long) 1, "Linda","Mitchell", 2, 1, 1, 1, 5200475.231, 98027)),
+                tf.newTuple(ImmutableList.of((long) 1, "Jillian", "Carson", 3,1, 1, 1, 3857163.633, 98027)),
+                tf.newTuple(ImmutableList.of((long) 1, "Garrett","Vargas", 4, 1, 1, 1, 1764938.986, 98027)),
+                tf.newTuple(ImmutableList.of((long) 1, "Tsvi", "Reiter",5, 1, 1, 2, 2811012.715, 98027)),
+                tf.newTuple(ImmutableList.of((long) 6, "Shu", "Ito", 6,6, 2, 2, 3018725.486, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Jose", "Saraiva",7, 6, 2, 2, 3189356.247, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "David","Campbell", 8, 6, 2, 3, 3587378.426, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Tete", "Mensa-Annan",9, 6, 2, 3, 1931620.184, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Lynn","Tsoflias", 10, 6, 2, 3, 1758385.926, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Rachel", "Valdez", 11,6, 2, 4, 2241204.042, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Jae", "Pak", 12,6, 2, 4, 5015682.375, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Ranjit","Varkey Chudukatil", 13, 6, 2, 4, 3827950.238,98055)));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank05RankBy() throws IOException {
+        String query = "A = LOAD 'test02' USING mock.Storage() AS (firstname:chararray,lastname:chararray,rownumberPrev:int,rankPrev:int,denserankPrev:int,quartilePrev:int,sales:double,postalcode:int);"
+            + "C = rank A by *;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "David", "Campbell", 8,6, 2, 3, 3587378.426, 98055)),
+                tf.newTuple(ImmutableList.of((long) 2, "Garrett","Vargas", 4, 1, 1, 1, 1764938.986, 98027)),
+                tf.newTuple(ImmutableList.of((long) 3, "Jae", "Pak", 12,6, 2, 4, 5015682.375, 98055)),
+                tf.newTuple(ImmutableList.of((long) 4, "Jillian","Carson", 3, 1, 1, 1, 3857163.633, 98027)),
+                tf.newTuple(ImmutableList.of((long) 5, "Jose", "Saraiva",7, 6, 2, 2, 3189356.247, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Linda","Mitchell", 2, 1, 1, 1, 5200475.231, 98027)),
+                tf.newTuple(ImmutableList.of((long) 7, "Lynn", "Tsoflias", 10,6, 2, 3, 1758385.926, 98055)),
+                tf.newTuple(ImmutableList.of((long) 8, "Michael","Blythe", 1, 1, 1, 1, 4557045.046, 98027)),
+                tf.newTuple(ImmutableList.of((long) 9, "Rachel","Valdez", 11, 6, 2, 4, 2241204.042, 98055)),
+                tf.newTuple(ImmutableList.of((long) 10, "Ranjit","Varkey Chudukatil", 13, 6, 2, 4, 3827950.238, 98055)),
+                tf.newTuple(ImmutableList.of((long) 11, "Shu", "Ito", 6, 6, 2, 2, 3018725.486,98055)),
+                tf.newTuple(ImmutableList.of((long) 12, "Tete", "Mensa-Annan", 9, 6, 2, 3,1931620.184, 98055)),
+                tf.newTuple(ImmutableList.of((long) 13, "Tsvi", "Reiter", 5, 1, 1, 2, 2811012.715,98027)));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank06RankBy() throws IOException {
+        String query = "A = LOAD 'test02' USING mock.Storage() AS (firstname:chararray,lastname:chararray,rownumberPrev:int,rankPrev:int,denserankPrev:int,quartilePrev:int,sales:double,postalcode:int);"
+            + "C = rank A by $0..$2;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "David", "Campbell", 8, 6, 2, 3, 3587378.426, 98055)),
+                tf.newTuple(ImmutableList.of((long) 2, "Garrett","Vargas", 4, 1, 1, 1, 1764938.986, 98027)),
+                tf.newTuple(ImmutableList.of((long) 3, "Jae", "Pak", 12,6, 2, 4, 5015682.375, 98055)),
+                tf.newTuple(ImmutableList.of((long) 4, "Jillian","Carson", 3, 1, 1, 1, 3857163.633, 98027)),
+                tf.newTuple(ImmutableList.of((long) 5, "Jose", "Saraiva",7, 6, 2, 2, 3189356.247, 98055)),
+                tf.newTuple(ImmutableList.of((long) 6, "Linda","Mitchell", 2, 1, 1, 1, 5200475.231, 98027)),
+                tf.newTuple(ImmutableList.of((long) 7, "Lynn", "Tsoflias", 10,6, 2, 3, 1758385.926, 98055)),
+                tf.newTuple(ImmutableList.of((long) 8, "Michael","Blythe", 1, 1, 1, 1, 4557045.046, 98027)),
+                tf.newTuple(ImmutableList.of((long) 9, "Rachel","Valdez", 11, 6, 2, 4, 2241204.042, 98055)),
+                tf.newTuple(ImmutableList.of((long) 10, "Ranjit","Varkey Chudukatil", 13, 6, 2, 4, 3827950.238, 98055)),
+                tf.newTuple(ImmutableList.of((long) 11, "Shu", "Ito", 6, 6, 2, 2, 3018725.486,98055)),
+                tf.newTuple(ImmutableList.of((long) 12, "Tete", "Mensa-Annan", 9, 6, 2, 3,1931620.184, 98055)),
+                tf.newTuple(ImmutableList.of((long) 13, "Tsvi", "Reiter", 5, 1, 1, 2, 2811012.715,98027)));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank07RankBy() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f1..f3;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "A", 1, "N")),
+                tf.newTuple(ImmutableList.of((long) 2, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 3, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 4, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 5, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 7, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 10, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 11, "G", 10, "V")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    public void verifyExpected(List<Tuple> out, Set<Tuple> expected) {
+
+        for (Tuple tup : out) {
+            assertTrue(expected + " contains " + tup, expected.contains(tup));
+        }
+    }
+
+}

Added: pig/trunk/test/org/apache/pig/test/TestRank2.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestRank2.java?rev=1384352&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestRank2.java (added)
+++ pig/trunk/test/org/apache/pig/test/TestRank2.java Thu Sep 13 14:55:36 2012
@@ -0,0 +1,206 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.test;
+
+import static org.apache.pig.builtin.mock.Storage.resetData;
+import static org.apache.pig.builtin.mock.Storage.tuple;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pig.PigServer;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.builtin.mock.Storage.Data;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+public class TestRank2 extends TestCase {
+
+    private final Log log = LogFactory.getLog(getClass());
+    private static PigServer pigServer;
+    private static TupleFactory tf = TupleFactory.getInstance();
+    private Data data;
+
+    @BeforeClass
+    public static void oneTimeSetUp() throws Exception {
+    }
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+
+        try {
+            pigServer = new PigServer("local");
+
+            data = resetData(pigServer);
+            data.set("test01", tuple("A", 1, "N"), tuple("B", 2, "N"),
+                    tuple("C", 3, "M"), tuple("D", 4, "P"), tuple("E", 4, "Q"),
+                    tuple("E", 4, "Q"), tuple("F", 8, "Q"), tuple("F", 7, "Q"),
+                    tuple("F", 8, "T"), tuple("F", 8, "Q"), tuple("G", 10, "V"));
+
+            data.set(
+                    "test02",
+                    tuple("Michael", "Blythe", 1, 1, 1, 1, 4557045.046, 98027),
+                    tuple("Linda", "Mitchell", 2, 1, 1, 1, 5200475.231, 98027),
+                    tuple("Jillian", "Carson", 3, 1, 1, 1, 3857163.633, 98027),
+                    tuple("Garrett", "Vargas", 4, 1, 1, 1, 1764938.986, 98027),
+                    tuple("Tsvi", "Reiter", 5, 1, 1, 2, 2811012.715, 98027),
+                    tuple("Shu", "Ito", 6, 6, 2, 2, 3018725.486, 98055),
+                    tuple("Jose", "Saraiva", 7, 6, 2, 2, 3189356.247, 98055),
+                    tuple("David", "Campbell", 8, 6, 2, 3, 3587378.426, 98055),
+                    tuple("Tete", "Mensa-Annan", 9, 6, 2, 3, 1931620.184, 98055),
+                    tuple("Lynn", "Tsoflias", 10, 6, 2, 3, 1758385.926, 98055),
+                    tuple("Rachel", "Valdez", 11, 6, 2, 4, 2241204.042, 98055),
+                    tuple("Jae", "Pak", 12, 6, 2, 4, 5015682.375, 98055),
+                    tuple("Ranjit", "Varkey Chudukatil", 13, 6, 2, 4,
+                            3827950.238, 98055));
+
+        } catch (ExecException e) {
+            IOException ioe = new IOException("Failed to create Pig Server");
+            ioe.initCause(e);
+            throw ioe;
+        }
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @AfterClass
+    public static void oneTimeTearDown() throws Exception {
+    }
+
+    @Test
+    public void testRank01RankByDense() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f3 DENSE;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 2, "A", 1, "N")),
+                tf.newTuple(ImmutableList.of((long) 2, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 3, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 4, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 4, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 4, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 4, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 4, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 6, "G", 10, "V")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank02RankByDense() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f2 ASC DENSE;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "A", 1, "N")),
+                tf.newTuple(ImmutableList.of((long) 2, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 3, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 4, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 4, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 4, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 7, "G", 10, "V")));
+
+        verifyExpected(data.get("result"), expected);
+
+    }
+
+    @Test
+    public void testRank03RankByDense() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f1 DESC DENSE;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "G", 10, "V")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 2, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 3, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 3, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 4, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 5, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 6, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 7, "A", 1, "N")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    @Test
+    public void testRank04RankByDense() throws IOException {
+        String query = "A = LOAD 'test01' USING mock.Storage() AS (f1:chararray,f2:int,f3:chararray);"
+            + "C = rank A by f1, f2 DESC DENSE;"
+            + "store C into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long) 1, "A", 1, "N")),
+                tf.newTuple(ImmutableList.of((long) 2, "B", 2, "N")),
+                tf.newTuple(ImmutableList.of((long) 3, "C", 3, "M")),
+                tf.newTuple(ImmutableList.of((long) 4, "D", 4, "P")),
+                tf.newTuple(ImmutableList.of((long) 5, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 5, "E", 4, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "F", 8, "Q")),
+                tf.newTuple(ImmutableList.of((long) 6, "F", 8, "T")),
+                tf.newTuple(ImmutableList.of((long) 7, "F", 7, "Q")),
+                tf.newTuple(ImmutableList.of((long) 8, "G", 10, "V")));
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    public void verifyExpected(List<Tuple> out, Set<Tuple> expected) {
+
+        for (Tuple tup : out) {
+            assertTrue(expected + " contains " + tup, expected.contains(tup));
+        }
+    }
+
+}

Added: pig/trunk/test/org/apache/pig/test/TestRank3.java
URL: http://svn.apache.org/viewvc/pig/trunk/test/org/apache/pig/test/TestRank3.java?rev=1384352&view=auto
==============================================================================
--- pig/trunk/test/org/apache/pig/test/TestRank3.java (added)
+++ pig/trunk/test/org/apache/pig/test/TestRank3.java Thu Sep 13 14:55:36 2012
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pig.test;
+
+import static org.apache.pig.builtin.mock.Storage.resetData;
+import static org.apache.pig.builtin.mock.Storage.tuple;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.pig.PigServer;
+import org.apache.pig.backend.executionengine.ExecException;
+import org.apache.pig.builtin.mock.Storage.Data;
+import org.apache.pig.data.Tuple;
+import org.apache.pig.data.TupleFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+public class TestRank3 extends TestCase {
+
+    private final Log log = LogFactory.getLog(getClass());
+    private static PigServer pigServer;
+    private static TupleFactory tf = TupleFactory.getInstance();
+    private Data data;
+
+    @BeforeClass
+    public static void oneTimeSetUp() throws Exception {
+    }
+
+    @Override
+    @Before
+    public void setUp() throws Exception {
+
+        try {
+            pigServer = new PigServer("local");
+
+            data = resetData(pigServer);
+            data.set(
+                    "testcascade",
+                    tuple(3,2,3),
+                    tuple(2,7,10),
+                    tuple(1,0,2),
+                    tuple(5,6,0),
+                    tuple(7,4,8),
+                    tuple(9,8,4),
+                    tuple(1,9,10),
+                    tuple(7,4,4),
+                    tuple(5,7,6),
+                    tuple(4,6,10),
+                    tuple(5,7,2),
+                    tuple(6,4,5),
+                    tuple(6,0,0),
+                    tuple(1,7,2),
+                    tuple(7,5,6),
+                    tuple(9,1,9),
+                    tuple(9,8,8),
+                    tuple(9,9,6),
+                    tuple(5,6,5),
+                    tuple(3,8,1),
+                    tuple(7,0,6),
+                    tuple(0,8,8),
+                    tuple(6,9,10),
+                    tuple(7,10,1),
+                    tuple(7,8,0),
+                    tuple(8,7,9),
+                    tuple(8,3,5),
+                    tuple(1,3,10),
+                    tuple(9,7,4),
+                    tuple(9,4,4));
+
+        } catch (ExecException e) {
+            IOException ioe = new IOException("Failed to create Pig Server");
+            ioe.initCause(e);
+            throw ioe;
+        }
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+    }
+
+    @AfterClass
+    public static void oneTimeTearDown() throws Exception {
+    }
+
+    @Test
+    public void testRankCascade() throws IOException {
+        String query = "R1 = LOAD 'testcascade' USING mock.Storage() AS (a:long,b:long,c:long);"
+            + "R2 = rank R1 by a ASC,b ASC DENSE;"
+            + "R3 = rank R2 by a ASC,c DESC DENSE;"
+            + "R4 = rank R3 by b DESC,c ASC DENSE;"
+            + "R5 = rank R4 by b DESC,a ASC;"
+            + "R6 = rank R5 by c ASC,b DESC;"
+            + "R7 = order R6 by a ASC,c DESC,b DESC;"
+            + "R8 = rank R7;"
+            + "store R8 into 'result' using mock.Storage();";
+
+        Util.registerMultiLineQuery(pigServer, query);
+
+        Set<Tuple> expected = ImmutableSet.of(
+                tf.newTuple(ImmutableList.of((long)1,(long)21,(long)5,(long)7,(long)1,(long)1,(long)0,(long)8,(long)8)),
+                tf.newTuple(ImmutableList.of((long)2,(long)26,(long)2,(long)3,(long)2,(long)5,(long)1,(long)9,(long)10)),
+                tf.newTuple(ImmutableList.of((long)3,(long)30,(long)24,(long)21,(long)2,(long)3,(long)1,(long)3,(long)10)),
+                tf.newTuple(ImmutableList.of((long)4,(long)6,(long)10,(long)8,(long)3,(long)4,(long)1,(long)7,(long)2)),
+                tf.newTuple(ImmutableList.of((long)5,(long)8,(long)28,(long)25,(long)3,(long)2,(long)1,(long)0,(long)2)),
+                tf.newTuple(ImmutableList.of((long)6,(long)28,(long)11,(long)12,(long)4,(long)6,(long)2,(long)7,(long)10)),
+                tf.newTuple(ImmutableList.of((long)7,(long)9,(long)26,(long)22,(long)5,(long)7,(long)3,(long)2,(long)3)),
+                tf.newTuple(ImmutableList.of((long)8,(long)5,(long)6,(long)5,(long)6,(long)8,(long)3,(long)8,(long)1)),
+                tf.newTuple(ImmutableList.of((long)9,(long)29,(long)16,(long)15,(long)7,(long)9,(long)4,(long)6,(long)10)),
+                tf.newTuple(ImmutableList.of((long)10,(long)18,(long)12,(long)10,(long)8,(long)11,(long)5,(long)7,(long)6)),
+                tf.newTuple(ImmutableList.of((long)11,(long)14,(long)17,(long)14,(long)9,(long)10,(long)5,(long)6,(long)5)),
+                tf.newTuple(ImmutableList.of((long)12,(long)6,(long)12,(long)8,(long)10,(long)11,(long)5,(long)7,(long)2)),
+                tf.newTuple(ImmutableList.of((long)13,(long)2,(long)17,(long)13,(long)11,(long)10,(long)5,(long)6,(long)0)),
+                tf.newTuple(ImmutableList.of((long)14,(long)26,(long)3,(long)3,(long)12,(long)14,(long)6,(long)9,(long)10)),
+                tf.newTuple(ImmutableList.of((long)15,(long)15,(long)20,(long)18,(long)13,(long)13,(long)6,(long)4,(long)5)),
+                tf.newTuple(ImmutableList.of((long)16,(long)3,(long)29,(long)24,(long)14,(long)12,(long)6,(long)0,(long)0)),
+                tf.newTuple(ImmutableList.of((long)17,(long)23,(long)21,(long)19,(long)15,(long)16,(long)7,(long)4,(long)8)),
+                tf.newTuple(ImmutableList.of((long)18,(long)19,(long)19,(long)16,(long)16,(long)17,(long)7,(long)5,(long)6)),
+                tf.newTuple(ImmutableList.of((long)19,(long)20,(long)30,(long)26,(long)16,(long)15,(long)7,(long)0,(long)6)),
+                tf.newTuple(ImmutableList.of((long)20,(long)12,(long)21,(long)17,(long)17,(long)16,(long)7,(long)4,(long)4)),
+                tf.newTuple(ImmutableList.of((long)21,(long)4,(long)1,(long)1,(long)18,(long)19,(long)7,(long)10,(long)1)),
+                tf.newTuple(ImmutableList.of((long)22,(long)1,(long)7,(long)4,(long)19,(long)18,(long)7,(long)8,(long)0)),
+                tf.newTuple(ImmutableList.of((long)23,(long)24,(long)14,(long)11,(long)20,(long)21,(long)8,(long)7,(long)9)),
+                tf.newTuple(ImmutableList.of((long)24,(long)16,(long)25,(long)20,(long)21,(long)20,(long)8,(long)3,(long)5)),
+                tf.newTuple(ImmutableList.of((long)25,(long)25,(long)27,(long)23,(long)22,(long)22,(long)9,(long)1,(long)9)),
+                tf.newTuple(ImmutableList.of((long)26,(long)21,(long)8,(long)7,(long)23,(long)25,(long)9,(long)8,(long)8)),
+                tf.newTuple(ImmutableList.of((long)27,(long)17,(long)4,(long)2,(long)24,(long)26,(long)9,(long)9,(long)6)),
+                tf.newTuple(ImmutableList.of((long)28,(long)10,(long)8,(long)6,(long)25,(long)25,(long)9,(long)8,(long)4)),
+                tf.newTuple(ImmutableList.of((long)29,(long)11,(long)15,(long)9,(long)25,(long)24,(long)9,(long)7,(long)4)),
+                tf.newTuple(ImmutableList.of((long)30,(long)12,(long)23,(long)17,(long)25,(long)23,(long)9,(long)4,(long)4))
+        );
+
+        verifyExpected(data.get("result"), expected);
+    }
+
+    public void verifyExpected(List<Tuple> out, Set<Tuple> expected) {
+
+        for (Tuple tup : out) {
+            assertTrue(expected + " contains " + tup, expected.contains(tup));
+        }
+    }
+
+}