Package org.apache.pig.experimental.logical.expression

Examples of org.apache.pig.experimental.logical.expression.ProjectExpression


       
        LOInnerLoad innerLoad2 = new LOInnerLoad(innerPlan, foreach, 1);
        innerPlan.add(innerLoad2);
       
        LogicalExpressionPlan namePrj = new LogicalExpressionPlan();       
        ProjectExpression prjName = new ProjectExpression(namePrj, DataType.CHARARRAY, 0, 0);
        namePrj.add(prjName);
       
        LogicalExpressionPlan cuisinesPrj = new LogicalExpressionPlan();
        ProjectExpression prjCuisines = new ProjectExpression(cuisinesPrj, DataType.BAG, 1, 0);
        cuisinesPrj.add(prjCuisines);
       
        List<LogicalExpressionPlan> expPlans = new ArrayList<LogicalExpressionPlan>();
        expPlans.add(namePrj);
        expPlans.add(cuisinesPrj);
       
        boolean flatten[] = new boolean[2];
        flatten[0] = false;
        flatten[1] = true;
       
        LOGenerate generate = new LOGenerate(innerPlan, expPlans, flatten);       
        innerPlan.add(generate);
        innerPlan.connect(innerLoad, generate);
        innerPlan.connect(innerLoad2, generate);
       
        foreach.setInnerPlan(innerPlan);
        foreach.setAlias("B");
        plan.add(foreach);
       
        plan.connect(load, foreach);
       
        filter = new LOFilter(plan);
        LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
        ProjectExpression namePrj2 = new ProjectExpression(filterPlan, DataType.CHARARRAY, 0, 1);
        filterPlan.add(namePrj2);
        ConstantExpression constExp = new ConstantExpression(filterPlan, DataType.CHARARRAY, "joe");
        filterPlan.add(constExp);
        EqualExpression equal = new EqualExpression(filterPlan, namePrj2, constExp);
        filterPlan.add(equal);
       
        filter.setFilterPlan(filterPlan);
        filter.setAlias("C");
        plan.add(filter);
       
        plan.connect(foreach, filter);
       
        stor = new LOStore(plan);
        stor.setAlias("D");
        plan.add(stor);
        plan.connect(filter,stor);
       
        try {
            // Stamp everything with a Uid
            UidStamper stamper = new UidStamper(plan);
            stamper.visit();
        }catch(Exception e) {
            assertTrue("Failed to set a valid uid", false );
        }
       
       
        // run filter rule
        Rule r = new FilterAboveForeach("FilterAboveFlatten");
        Set<Rule> s = new HashSet<Rule>();
        s.add(r);
        List<Set<Rule>> ls = new ArrayList<Set<Rule>>();
        ls.add(s);
       
        // Test Plan before optimizing
        List<Operator> list = plan.getSinks();
        assertTrue( list.contains(stor) );
       
        list = plan.getSources();
        assertTrue( list.contains(load) );
       
        assertTrue( plan.getPredecessors(stor).contains(filter) );
        assertEquals( 1, plan.getPredecessors(stor).size() );
       
        assertTrue( plan.getPredecessors(filter).contains(foreach) );
        assertEquals( 1, plan.getPredecessors(filter).size() );
       
        assertTrue( foreach.getInnerPlan().getSinks().contains(generate) );
        assertEquals( 1, foreach.getInnerPlan().getSinks().size() );
        assertTrue( foreach.getInnerPlan().getSources().contains(innerLoad) );
        assertTrue( foreach.getInnerPlan().getSources().contains(innerLoad2) );
        assertEquals( 2, foreach.getInnerPlan().getSources().size() );
       
        // Run the optimizer
        MyPlanOptimizer optimizer = new MyPlanOptimizer(plan, ls, 3);
        optimizer.addPlanTransformListener(new ProjectionPatcher());
        optimizer.addPlanTransformListener(new SchemaPatcher());
        optimizer.optimize();
       
        // Test after optimization
        list = plan.getSinks();
        assertTrue( list.contains(stor) );
       
        list = plan.getSources();
        assertTrue( list.contains(load) );
       
        assertTrue( plan.getPredecessors(stor).contains(filter) );
        assertEquals( 1, plan.getPredecessors(stor).size() );
       
        assertFalse( prjCuisines.getUid() == namePrj2.getUid() );
       
        assertTrue( plan.getPredecessors(filter).contains(foreach) );
        assertEquals( 1, plan.getPredecessors(filter).size() );
       
        assertTrue( foreach.getInnerPlan().getSinks().contains(generate) );
