Package org.apache.pig.test.utils

Examples of org.apache.pig.test.utils.LogicalPlanTester


    }
   
    @SuppressWarnings("unchecked")
    public void testPruneWithMapKey() throws Exception {
         // only foreach
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, m:map[]);");
        lpt.buildPlan("b = foreach a generate id, m#'path';");       
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan("store b into 'empty';")
        LogicalPlan newLogicalPlan = migratePlan(plan);
              
        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, m:map[]);");
        lpt.buildPlan("b = foreach a generate id, m#'path';");       
        plan = lpt.buildPlan("store b into 'empty';")
        LogicalPlan expected = migratePlan(plan);
       
        assertTrue(expected.isEqual(newLogicalPlan));
       
        LOLoad op = (LOLoad)newLogicalPlan.getSources().get(0);
        Map<Integer,Set<String>> annotation =
                (Map<Integer, Set<String>>) op.getAnnotation(MapKeysPruneHelper.REQUIRED_MAPKEYS);
        assertEquals(annotation.size(), 1);
        Set<String> s = new HashSet<String>();
        s.add("path");
        assertEquals(annotation.get(2), s);
       
        // foreach with join
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, m:map[]);");
        lpt.buildPlan("b = load 'd.txt' as (id, v1, m:map[]);");
        lpt.buildPlan("c = join a by id, b by id;");
        lpt.buildPlan("d = filter c by a::m#'path' != NULL;");
        lpt.buildPlan("e = foreach d generate a::id, b::id, b::m#'path', a::m;");       
        plan = lpt.buildPlan("store e into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, m:map[]);");
        lpt.buildPlan("b = load 'd.txt' as (id, m:map[]);");
        lpt.buildPlan("c = join a by id, b by id;");
        lpt.buildPlan("d = filter c by a::m#'path' != NULL;");
        lpt.buildPlan("e = foreach d generate a::id, b::id, b::m#'path', a::m;");       
        plan = lpt.buildPlan("store e into 'empty';")
        expected = migratePlan(plan);
       
        assertTrue(expected.isEqual(newLogicalPlan));
       
        List<Operator> ll = newLogicalPlan.getSources();
View Full Code Here


        assertEquals(annotation.get(2), s);
    }
   
    public void testPruneWithBag() throws Exception  {
        // filter above foreach
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v:bag{t:(s1,s2,s3)});");
        lpt.buildPlan("b = filter a by id>10;");
        lpt.buildPlan("c = foreach b generate id, FLATTEN(v);");   
        lpt.buildPlan("d = foreach c generate id, v::s2;");   
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan("store d into 'empty';")
        LogicalPlan newLogicalPlan = migratePlan(plan);
              
        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v:bag{t:(s1,s2,s3)});");
        lpt.buildPlan("b = filter a by id>10;");
        lpt.buildPlan("c = foreach b generate id, FLATTEN(v);");   
        lpt.buildPlan("d = foreach c generate id, v::s2;");   
        plan = lpt.buildPlan("store d into 'empty';");
        LogicalPlan expected = migratePlan(plan);
       
        assertTrue(expected.isEqual(newLogicalPlan));
    }
View Full Code Here

        assertTrue(expected.isEqual(newLogicalPlan));
    }
   
    public void testAddForeach() throws Exception  {
        // filter above foreach
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v2);");
        lpt.buildPlan("b = filter a by v1>10;");
        lpt.buildPlan("c = foreach b generate id;");       
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan("store c into 'empty';")
        LogicalPlan newLogicalPlan = migratePlan(plan);
              
        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1);");
        lpt.buildPlan("b = filter a by v1>10;");
        lpt.buildPlan("c = foreach b generate id;");     
        plan = lpt.buildPlan("store c into 'empty';")
        LogicalPlan expected = migratePlan(plan);
       
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // join with foreach
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v2);");
        lpt.buildPlan("b = load 'd.txt' as (id, v1, v2);");
        lpt.buildPlan("c = join a by id, b by id;");
        lpt.buildPlan("d = filter c by a::v1>b::v1;");
        lpt.buildPlan("e = foreach d generate a::id;");       
        plan = lpt.buildPlan("store e into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1);");
        lpt.buildPlan("b = load 'd.txt' as (id, v1);");
        lpt.buildPlan("c = join a by id, b by id;");
        lpt.buildPlan("d = foreach c generate a::id, a::v1, b::v1;");       
        lpt.buildPlan("e = filter d by a::v1>b::v1;")
        lpt.buildPlan("f = foreach e generate a::id;");       
        plan = lpt.buildPlan("store f into 'empty';")
        expected = migratePlan(plan);
       
        assertTrue(expected.isEqual(newLogicalPlan));
    }
