Package org.apache.pig.newplan

Examples of org.apache.pig.newplan.OperatorPlan


        Assert.assertEquals(next.getClass(), LOFilter.class);
       
        next = plan.getSuccessors(next).get(0);
        Assert.assertEquals(next.getClass(), LOStore.class);
       
        OperatorPlan transformed = listener.getTransformed();
        Assert.assertEquals(transformed.size(), 2);
    }  
View Full Code Here


    private void injectForeachOperator(SourceLocation loc, LOCube op, LOForEach foreach)
      throws FrontendException {
  // connect the foreach operator with predecessors of cube operator
  List<Operator> opers = op.getPlan().getPredecessors(op);
  for (Operator oper : opers) {
      OperatorPlan foreachPlan = foreach.getPlan();
      foreachPlan.connect(oper, (Operator) foreach);
  }

  // disconnect the cube operator from the plan
  opers = foreach.getPlan().getPredecessors(foreach);
  for (Operator lop : opers) {
View Full Code Here

    }

    Operator buildNestedOperatorInput(SourceLocation loc, LogicalPlan innerPlan, LOForEach foreach,
            Map<String, Operator> operators, LogicalExpression expr)
    throws NonProjectExpressionException, ParserValidationException {
        OperatorPlan plan = expr.getPlan();
        Iterator<Operator> it = plan.getOperators();
        if( !( it.next() instanceof ProjectExpression ) || it.hasNext() ) {
            throw new NonProjectExpressionException( intStream, loc, expr );
        }
        Operator op = null;
        ProjectExpression projExpr = (ProjectExpression)expr;
View Full Code Here

     * @param relOp
     * @throws FrontendException
     */
    private void mapToPredLoadFunc(LogicalRelationalOperator relOp)
    throws FrontendException {
        OperatorPlan lp = relOp.getPlan();
        List<Operator> preds = lp.getPredecessors(relOp);
        if(lp.getPredecessors(relOp) == null ||
                lp.getPredecessors(relOp).size() == 0){
            // no predecessors , nothing to do
            return;
        }

        FuncSpec loadFuncSpec = getAssociatedLoadFunc((LogicalRelationalOperator) preds.get(0));
View Full Code Here

        if( !union.isOnSchema() )
            return;
       
        LogicalSchema outputSchema = union.getSchema();
        int fieldCount = outputSchema.size();
        OperatorPlan plan = union.getPlan();
        List<Operator> preds = new ArrayList<Operator>();
        preds.addAll( plan.getPredecessors( union ) );

        List<LogicalSchema> fieldSchemas = new ArrayList<LogicalSchema>( fieldCount );
        for( LogicalFieldSchema fs : outputSchema.getFields() ) {
            LogicalSchema ls = new LogicalSchema();
            ls.addField( new LogicalFieldSchema( fs.alias, null, DataType.NULL ) );
            fieldSchemas.add( ls );
        }
       
        for( Operator pred : preds ) {
            LogicalRelationalOperator op = (LogicalRelationalOperator)pred;
            LogicalSchema opSchema = op.getSchema();
            if( opSchema.isEqual( outputSchema , true) )
                continue;
           
            LOForEach foreach = new LOForEach( plan );
            LogicalPlan innerPlan = new LogicalPlan();

            LOGenerate gen = new LOGenerate( innerPlan );
            boolean[] flattenFlags = new boolean[fieldCount];
            List<LogicalExpressionPlan> exprPlans = new ArrayList<LogicalExpressionPlan>( fieldCount );
            List<Operator> genInputs = new ArrayList<Operator>();
           
            // Get exprPlans, and genInputs
            for( LogicalFieldSchema fs : outputSchema.getFields() ) {
                LogicalExpressionPlan exprPlan = new LogicalExpressionPlan();
                exprPlans.add( exprPlan );
                int pos = -1;
                //do a match with subname also
                LogicalFieldSchema matchFS = opSchema.getFieldSubNameMatch(fs.alias);
                if(matchFS != null){
                    pos = opSchema.getFieldPosition(matchFS.alias);
                }
                if( pos == -1 ) {
                    ConstantExpression constExp = new ConstantExpression( exprPlan, null);
                    if(fs.type != DataType.BYTEARRAY){
                        LogicalSchema.LogicalFieldSchema constFs = fs.deepCopy();
                        constFs.resetUid();
                        new CastExpression(exprPlan, constExp, constFs);
                    }
                } else {
                    ProjectExpression projExpr =
                        new ProjectExpression( exprPlan, genInputs.size(), 0, gen );
                    if( opSchema.getField( pos ).type != fs.type ) {
                        new CastExpression( exprPlan, projExpr, fs );
                    }
                    genInputs.add( new LOInnerLoad( innerPlan, foreach, pos ) );
                }
            }
           
            gen.setFlattenFlags( flattenFlags );
            gen.setOutputPlans( exprPlans );
            gen.setUserDefinedSchema( fieldSchemas );
            innerPlan.add( gen );
            for( Operator input : genInputs ) {
                innerPlan.add(input);
                innerPlan.connect( input, gen );
            }
           
            foreach.setInnerPlan( innerPlan );
            foreach.setAlias(union.getAlias());
            Pair<Integer, Integer> pair = plan.disconnect( pred, union );
            plan.add( foreach );
            plan.connect( pred, pair.first, foreach, 0 );
            plan.connect( foreach, 0, union, pair.second );
        }
       
        union.setUnionOnSchema(false);
    }
View Full Code Here

        }
    }

    private void addChildren(LogicalExpression current,
                    LogicalExpression exp) throws FrontendException {
        OperatorPlan childPlan = exp.getPlan();
        Operator[] children = childPlan.getSuccessors(exp).toArray(
                        new Operator[0]);
        int size = children.length;
        for (int i = 0; i < size; ++i) {
            ((DNFPlan) dnfPlan).safeAdd(children[i]);
            dnfPlan.connect(current, children[i]);
View Full Code Here

            Operator op = ops.next();
            if (op instanceof LOSplit || op instanceof LOStore)
                continue;
            List<Operator> succs = plan.getSuccessors(op);
            if (succs != null && succs.size() >= 2) {
                OperatorPlan match = new LogicalPlan();
                match.add(op);
                ll.add(match);
            }
        }
        return ll;
    }