View Full Code Here


       
        LOInnerLoad innerLoad2 = new LOInnerLoad(innerPlan, foreach, 1);
        innerPlan.add(innerLoad2);
       
        LogicalExpressionPlan namePrj = new LogicalExpressionPlan();       
        ProjectExpression prjName = new ProjectExpression(namePrj, DataType.CHARARRAY, 0, 0);
        namePrj.add(prjName);
       
        LogicalExpressionPlan cuisinesPrj = new LogicalExpressionPlan();
        ProjectExpression prjCuisines = new ProjectExpression(cuisinesPrj, DataType.BAG, 1, 0);
        cuisinesPrj.add(prjCuisines);
       
        List<LogicalExpressionPlan> expPlans = new ArrayList<LogicalExpressionPlan>();
        expPlans.add(namePrj);
        expPlans.add(cuisinesPrj);
       
        boolean flatten[] = new boolean[2];
        flatten[0] = false;
        flatten[1] = false;
       
        LOGenerate generate = new LOGenerate(innerPlan, expPlans, flatten);       
        innerPlan.add(generate);
        innerPlan.connect(innerLoad, generate);
        innerPlan.connect(innerLoad2, generate);
       
        foreach.setInnerPlan(innerPlan);
        foreach.setAlias("B");
        plan.add(foreach);
       
        plan.connect(load, foreach);
       
        filter = new LOFilter(plan);
        LogicalExpressionPlan filterPlan = new LogicalExpressionPlan();
        ProjectExpression namePrj2 = new ProjectExpression(filterPlan, DataType.CHARARRAY, 0, 0);
        filterPlan.add(namePrj2);
        ConstantExpression constExp = new ConstantExpression(filterPlan, DataType.CHARARRAY, "joe");
        filterPlan.add(constExp);
        EqualExpression equal = new EqualExpression(filterPlan, namePrj2, constExp);
        filterPlan.add(equal);
       
        filter.setFilterPlan(filterPlan);
        filter.setAlias("C");
        plan.add(filter);
       
        plan.connect(foreach, filter);
       
        stor = new LOStore(plan);
        stor.setAlias("D");
        plan.add(stor);
        plan.connect(filter,stor);
       
        try {
            // Stamp everything with a Uid
            UidStamper stamper = new UidStamper(plan);
            stamper.visit();
        }catch(Exception e) {
            assertTrue("Failed to set a valid uid", false );
        }
       
       
        // run filter rule
        Rule r = new FilterAboveForeach("FilterAboveFlatten");
        Set<Rule> s = new HashSet<Rule>();
        s.add(r);
        List<Set<Rule>> ls = new ArrayList<Set<Rule>>();
        ls.add(s);
       
        // Test Plan before optimizing
        List<Operator> list = plan.getSinks();
        assertTrue( list.contains(stor) );
       
        list = plan.getSources();
        assertTrue( list.contains(load) );
       
        assertTrue( plan.getPredecessors(stor).contains(filter) );
        assertEquals( 1, plan.getPredecessors(stor).size() );
       
        assertTrue( plan.getPredecessors(filter).contains(foreach) );
        assertEquals( 1, plan.getPredecessors(filter).size() );
       
        assertTrue( foreach.getInnerPlan().getSinks().contains(generate) );
        assertEquals( 1, foreach.getInnerPlan().getSinks().size() );
        assertTrue( foreach.getInnerPlan().getSources().contains(innerLoad) );
        assertTrue( foreach.getInnerPlan().getSources().contains(innerLoad2) );
        assertEquals( 2, foreach.getInnerPlan().getSources().size() );
       
        // Run the optimizer
        MyPlanOptimizer optimizer = new MyPlanOptimizer(plan, ls, 3);
        optimizer.addPlanTransformListener(new ProjectionPatcher());
        optimizer.addPlanTransformListener(new SchemaPatcher());
        optimizer.optimize();
       
        // Test after optimization
        list = plan.getSinks();
        assertTrue( list.contains(stor) );
       
        list = plan.getSources();
        assertTrue( list.contains(load) );
       
        assertTrue( plan.getPredecessors(stor).contains(foreach) );
        assertEquals( 1, plan.getPredecessors(stor).size() );
       
        assertTrue( plan.getPredecessors(filter).contains(load) );
        assertEquals( 1, plan.getPredecessors(filter).size() );
       
        assertTrue( plan.getPredecessors(foreach).contains(filter) );
        assertEquals( 1, plan.getPredecessors(foreach).size() );
       
        assertEquals( load.getSchema().getField(0).uid , namePrj2.getUid() );
        assertEquals( namePrj2.getUid(), prjName.getUid() );
       
        assertTrue( foreach.getInnerPlan().getSinks().contains(generate) );
        assertEquals( 1, foreach.getInnerPlan().getSinks().size() );
        assertTrue( foreach.getInnerPlan().getSources().contains(innerLoad) );
        assertTrue( foreach.getInnerPlan().getSources().contains(innerLoad2) );