View Full Code Here

    }
   
  
    public void testNoPrune() throws Exception  {
        // no foreach
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v2);");
        lpt.buildPlan("b = filter a by v1==NULL;");       
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan("store b into 'empty';")
        LogicalPlan newLogicalPlan = migratePlan(plan);
              
        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v2);");
        lpt.buildPlan("b = filter a by v1==NULL;");       
        plan = lpt.buildPlan("store b into 'empty';")
        LogicalPlan expected = migratePlan(plan);
       
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // no schema
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt';");
        lpt.buildPlan("b = foreach a generate $0, $1;");
        plan = lpt.buildPlan("store b into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt';");
        lpt.buildPlan("b = foreach a generate $0, $1;");
        plan = lpt.buildPlan("store b into 'empty';")
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
    }
View Full Code Here

        assertTrue(expected.isEqual(newLogicalPlan));
    }
      
    public void testPrune() throws Exception  {
        // only foreach
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v2);");
        lpt.buildPlan("b = foreach a generate id;");       
        org.apache.pig.impl.logicalLayer.LogicalPlan plan = lpt.buildPlan("store b into 'empty';")
        LogicalPlan newLogicalPlan = migratePlan(plan);
              
        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id);");
        lpt.buildPlan("b = foreach a generate id;");       
        plan = lpt.buildPlan("store b into 'empty';")
        LogicalPlan expected = migratePlan(plan);
       
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // with filter
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v5, v3, v4, v2);");
        lpt.buildPlan("b = filter a by v1 != NULL AND (v2+v3)<100;");
        lpt.buildPlan("c = foreach b generate id;");
        plan = lpt.buildPlan("store c into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v3, v2);");
        lpt.buildPlan("b = filter a by v1 != NULL AND (v2+v3)<100;");
        lpt.buildPlan("c = foreach b generate id;");
        plan = lpt.buildPlan("store c into 'empty';");
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // with 2 foreach
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v5, v3, v4, v2);");
        lpt.buildPlan("b = foreach a generate v2, v5, v4;");
        lpt.buildPlan("c = foreach b generate v5, v4;");
        plan = lpt.buildPlan("store c into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (v5, v4);");
        lpt.buildPlan("b = foreach a generate v5, v4;");
        lpt.buildPlan("c = foreach b generate v5, v4;");
        plan = lpt.buildPlan("store c into 'empty';");
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // with 2 foreach
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v5, v3, v4, v2);");
        lpt.buildPlan("b = foreach a generate id, v1, v5, v3, v4;");
        lpt.buildPlan("c = foreach b generate v5, v4;");
        plan = lpt.buildPlan("store c into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (v5, v4);");
        lpt.buildPlan("b = foreach a generate v5, v4;");
        lpt.buildPlan("c = foreach b generate v5, v4;");
        plan = lpt.buildPlan("store c into 'empty';");
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // with 2 foreach and filter in between
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v5, v3, v4, v2);");
        lpt.buildPlan("b = foreach a generate v2, v5, v4;");
        lpt.buildPlan("c = filter b by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5, v4;");
        plan = lpt.buildPlan("store d into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (v5, v4, v2);");
        lpt.buildPlan("b = foreach a generate v2, v5, v4;");
        lpt.buildPlan("c = filter b by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5, v4;");
        plan = lpt.buildPlan("store d into 'empty';")
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // with 2 foreach after join
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v1, v2, v3);");
        lpt.buildPlan("b = load 'c.txt' as (id, v4, v5, v6);");
        lpt.buildPlan("c = join a by id, b by id;");      
        lpt.buildPlan("d = foreach c generate a::id, v5, v3, v4;");
        plan = lpt.buildPlan("store d into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' as (id, v3);");
        lpt.buildPlan("b = load 'c.txt' as (id, v4, v5);");
        lpt.buildPlan("c = join a by id, b by id;")
        lpt.buildPlan("d = foreach c generate a::id, v5, v3, v4;");
        plan = lpt.buildPlan("store d into 'empty';")
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
       
        // with BinStorage, insert foreach after load
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);");       
        lpt.buildPlan("c = filter a by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5, v4;");
        plan = lpt.buildPlan("store d into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);");
        lpt.buildPlan("b = foreach a generate v5, v4, v2;");
        lpt.buildPlan("c = filter b by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5, v4;");
        plan = lpt.buildPlan("store d into 'empty';")
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
       
       // with BinStorage, not to insert foreach after load if there is already one
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);");   
        lpt.buildPlan("b = foreach a generate v5, v4, v2;");
        lpt.buildPlan("c = filter b by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5;");
        plan = lpt.buildPlan("store d into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);");
        lpt.buildPlan("b = foreach a generate v5, v2;");
        lpt.buildPlan("c = filter b by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5;");
        plan = lpt.buildPlan("store d into 'empty';")
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
       
       // with BinStorage, not to insert foreach after load if there is already one
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);");   
        lpt.buildPlan("b = foreach a generate v5, v4, v2, 10;");
        lpt.buildPlan("c = filter b by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5;");
        plan = lpt.buildPlan("store d into 'empty';")
        newLogicalPlan = migratePlan(plan);
              
        optimizer = new MyPlanOptimizer(newLogicalPlan, 3);
        optimizer.optimize();
       
        lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'd.txt' using BinStorage() as (id, v1, v5, v3, v4, v2);");
        lpt.buildPlan("b = foreach a generate v5, v2, 10;");
        lpt.buildPlan("c = filter b by v2 != NULL;");
        lpt.buildPlan("d = foreach c generate v5;");
        plan = lpt.buildPlan("store d into 'empty';")
        expected = migratePlan(plan);
        assertTrue(expected.isEqual(newLogicalPlan));
    }
