Examples of PlanOptimizer


Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

    public void test2() throws Exception {
        String query = "b = filter (load 'd.txt' as (name, age, gpa)) by age >= 50 or name > 'fred' and gpa <= 3.0 or name >= 'bob';" +
                       "store b into 'empty';";
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);;

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (name, age, gpa)) by age >= 50 or name >= 'bob';" +
                "store b into 'empty';";
        LogicalPlan expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));
       
        // Regex filtering
        query = "b = filter (load 'd.txt' as (name:chararray, age:int, registration, contributions:double)) by (name matches '^fred.*' and (chararray)registration matches '^dem.*');" +
                "store b into 'empty';";
        newLogicalPlan = Util.buildLp(pigServer, query);;

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (name:chararray, age:int, registration, contributions:double)) by (name matches '^fred.*' and (chararray)registration matches '^dem.*');" +
                "store b into 'empty';";
        expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));
       
        // NOT Regex filtering
        query = "b = filter (load 'd.txt') by (not $0 matches '^fred.*');" +
                "store b into 'empty';";
        newLogicalPlan = Util.buildLp(pigServer, query);;

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt') by (not $0 matches '^fred.*');" +
                "store b into 'empty';";
        expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));  
       
        // naiive filtering
        query = "b = filter (load 'd.txt') by 1==1;" +
                "store b into 'empty';";
        newLogicalPlan = Util.buildLp(pigServer, query);;

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = load 'd.txt';" +
                "store b into 'empty';";
        expected = Util.buildLp(pigServer, query);;