View Full Code Here


    @Override
    public void visit(LOSplitOutput op) throws FrontendException {
        op.resetSchema();
        OperatorPlan lp = op.getPlan();
        // LOSplitOutput can only have 1 input
        List<Operator> list = lp.getPredecessors(op) ;
        if (list.size() != 1) {
            int errCode = 2008;
            String msg = "LOSplitOutput cannot have more than one input. Found: " + list.size() + " input(s).";
            throwTypeCheckerException(op, msg, errCode, PigException.BUG, null) ;
        }
View Full Code Here

    /***
     * The schema of split output will be the same as split input
     */

    public void visit(LOSplit split) throws VisitorException {
        OperatorPlan lp = split.getPlan();
        List<Operator> inputList = lp.getPredecessors(split);

        if (inputList.size() != 1) {           
            int errCode = 2008;
            String msg = "LOSplit cannot have more than one input. Found: " + inputList.size() + " input(s).";
            throwTypeCheckerException(split, msg, errCode, PigException.BUG, null) ;
View Full Code Here

    }
   
    @Override
    public void visit(LOForEach foreach) throws FrontendException {
        foreach.resetUid();
        OperatorPlan innerPlan = foreach.getInnerPlan();
        PlanWalker newWalker = currentWalker.spawnChildWalker(innerPlan);
        pushWalker(newWalker);
        currentWalker.walk(this);
        popWalker();
    }
View Full Code Here

TOP

Related Classes of org.apache.pig.newplan.OperatorPlan

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.