View Full Code Here

    static PigContext pc = new PigContext(ExecType.LOCAL, new Properties());
    static LogicalPlanTester lpTester;
   
    @BeforeClass
    public static void setup() throws Exception {
        lpTester = new LogicalPlanTester(pc);
        lpTester.buildPlan("a = load 'foo' as (srcid, mrkt, dstid, name, age);");
    }
View Full Code Here

     * tests sortinfo for the case where order by is ascending on
     * all sort columns
     */
    @Test
    public void testSortInfoAsc() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'bla' as (i:int, n:chararray, d:double);");
        lpt.buildPlan("b = order a by i, d;");
        LogicalPlan lp = lpt.buildPlan("store b into 'foo';");
        PigServer.SortInfoSetter siSetter = new PigServer.SortInfoSetter(lp);
        siSetter.visit();
        PhysicalPlan pp = buildPhysicalPlan(lp);
        SortInfo si = ((POStore)(pp.getLeaves().get(0))).getSortInfo();
        SortInfo expected = getSortInfo(
View Full Code Here

     * tests sortInfo for mixed ascending and descending in order by
     * @throws Exception
     */
    @Test
    public void testSortInfoAscDesc() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'bla' as (i:int, n:chararray, d:double);");
        lpt.buildPlan("b = filter a by i > 10;");
        lpt.buildPlan("c = order b by i desc, d;");
        LogicalPlan lp = lpt.buildPlan("store c into 'foo';");
        PigServer.SortInfoSetter siSetter = new PigServer.SortInfoSetter(lp);
        siSetter.visit();
        PhysicalPlan pp = buildPhysicalPlan(lp);
        SortInfo si = ((POStore)(pp.getLeaves().get(0))).getSortInfo();
        SortInfo expected = getSortInfo(
View Full Code Here

     * before the store
     * @throws Exception
     */
    @Test
    public void testSortInfoNoOrderBy1() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'bla' as (i:int, n:chararray, d:double);");
        lpt.buildPlan("b = filter a by i > 10;");
        LogicalPlan lp = lpt.buildPlan("store b into 'foo';");
        PigServer.SortInfoSetter siSetter = new PigServer.SortInfoSetter(lp);
        siSetter.visit();
        PhysicalPlan pp = buildPhysicalPlan(lp);
        SortInfo si = ((POStore)(pp.getLeaves().get(0))).getSortInfo();
        assertEquals(null, si);
View Full Code Here

     * between order by and the store
     * @throws Exception
     */
    @Test
    public void testSortInfoNoOrderBy2() throws Exception {
        LogicalPlanTester lpt = new LogicalPlanTester(pc);
        lpt.buildPlan("a = load 'bla' as (i:int, n:chararray, d:double);");
        lpt.buildPlan("b = order a by i, d;");
        lpt.buildPlan("c = filter b by i > 10;");
        LogicalPlan lp = lpt.buildPlan("store c into 'foo';");
        PhysicalPlan pp = buildPhysicalPlan(lp);
        PigServer.SortInfoSetter siSetter = new PigServer.SortInfoSetter(lp);
        siSetter.visit();
        SortInfo si = ((POStore)(pp.getLeaves().get(0))).getSortInfo();
        assertEquals(null, si);
View Full Code Here

TOP

Related Classes of org.apache.pig.test.utils.LogicalPlanTester

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.