View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

        // boolean constant elimination: AND
        String query = "b = filter (load 'd.txt' as (id:int, v1, v2)) by ((v1 is not null) AND (id == 1) AND (1 == 1));" +
                       "store b into 'empty';";
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);;

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (id:int, v1, v2)) by ((v1 is not null) AND (id == 1));" +
                "store b into 'empty';";
        LogicalPlan expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));

        // boolean constant elimination: OR
        query = "b = filter (load 'd.txt' as (id:int, v1, v2)) by (((v1 is not null) AND (id == 1)) OR (1 == 0));" +
                "store b into 'empty';";
        newLogicalPlan = Util.buildLp(pigServer, query);;

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (id:int, v1, v2)) by ((v1 is not null) AND (id == 1));" +
                "store b into 'empty';";
        expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));
       
        // the mirror case of the above
        query = "b = filter (load 'd.txt' as (id:int, v1, v2)) by ((1 == 0) OR ((v1 is not null) AND (id == 1)));" +
                "store b into 'empty';";
        newLogicalPlan = Util.buildLp(pigServer, query);;

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (id:int, v1, v2)) by ((v1 is not null) AND (id == 1));" +
                "store b into 'empty';";
        expected = Util.buildLp(pigServer, query);;
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

    public void test4() throws Exception {
        String query = "b = filter (load 'd.txt' as (a:chararray, b:long, c:map[], d:chararray, e:chararray)) by a == 'v' and b == 117L and c#'p1' == 'h' and c#'p2' == 'to' and ((d is not null and d != '') or (e is not null and e != ''));" +
                       "store b into 'empty';";
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);;

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (a:chararray, b:long, c:map[], d:chararray, e:chararray)) by a == 'v' and b == 117L and c#'p1' == 'h' and c#'p2' == 'to' and ((d is not null and d != '') or (e is not null and e != ''));" +
                "store b into 'empty';";
        LogicalPlan expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));

        // mirror of the above
        query = "b = filter (load 'd.txt' as (a:chararray, b:long, c:map[], d:chararray, e:chararray)) by ((d is not null and d != '') or (e is not null and e != '')) and a == 'v' and b == 117L and c#'p1' == 'h' and c#'p2' == 'to';" +

                "store b into 'empty';";
        newLogicalPlan = Util.buildLp(pigServer, query);;

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (a:chararray, b:long, c:map[], d:chararray, e:chararray)) by ((d is not null and d != '') or (e is not null and e != '')) and a == 'v' and b == 117L and c#'p1' == 'h' and c#'p2' == 'to';" +
                "store b into 'empty';";
        expected = Util.buildLp(pigServer, query);;
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

        StringBuilder sb = new StringBuilder();
        sb.append("b = filter (load 'd.txt' as (a:int, b:int, c:int, d:int)) by (((a < 1) " + (b1 ? "and" : "or") + " (b < 2)) " + (b2 ? "and" : "or") + " ((c < 3) " + (b3 ? "and" : "or") + " (d < 4)));")
        String query = sb.toString() + "store b into 'empty';";
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);;

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        LogicalPlan expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));
    }
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

        StringBuilder sb = new StringBuilder();
        sb.append("b = filter (load 'd.txt' as (a:int, b:int, c:int, d:int, e:int, f:int, g:int, h:int)) by ((((a < 1) " + (b1 ? "and" : "or") + " (b < 2)) " + (b2 ? "and" : "or") + " ((c < 3) " + (b3 ? "and" : "or") + " (d < 4))) " + (b4 ? "and" : "or") + " (((e < 5) " + (b5 ? "and" : "or") + " (f < 6)) " + (b6 ? "and" : "or") + " ((g < 7) " + (b7 ? "and" : "or") + " (h < 8))));")
        String query = sb.toString() + "store b into 'empty';";
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);;

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        LogicalPlan expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));
    }
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

    public void test7() throws Exception {
        String query = "b = filter (load 'd.txt' as (k1, k2, k3, v1, v2, v3)) by k2#'f1'#'f' is not null and (v2#'f'#'f1' is not null or v2#'f'#'f2' is not null);" +
                       "store b into 'empty';";
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);;

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (k1, k2, k3, v1, v2, v3)) by k2#'f1'#'f' is not null and (v2#'f'#'f1' is not null or v2#'f'#'f2' is not null);" +
                "store b into 'empty';";
        LogicalPlan expected = Util.buildLp(pigServer, query);;

        assertTrue(expected.isEqual(newLogicalPlan));
       
        query = "b = filter (load 'd.txt' as (k1, k2, k3, v1, v2, v3)) by k2#'f1'#'f' is not null and (v2#'f1'#'f' is not null or v2#'f2'#'f' is not null);" +

                "store b into 'empty';";
        newLogicalPlan = Util.buildLp(pigServer, query);;

        optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (k1, k2, k3, v1, v2, v3)) by k2#'f1'#'f' is not null and (v2#'f1'#'f' is not null or v2#'f2'#'f' is not null);" +
                "store b into 'empty';";
        expected = Util.buildLp(pigServer, query);;
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

    public void test8() throws Exception {
        String query = "b = filter (load 'd.txt' as (a0, a1)) by (a0 is not null or a1 is not null) and IsEmpty(a0);" +
                       "store b into 'empty';";
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);;

        PlanOptimizer optimizer = new MyPlanOptimizer(newLogicalPlan, 10);
        optimizer.optimize();

        query = "b = filter (load 'd.txt' as (a0, a1)) by (a0 is not null or a1 is not null) and IsEmpty(a0);" +
                "store b into 'empty';";
        LogicalPlan expected = Util.buildLp(pigServer, query);;
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

        Rule r = new SplitFilter("SplitFilter");
        Set<Rule> s = new HashSet<Rule>();
        s.add(r);
        List<Set<Rule>> ls = new ArrayList<Set<Rule>>();
        ls.add(s);
        PlanOptimizer optimizer = new MyPlanOptimizer(plan, ls, 3);
        optimizer.optimize();
       
        Assert.assertEquals(plan.getPredecessors(filter).get(0), join);
        Operator next = plan.getSuccessors(filter).get(0);
        Assert.assertEquals(LOFilter.class, next.getClass());       
        next = plan.getSuccessors(next).get(0);
        Assert.assertEquals(LOStore.class, next.getClass());
       
        // run push up filter rule
        r = new PushUpFilter("PushUpFilter");
        s = new HashSet<Rule>();
        s.add(r);
        ls = new ArrayList<Set<Rule>>();
        ls.add(s);
        optimizer = new MyPlanOptimizer(plan, ls, 3);
        optimizer.optimize();
       
        // both filters should be moved up to be after each load
        next = plan.getSuccessors(load1).get(0);
        Assert.assertEquals(next.getClass(), LOFilter.class);
        Assert.assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(load2).get(0);
        Assert.assertEquals(next.getClass(), LOFilter.class);
        Assert.assertEquals(plan.getSuccessors(next).get(0), join);
       
        Assert.assertEquals(plan.getSuccessors(join).get(0), store);
       
        // run merge filter rule
        r = new MergeFilter("MergeFilter");
        s = new HashSet<Rule>();
        s.add(r);
        ls = new ArrayList<Set<Rule>>();
        ls.add(s);
        optimizer = new MyPlanOptimizer(plan, ls, 3);
        optimizer.optimize();
       
        // the filters should the same as before, nothing to merge
        next = plan.getSuccessors(load1).get(0);
        Assert.assertEquals(next.getClass(), LOFilter.class);
        Assert.assertEquals(plan.getSuccessors(next).get(0), join);
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

    }

    private LogicalPlan migrateAndOptimizePlan(String query) throws Exception {
      PigServer pigServer = new PigServer(pc);
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);
        PlanOptimizer optimizer = new NewPlanOptimizer( newLogicalPlan, 3 );
        optimizer.optimize();
        return newLogicalPlan;
    }
View Full Code Here

Examples of org.apache.pig.newplan.optimizer.PlanOptimizer

    }

    private LogicalPlan migrateAndOptimizePlanWithPruning(String query) throws Exception {
        PigServer pigServer = new PigServer( pc );
        LogicalPlan newLogicalPlan = Util.buildLp(pigServer, query);
        PlanOptimizer optimizer = new MyPlanOptimizerWithPruning( newLogicalPlan, 3 );
        optimizer.optimize();
        return newLogicalPlan;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.