Package org.apache.pig.experimental.plan

Examples of org.apache.pig.experimental.plan.Operator


        ls.add(s);
        PlanOptimizer optimizer = new MyPlanOptimizer(plan, ls, 3);
        optimizer.optimize();
       
        assertEquals(plan.getPredecessors(filter).get(0), join);
        Operator next = plan.getSuccessors(filter).get(0);
        assertEquals(LOFilter.class, next.getClass());       
        next = plan.getSuccessors(next).get(0);
        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);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(load2).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        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);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(load2).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        assertEquals(plan.getSuccessors(join).get(0), store);
    }
View Full Code Here


        MyPlanTransformListener listener = new MyPlanTransformListener();
        optimizer.addPlanTransformListener(listener);
        optimizer.optimize();
       
        assertEquals(plan.getPredecessors(filter).get(0), join);
        Operator next = plan.getSuccessors(filter).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        next = plan.getSuccessors(next).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        next = plan.getSuccessors(next).get(0);
        assertEquals(LOStore.class, next.getClass());
       
        OperatorPlan transformed = listener.getTransformed();
        assertEquals(transformed.size(), 3);
       
        // 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);
        listener = new MyPlanTransformListener();
        optimizer.addPlanTransformListener(listener);
        optimizer.optimize();
       
        // 2 filters should be moved up to be after each load, and one filter should remain
        next = plan.getSuccessors(load1).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(load2).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(join).get(0);
        assertEquals(next.getClass(), LOFilter.class);
       
        next = plan.getSuccessors(next).get(0);
        assertEquals(next.getClass(), LOStore.class);
       
        transformed = listener.getTransformed();
        assertEquals(transformed.size(), 4);
        assertEquals(transformed.getSinks().get(0).getClass(), LOFilter.class);
        assertEquals(transformed.getSources().get(0).getClass(), LOLoad.class);
       
        // 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);
        listener = new MyPlanTransformListener();
        optimizer.addPlanTransformListener(listener);
        optimizer.optimize();
       
        // the filters should the same as before, nothing to merge
        next = plan.getSuccessors(load1).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(load2).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(join).get(0);
        assertEquals(next.getClass(), LOFilter.class);
       
        next = plan.getSuccessors(next).get(0);
        assertEquals(next.getClass(), LOStore.class);
       
        transformed = listener.getTransformed();
        assertNull(transformed);
    }  
View Full Code Here

        ls.add(s);
        MyPlanOptimizer optimizer = new MyPlanOptimizer(plan, ls, 3);
        optimizer.optimize();
       
        assertEquals(plan.getPredecessors(filter).get(0), join);
        Operator next = plan.getSuccessors(filter).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        next = plan.getSuccessors(next).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        next = plan.getSuccessors(next).get(0);
        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();
       
        // 1 filter should be moved up to be after a load, and 2 filters should remain
        next = plan.getSuccessors(load1).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(load2).get(0);
        assertEquals(next, join);    
       
        next = plan.getSuccessors(join).get(0);
        assertEquals(next.getClass(), LOFilter.class);
       
        next = plan.getSuccessors(next).get(0);
        assertEquals(next.getClass(), LOFilter.class);
               
        next = plan.getSuccessors(next).get(0);
        assertEquals(next.getClass(), LOStore.class);
       
        // 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);
        MyPlanTransformListener listener = new MyPlanTransformListener();
        optimizer.addPlanTransformListener(listener);
        optimizer.optimize();
       
        // the 2 filters after join should merge
        next = plan.getSuccessors(load1).get(0);
        assertEquals(next.getClass(), LOFilter.class);
        assertEquals(plan.getSuccessors(next).get(0), join);
       
        next = plan.getSuccessors(load2).get(0);
        assertEquals(next, join);       
       
        next = plan.getSuccessors(join).get(0);
        assertEquals(next.getClass(), LOFilter.class);
       
        next = plan.getSuccessors(next).get(0);
        assertEquals(next.getClass(), LOStore.class);
       
        OperatorPlan transformed = listener.getTransformed();
        assertEquals(transformed.size(), 2);
    }  
