Package org.apache.pig.experimental.plan

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


           
            List<Operator> opSet = currentPlan.getPredecessors(filter);
            if( ! ( opSet != null && opSet.size() > 0 ) ) {
                return;
            }
            Operator filterPred = opSet.get(0);
           
            opSet = currentPlan.getSuccessors(filter);
            if( ! ( opSet != null && opSet.size() > 0 ) ) {
                return;
            }
            Operator filterSuc = opSet.get(0);
           
            subPlan = new OperatorSubPlan(currentPlan);
           
            // Steps below do the following
            /*
 
View Full Code Here


           
            filter.setFilterPlan(op1);
            LOFilter filter2 = new LOFilter((LogicalPlan)currentPlan, op2);
            currentPlan.add(filter2);
           
            Operator succed = null;
            try {
                List<Operator> succeds = currentPlan.getSuccessors(filter);
                if (succeds != null) {
                    succed = succeds.get(0);
                    subPlan.add(succed);
View Full Code Here

            p = new OperatorSubPlan(currentPlan);
        }
        Iterator<Operator> iter = currentPlan.getOperators();
       
        while(iter.hasNext()) {
            Operator op = iter.next();
            if (op instanceof LOForEach) {
                addOperator(op, p);
            }
        }
       
View Full Code Here

        Iterator<Operator> iter = plan.getOperators();
        List<OperatorPlan> matchedList = new ArrayList<OperatorPlan>();      
        matchedNodes.clear();
      
        while(iter.hasNext()) {
            Operator op = iter.next();
          
            // find a node that matches the first leaf of the pattern
            if (match(op, leaves.get(0))) {
                List<Operator> planOps = new ArrayList<Operator>();
                planOps.add(op);
                               
                // if there is more than 1 leaves in the pattern, we check
                // if other leaves match the siblings of this node
                if (leaves.size()>1) {
                    boolean matched = true;
                   
                   
                    List<Operator> preds = null;
                    try {
                        preds = plan.getPredecessors(op);
                    }catch(IOException e) {
                        // not going to happen
                    }
                   
                    // if this node has no predecessor, it must be a root
                    if (preds == null) {
                        preds = new ArrayList<Operator>();
                        preds.add(null);
                    }
                   
                    for(Operator s: preds) {
                        matched = true;
                        List<Operator> siblings = null;
                        try {
                            if (s != null) {
                                siblings = plan.getSuccessors(s);
                            }else{
                                // for a root, we get its siblings by getting all roots
                                siblings = plan.getSources();
                            }
                        }catch(IOException e) {
                            // not going to happen
                            throw new RuntimeException(e);
                        }
                        int index = siblings.indexOf(op);
                        if (siblings.size()-index < leaves.size()) {
                            continue;
                        }
                   
                       
                        for(int j=1; j<leaves.size(); j++) {
                            if (!match(siblings.get(index+j), leaves.get(j))) {
                                matched = false;
                                break;
                            }
                        }    
                       
                        if (matched) {
                            for(int j=1; j<leaves.size(); j++) {
                                planOps.add(siblings.get(index+j));
                                break;
                            }
                        }
                   
                    }
                  
                    // we have move on to next operator as this one doesn't have siblings to
                    // match all the leaves
                    if (!matched) {
                        continue;
                    }
                }
               
             
                PatternMatchOperatorPlan match = new PatternMatchOperatorPlan(plan);
                try {
                    if (match.check(planOps)) {
                        // we find a matched pattern,
                        // add the operators into matchedNodes
                        Iterator<Operator> iter2 = match.getOperators();                     
                        while(iter2.hasNext()) {
                            Operator opt = iter2.next();
                            matchedNodes.add(opt);                       
                        }
                       
                        // add pattern
                        matchedList.add(match);                                               
View Full Code Here

                LOFilter next = (LOFilter)succeds.get(0);
                combineFilterCond(filter, next);
                Pair<Integer, Integer> p1 = currentPlan.disconnect(filter, next);
                List<Operator> ll = currentPlan.getSuccessors(next);
                if (ll!= null && ll.size()>0) {
                    Operator op = ll.get(0);
                    Pair<Integer, Integer> p2 = currentPlan.disconnect(next, op);
                    currentPlan.connect(filter, p1.first, op, p2.second);
                    subPlan.add(op);
                }
               
View Full Code Here

            }
           
            // add all connections
            iter = p1.getOperators();
            while(iter.hasNext()) {
                Operator n = iter.next();
                List<Operator> l = p1.getPredecessors(n);
                if (l != null) {
                    for(Operator op: l) {
                        andPlan.connect(op, n);
                    }
                }
            }
           
            iter = p2.getOperators();
            while(iter.hasNext()) {
                Operator n = iter.next();
                List<Operator> l = p2.getPredecessors(n);
                if (l != null) {
                    for(Operator op: l) {
                        andPlan.connect(op, n);
                    }
View Full Code Here

                PhysicalOperator op = logToPhyMap.get(l);
                if (l instanceof ProjectExpression ) {
                    int input = ((ProjectExpression)l).getInputNum();                   
                   
                    // for each sink projection, get its input logical plan and translate it
                    Operator pred = preds.get(input);
                    childWalker = new SubtreeDependencyOrderWalker(inner, pred);
                    pushWalker(childWalker);
                    childWalker.walk(this);
                    popWalker();
                   
View Full Code Here

       
        // Outer list corresponds to join predicates and inner list corresponds to type of keys for each predicate.
        List<List<Byte>> keyTypes = new ArrayList<List<Byte>>();
       
        for (int i=0; i<inputs.size(); i++) {
            Operator op = inputs.get(i);
            if( ! ( op instanceof LogicalRelationalOperator ) ) {
                continue;
            }
            LogicalRelationalOperator lop = (LogicalRelationalOperator)op;
            PhysicalOperator physOp = logToPhyMap.get(op);
            inp.add(physOp);
            List<LogicalExpressionPlan> plans = (List<LogicalExpressionPlan>) loj.getJoinPlan(i);
           
            // Convert the expression plan into physical Plan
            List<PhysicalPlan> exprPlans = translateExpressionPlans(loj, plans);

            ppLists.add(exprPlans);
            joinPlans.put(physOp, exprPlans);
           
            // Key could potentially be a tuple. So, we visit all exprPlans to get types of members of tuples.
            List<Byte> tupleKeyMemberTypes = new ArrayList<Byte>();
            for(PhysicalPlan exprPlan : exprPlans)
                tupleKeyMemberTypes.add(exprPlan.getLeaves().get(0).getResultType());
            keyTypes.add(tupleKeyMemberTypes);
        }

        if (loj.getJoinType() == LOJoin.JOINTYPE.SKEWED) {
            POSkewedJoin skj;
            try {
                skj = new POSkewedJoin(new OperatorKey(scope,nodeGen.getNextNodeId(scope)),loj.getRequestedParallelisam(),
                                            inp, loj.getInnerFlags());
                skj.setAlias(loj.getAlias());
                skj.setJoinPlans(joinPlans);
            }
            catch (Exception e) {
                int errCode = 2015;
                String msg = "Skewed Join creation failed";
                throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
            }
            skj.setResultType(DataType.TUPLE);
           
            boolean[] innerFlags = loj.getInnerFlags();
            for (int i=0; i < inputs.size(); i++) {
                LogicalRelationalOperator op = (LogicalRelationalOperator) inputs.get(i);
                if (!innerFlags[i]) {
                    try {
                        LogicalSchema s = op.getSchema();
                        // if the schema cannot be determined
                        if (s == null) {
                            throw new FrontendException();
                        }
                        skj.addSchema(translateSchema(s));
                    } catch (FrontendException e) {
                        int errCode = 2015;
                        String msg = "Couldn't set the schema for outer join" ;
                        throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
                    }
                } else {
                    // This will never be retrieved. It just guarantees that the index will be valid when
                    // MRCompiler is trying to read the schema
                    skj.addSchema(null);
                }
            }
           
            currentPlan.add(skj);

            for (Operator op : inputs) {
                try {
                    currentPlan.connect(logToPhyMap.get(op), skj);
                } catch (PlanException e) {
                    int errCode = 2015;
                    String msg = "Invalid physical operators in the physical plan" ;
                    throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
                }
            }
            logToPhyMap.put(loj, skj);
        }
        else if(loj.getJoinType() == LOJoin.JOINTYPE.REPLICATED) {
           
            int fragment = 0;
            POFRJoin pfrj;
            try {
                boolean []innerFlags = loj.getInnerFlags();
                boolean isLeftOuter = false;
                // We dont check for bounds issue as we assume that a join
                // involves atleast two inputs
                isLeftOuter = !innerFlags[1];
               
                Tuple nullTuple = null;
                if( isLeftOuter ) {
                    try {
                        // We know that in a Left outer join its only a two way
                        // join, so we assume index of 1 for the right input                       
                        LogicalSchema inputSchema = ((LogicalRelationalOperator)inputs.get(1)).getSchema();                    
                       
                        // We check if we have a schema before the join
                        if(inputSchema == null) {
                            int errCode = 1109;
                            String msg = "Input (" + ((LogicalRelationalOperator) inputs.get(1)).getAlias() + ") " +
                            "on which outer join is desired should have a valid schema";
                            throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.INPUT);
                        }
                       
                        // Using the schema we decide the number of columns/fields
                        // in the nullTuple
                        nullTuple = TupleFactory.getInstance().newTuple(inputSchema.size());
                        for(int j = 0; j < inputSchema.size(); j++) {
                            nullTuple.set(j, null);
                        }
                       
                    } catch( FrontendException e ) {
                        int errCode = 2104;
                        String msg = "Error while determining the schema of input";
                        throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
                    }
                }
               
                pfrj = new POFRJoin(new OperatorKey(scope,nodeGen.getNextNodeId(scope)),loj.getRequestedParallelisam(),
                                            inp, ppLists, keyTypes, null, fragment, isLeftOuter, nullTuple);
                pfrj.setAlias(loj.getAlias());
            } catch (ExecException e1) {
                int errCode = 2058;
                String msg = "Unable to set index on newly create POLocalRearrange.";
                throw new VisitorException(msg, errCode, PigException.BUG, e1);
            }
            pfrj.setResultType(DataType.TUPLE);
            currentPlan.add(pfrj);
            for (Operator op : inputs) {
                try {
                    currentPlan.connect(logToPhyMap.get(op), pfrj);
                } catch (PlanException e) {
                    int errCode = 2015;
                    String msg = "Invalid physical operators in the physical plan" ;
                    throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
                }
            }
            logToPhyMap.put(loj, pfrj);
        }
       
        else if (loj.getJoinType() == LOJoin.JOINTYPE.MERGE && validateMergeJoin(loj)) {
           
            POMergeJoin smj;
            try {
                smj = new POMergeJoin(new OperatorKey(scope,nodeGen.getNextNodeId(scope)),loj.getRequestedParallelisam(),inp,joinPlans,keyTypes);
            }
            catch (Exception e) {
                int errCode = 2042;
                String msg = "Merge Join creation failed";
                throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
            }

            smj.setResultType(DataType.TUPLE);
            currentPlan.add(smj);

            for (Operator op : inputs) {
                try {
                    currentPlan.connect(logToPhyMap.get(op), smj);
                } catch (PlanException e) {
                    int errCode = 2015;
                    String msg = "Invalid physical operators in the physical plan" ;
                    throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
                }
            }
            logToPhyMap.put(loj, smj);
            return;
        }
        else if (loj.getJoinType() == LOJoin.JOINTYPE.HASH){
            POGlobalRearrange poGlobal = new POGlobalRearrange(new OperatorKey(
                    scope, nodeGen.getNextNodeId(scope)), loj
                    .getRequestedParallelisam());
            poGlobal.setAlias(loj.getAlias());
            POPackage poPackage = new POPackage(new OperatorKey(scope, nodeGen
                    .getNextNodeId(scope)), loj.getRequestedParallelisam());
            poPackage.setAlias(loj.getAlias());
            currentPlan.add(poGlobal);
            currentPlan.add(poPackage);
           
            int count = 0;
            Byte type = null;
           
            try {
                currentPlan.connect(poGlobal, poPackage);
                for (int i=0; i<inputs.size(); i++) {      
                    Operator op = inputs.get(i);
                    List<LogicalExpressionPlan> plans =
                        (List<LogicalExpressionPlan>) loj.getJoinPlan(i);
                    POLocalRearrange physOp = new POLocalRearrange(new OperatorKey(
                            scope, nodeGen.getNextNodeId(scope)), loj
                            .getRequestedParallelisam());
                    List<PhysicalPlan> exprPlans = translateExpressionPlans(loj, plans);
//                    currentPlans.push(currentPlan);
//                    for (LogicalExpressionPlan lp : plans) {
//                        currentPlan = new PhysicalPlan();
//                        PlanWalker childWalker = currentWalker
//                                .spawnChildWalker(lp);
//                        pushWalker(childWalker);
//                        //currentWalker.walk(this);
//                        currentWalker.walk(
//                                new ExpToPhyTranslationVisitor(currentWalker.getPlan(),
//                                        childWalker) );
//                        exprPlans.add(currentPlan);
//                        popWalker();
//
//                    }
//                    currentPlan = currentPlans.pop();
                    try {
                        physOp.setPlans(exprPlans);
                    } catch (PlanException pe) {
                        int errCode = 2071;
                        String msg = "Problem with setting up local rearrange's plans.";
                        throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, pe);
                    }
                    try {
                        physOp.setIndex(count++);
                    } catch (ExecException e1) {
                        int errCode = 2058;
                        String msg = "Unable to set index on newly create POLocalRearrange.";
                        throw new VisitorException(msg, errCode, PigException.BUG, e1);
                    }
                    if (plans.size() > 1) {
                        type = DataType.TUPLE;
                        physOp.setKeyType(type);
                    } else {
                        type = exprPlans.get(0).getLeaves().get(0).getResultType();
                        physOp.setKeyType(type);
                    }
                    physOp.setResultType(DataType.TUPLE);

                    currentPlan.add(physOp);

                    try {
                        currentPlan.connect(logToPhyMap.get(op), physOp);
                        currentPlan.connect(physOp, poGlobal);
                    } catch (PlanException e) {
                        int errCode = 2015;
                        String msg = "Invalid physical operators in the physical plan" ;
                        throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e);
                    }

                }
               
            } catch (PlanException e1) {
                int errCode = 2015;
                String msg = "Invalid physical operators in the physical plan" ;
                throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e1);
            }

            poPackage.setKeyType(type);
            poPackage.setResultType(DataType.TUPLE);
            poPackage.setNumInps(count);
           
            boolean[] innerFlags = loj.getInnerFlags();
            poPackage.setInner(innerFlags);
           
            List<PhysicalPlan> fePlans = new ArrayList<PhysicalPlan>();
            List<Boolean> flattenLst = new ArrayList<Boolean>();
           
            try{
                for(int i=0;i< count;i++){
                    PhysicalPlan fep1 = new PhysicalPlan();
                    POProject feproj1 = new POProject(new OperatorKey(scope, nodeGen.getNextNodeId(scope)),
                            loj.getRequestedParallelisam(), i+1); //i+1 since the first column is the "group" field
                    feproj1.setAlias(loj.getAlias());
                    feproj1.setResultType(DataType.BAG);
                    feproj1.setOverloaded(false);
                    fep1.add(feproj1);
                    fePlans.add(fep1);
                    // the parser would have marked the side
                    // where we need to keep empty bags on
                    // non matched as outer (innerFlags[i] would be
                    // false)
                    if(!(innerFlags[i])) {
                        Operator joinInput = inputs.get(i);
                        // for outer join add a bincond
                        // which will project nulls when bag is
                        // empty
                        updateWithEmptyBagCheck(fep1, joinInput);
                    }
View Full Code Here

                 if (!gen.getFlattenFlags()[i]) {
                     continue;
                 }
                
                 LogicalExpressionPlan exp = ll.get(i);
                 Operator s = exp.getSinks().get(0);
                
                 if (s instanceof ProjectExpression) {
                     int inputNum = ((ProjectExpression)s).getInputNum();      
                     int colNum = ((ProjectExpression)s).getColNum();      
                     LogicalRelationalOperator pred = (LogicalRelationalOperator)gen.getPlan().getPredecessors(gen).get(inputNum);
View Full Code Here

                if (!inner){
                    return false;
                }
            }
          
            Operator next = matched.getSinks().get(0);
            while(next != null && next instanceof LOFilter) {
                LOFilter filter = (LOFilter)next;           
                LogicalExpressionPlan filterPlan = filter.getFilterPlan();
               
                // collect all uids used in the filter plan
                Set<Long> uids = new HashSet<Long>();
                Iterator<Operator> iter = filterPlan.getOperators();
                while(iter.hasNext()) {
                    Operator op = iter.next();
                    if (op instanceof ProjectExpression) {
                        long uid = ((ProjectExpression)op).getUid();
                        uids.add(uid);
                    }
                }
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.