View Full Code Here

        // store column number as a ProjectExpression in a plan
        // to be able to dynamically adjust column number during optimization
        LogicalExpressionPlan exp = new LogicalExpressionPlan();
       
        // we don't care about type, so set to -1
        prj = new ProjectExpression(exp, (byte)-1, 0, colNum);
        this.foreach = foreach;
    }
View Full Code Here

                innerLoad.getProjection().setUid(foreach);                   
                innerPlan.add(innerLoad);         
                innerPlan.connect(innerLoad, gen);
               
                LogicalExpressionPlan exp = new LogicalExpressionPlan();
                ProjectExpression prj = new ProjectExpression(exp, schema.getField(i).type, j++, 0);
                prj.setUid(gen);
                exp.add(prj);
                exps.add(exp);               
            }               
          
        }
View Full Code Here

            LogicalOperator succed = oldLogicalPlan.getSuccessors(lg).get(0);
            int input = oldLogicalPlan.getPredecessors(succed).indexOf(lg);
                       
            // get data type of projection
            byte t = project.getType();           
            ProjectExpression pe = new ProjectExpression(exprPlan, t, input, project.isStar()?-1:col);         
           
            exprPlan.add(pe);
            exprOpsMap.put(project, pe);      
            translateConnection(project, pe);                      
        }
View Full Code Here

                    // and prepare for the expression plan
                    newInnerPlan.connect(innerLoad, gen);       
                   
                    List<LogicalOperator> ll = mPlan.getSuccessors(project);
                    if (ll == null || ll.get(0) instanceof ExpressionOperator) {                     
                        ProjectExpression pe = new ProjectExpression(exprPlan, project.getType(), inputNo++, project.isStar()?-1:0);                             
                        exprPlan.add(pe);
                        exprOpsMap.put(project, pe);      
                        translateConnection(project, pe);
                    }
                }
            }

            // This case occurs when there are two projects one after another
            // These projects in combination project a column (bag) out of a tuple
            // and then project a column out of this projected bag
            // Here we merge these two projects into one BagDereferenceExpression
            if( op instanceof LOProject ) {
                ProjectExpression projectExp = (ProjectExpression) exprOpsMap.get(op);
               
                // Add the bag in the plan
                BagDereferenceExpression bagDR = new BagDereferenceExpression(
                        exprPlan, project.getType(), project.getProjection(), projectExp);               
                exprOpsMap.put(project, bagDR);
View Full Code Here

                            innerLoad.getProjection().setUid(foreach);                   
                            innerPlan.add(innerLoad);         
                            innerPlan.connect(innerLoad, gen);
                           
                            LogicalExpressionPlan exp = new LogicalExpressionPlan();
                            ProjectExpression prj = new ProjectExpression(exp, rf.getType(), i, 0);
                            prj.setUid(gen);
                            exp.add(prj);
                            exps.add(exp);
                        }               
                      
                    } else {
View Full Code Here

TOP

Related Classes of org.apache.pig.experimental.logical.expression.ProjectExpression

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.