View Full Code Here

    OperatorPlan plan = null;
    Operator join;
   
    public void setUp() {
        plan = new SillyPlan();
        Operator l1 = new OP_Load("p1", plan);
        plan.add(l1);
        Operator l2 = new OP_Load("p2", plan);
        plan.add(l2);
        Operator j1 = new OP_Join("j1", plan);
        plan.add(j1);
        Operator f1 = new OP_Filter("f1", plan);
        plan.add(f1);
        Operator f2 = new OP_Filter("f2", plan);
        plan.add(f2);
        Operator t1 = new OP_Split("t1",plan);
        plan.add(t1);
        Operator f3 = new OP_Filter("f3", plan);
        plan.add(f3);
        Operator f4 = new OP_Filter("f4", plan);
        plan.add(f4);
        Operator s1 = new OP_Store("s1", plan);
        plan.add(s1);
        Operator s2 = new OP_Store("s2", plan);
        plan.add(s2);
       
        // load --|-join - filter - filter - split |- filter - store
        // load --|                                |- filter - store
        plan.connect(l1, j1);
View Full Code Here

   
    public void testMultiNode() throws Exception {   
        //         load --|-join - filter - filter - split |- filter - store
        //         load --|     
        // load -- filter-|
        Operator l3 = new OP_Load("p3", plan);
        Operator f5 = new OP_Filter("f5", plan);
        plan.add(l3);
        plan.add(f5);
        plan.connect(l3, f5);
           
         plan.connect(f5, join);
      
       
         OperatorPlan pattern = new SillyPlan();
         Operator op1 = new OP_Load("mmm1", pattern);
         Operator op2 = new OP_Filter("mmm2", pattern);
         Operator op3 = new OP_Join("mmm3", pattern);
         pattern.add(op1);
         pattern.add(op2);
         pattern.add(op3);
         pattern.connect(op1, op3);
         pattern.connect(op2, op3);
View Full Code Here

       
        Rule r = new SillyRule("basic", pattern);
        List<OperatorPlan> l = r.match(plan);
        assertEquals(l.size(), 2);
       
        Operator m1 = l.get(0).getSources().get(0);
        assertTrue(m1.getName().equals("p1") || m1.getName().equals("p2"));
        assertEquals(l.get(0).size(), 1);
       
        Operator m2 = l.get(1).getSources().get(0);
        assertTrue(m2.getName().equals("p1") || m2.getName().equals("p2"));
        assertEquals(l.get(1).size(), 1);
        assertNotSame(m1.getName(), m2.getName());
      
        // search for filter
        pattern = new SillyPlan();
        pattern.add(new OP_Filter("mmm",pattern));
        r = new SillyRule("basic", pattern);
        l = r.match(plan);
        assertEquals(l.size(), 4);
       
        m1 = l.get(0).getSources().get(0);
        assertTrue(m1.getName().equals("f1") || m1.getName().equals("f2")
                || m1.getName().equals("f3") || m1.getName().equals("f4"));
        assertEquals(l.get(0).size(), 1);
       
        m2 = l.get(1).getSources().get(0);
        assertTrue(m1.getName().equals("f1") || m1.getName().equals("f2")
                || m1.getName().equals("f3") || m1.getName().equals("f4"));
        assertEquals(l.get(1).size(), 1);
        assertNotSame(m1.getName(), m2.getName());
       
        // search for store
        pattern = new SillyPlan();
        pattern.add(new OP_Store("mmm",pattern));
        r = new SillyRule("basic", pattern);
        l = r.match(plan);
        assertEquals(l.size(), 2);
       
        m1 = l.get(0).getSources().get(0);
        assertTrue(m1.getName().equals("s1") || m1.getName().equals("s2"));
        assertEquals(l.get(0).size(), 1);
       
        m2 = l.get(1).getSources().get(0);
        assertTrue(m2.getName().equals("s1") || m2.getName().equals("s2"));
        assertEquals(l.get(1).size(), 1);
        assertNotSame(m1.getName(), m2.getName());
       
        // search for split
        pattern = new SillyPlan();
        pattern.add(new OP_Split("mmm",pattern));
        r = new SillyRule("basic", pattern);
View Full Code Here

       
        assertEquals(l.get(0).getSources().size(), 2);
        assertEquals(l.get(0).getSinks().size(), 2);
        assertEquals(l.get(0).size(), 2);
       
        Operator m1 = l.get(0).getSources().get(0);
        assertTrue(m1.getName().equals("p1") || m1.getName().equals("p2"));
        Operator m2 = l.get(0).getSources().get(1);
        assertTrue(m2.getName().equals("p1") || m2.getName().equals("p2"));      
        assertNotSame(m1.getName(), m2.getName());
      
       
        // search for join then filter
        pattern = new SillyPlan();
        Operator s1 = new OP_Join("mmm1", pattern);
        Operator s2 = new OP_Filter("mmm2", pattern);
        pattern.add(s1);
        pattern.add(s2);       
        pattern.connect(s1, s2);
       
        r = new SillyRule("basic", pattern);
        l = r.match(plan);
        assertEquals(l.size(), 1);
       
        assertEquals(l.get(0).getSources().size(), 1);
        assertEquals(l.get(0).getSinks().size(), 1);
        assertEquals(l.get(0).size(), 2);
       
        m1 = l.get(0).getSources().get(0);
        assertTrue(m1.getName().equals("j1"));
        m2 = l.get(0).getSinks().get(0);
        assertTrue(m2.getName().equals("f1"));      
      
 
        // search for filter, then store
        pattern = new SillyPlan();
        s1 = new OP_Filter("mmm1", pattern);
        s2 = new OP_Store("mmm2", pattern);       
        pattern.add(s1);
        pattern.add(s2);          
        pattern.connect(s1, s2);       
       
        r = new SillyRule("basic", pattern);
        l = r.match(plan);
        assertEquals(2, l.size());
       
        assertEquals(l.get(0).getSources().size(), 1);
        assertEquals(l.get(0).getSinks().size(), 1);                    
       
        // search for 2 loads, then join
        pattern = new SillyPlan();
        s1 = new OP_Load("mmm1", pattern);
        s2 = new OP_Load("mmm2", pattern);
        Operator s3 = new OP_Join("jjj", pattern);
        pattern.add(s1);
        pattern.add(s2);
        pattern.add(s3);
        pattern.connect(s1, s3);
        pattern.connect(s2, s3);
View Full Code Here

               
                // Loader does not support column pruning, insert foreach     
                if (columnPrune) {
                    if (response==null || !response.getRequiredFieldResponse()) {
                        LogicalPlan p = (LogicalPlan)load.getPlan();                       
                        Operator next = p.getSuccessors(load).get(0);
                        // if there is already a LOForEach after load, we don't need to
                        // add another LOForEach
                        if (next instanceof LOForEach) {
                            return;
                        }
View Full Code Here

       
        @Override
        public boolean check(OperatorPlan matched) throws IOException {
            Iterator<Operator> iter = matched.getOperators();
            while( iter.hasNext() ) {
                Operator op = iter.next();
                if( op instanceof LOForEach ) {
                    foreach = (LOForEach)op;
                    break;
                }
            }
           
            // This would be a strange case
            if( foreach == null ) return false;
           
            iter = matched.getOperators();
            while( iter.hasNext() ) {
                Operator op = iter.next();
                if( ( op instanceof LOFilter ) ) {
                    filter = (LOFilter)op;
                    break;
                }
            }
View Full Code Here

        private Set<Long> getFilterProjectionUids( LOFilter filter ) {
            Set<Long> uids = new HashSet<Long>();
            if( filter != null ) {
                LogicalExpressionPlan filterPlan = filter.getFilterPlan();
                Iterator<Operator> iter = filterPlan.getOperators();           
                Operator op = null;
                while( iter.hasNext() ) {
                    op = iter.next();
                    if( op instanceof ProjectExpression ) {
                        uids.add(((ProjectExpression)op).getUid() );
                    }
View Full Code Here

TOP

Related Classes of org.apache.pig.experimental.plan.Operator

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.