Package org.apache.pig.impl.plan

Examples of org.apache.pig.impl.plan.OperatorKey


    }

    @Override
    protected void visit(LOOr op) throws VisitorException {
        String scope = op.getOperatorKey().scope;
        BinaryComparisonOperator exprOp = new POOr(new OperatorKey(scope, nodeGen.getNextNodeId(scope)), op.getRequestedParallelism());
        exprOp.setAlias(op.getAlias());
        exprOp.setLhs((ExpressionOperator)logToPhyMap.get(op.getLhsOperand()));
        exprOp.setRhs((ExpressionOperator)logToPhyMap.get(op.getRhsOperand()));
        LogicalPlan lp = op.getPlan();
       
View Full Code Here


    }

    @Override
    protected void visit(LONot op) throws VisitorException {
        String scope = op.getOperatorKey().scope;
        UnaryComparisonOperator exprOp = new PONot(new OperatorKey(scope, nodeGen.getNextNodeId(scope)), op.getRequestedParallelism());
        exprOp.setAlias(op.getAlias());
        exprOp.setExpr((ExpressionOperator)logToPhyMap.get(op.getOperand()));
        LogicalPlan lp = op.getPlan();
       
        currentPlan.add(exprOp);
View Full Code Here

    @Override
    protected void visit(LOCross cs) throws VisitorException {
        String scope = cs.getOperatorKey().scope;
        List<LogicalOperator> inputs = cs.getInputs();
       
        POGlobalRearrange poGlobal = new POGlobalRearrange(new OperatorKey(
                scope, nodeGen.getNextNodeId(scope)), cs
                .getRequestedParallelism());
        poGlobal.setCustomPartitioner(cs.getCustomPartitioner());
        poGlobal.setAlias(cs.getAlias());
        POPackage poPackage = new POPackage(new OperatorKey(scope, nodeGen
                .getNextNodeId(scope)), cs.getRequestedParallelism());
        poGlobal.setAlias(cs.getAlias());
        currentPlan.add(poGlobal);
        currentPlan.add(poPackage);
       
        int count = 0;
       
        try {
            currentPlan.connect(poGlobal, poPackage);
            List<Boolean> flattenLst = Arrays.asList(true, true);
           
            for (LogicalOperator op : inputs) {
                List<PhysicalOperator> pop = Arrays.asList(logToPhyMap.get(op));
                PhysicalPlan fep1 = new PhysicalPlan();
                ConstantExpression ce1 = new ConstantExpression(new OperatorKey(scope, nodeGen.getNextNodeId(scope)),cs.getRequestedParallelism());
                ce1.setValue(inputs.size());
                ce1.setResultType(DataType.INTEGER);
                fep1.add(ce1);
               
                ConstantExpression ce2 = new ConstantExpression(new OperatorKey(scope, nodeGen.getNextNodeId(scope)),cs.getRequestedParallelism());
                ce2.setValue(count);
                ce2.setResultType(DataType.INTEGER);
                fep1.add(ce2);
                /*Tuple ce1val = TupleFactory.getInstance().newTuple(2);
                ce1val.set(0,inputs.size());
                ce1val.set(1,count);
                ce1.setValue(ce1val);
                ce1.setResultType(DataType.TUPLE);*/
               
               

                POUserFunc gfc = new POUserFunc(new OperatorKey(scope, nodeGen.getNextNodeId(scope)),cs.getRequestedParallelism(), Arrays.asList((PhysicalOperator)ce1,(PhysicalOperator)ce2), new FuncSpec(GFCross.class.getName()));
                gfc.setAlias(cs.getAlias());
                gfc.setResultType(DataType.BAG);
                fep1.addAsLeaf(gfc);
                gfc.setInputs(Arrays.asList((PhysicalOperator)ce1,(PhysicalOperator)ce2));
                /*fep1.add(gfc);
                fep1.connect(ce1, gfc);
                fep1.connect(ce2, gfc);*/
               
                PhysicalPlan fep2 = new PhysicalPlan();
                POProject feproj = new POProject(new OperatorKey(scope, nodeGen.getNextNodeId(scope)), cs.getRequestedParallelism());
                feproj.setAlias(cs.getAlias());
                feproj.setResultType(DataType.TUPLE);
                feproj.setStar(true);
                feproj.setOverloaded(false);
                fep2.add(feproj);
                List<PhysicalPlan> fePlans = Arrays.asList(fep1, fep2);
               
                POForEach fe = new POForEach(new OperatorKey(scope, nodeGen.getNextNodeId(scope)), cs.getRequestedParallelism(), fePlans, flattenLst );
                fe.setAlias(cs.getAlias());
                currentPlan.add(fe);
                currentPlan.connect(logToPhyMap.get(op), fe);
               
                POLocalRearrange physOp = new POLocalRearrange(new OperatorKey(
                        scope, nodeGen.getNextNodeId(scope)), cs
                        .getRequestedParallelism());
                physOp.setAlias(cs.getAlias());
                List<PhysicalPlan> lrPlans = new ArrayList<PhysicalPlan>();
                for(int i=0;i<inputs.size();i++){
                    PhysicalPlan lrp1 = new PhysicalPlan();
                    POProject lrproj1 = new POProject(new OperatorKey(scope, nodeGen.getNextNodeId(scope)), cs.getRequestedParallelism(), i);
                    lrproj1.setAlias(cs.getAlias());
                    lrproj1.setOverloaded(false);
                    lrproj1.setResultType(DataType.INTEGER);
                    lrp1.add(lrproj1);
                    lrPlans.add(lrp1);
                }
               
                physOp.setCross(true);
                physOp.setIndex(count++);
                physOp.setKeyType(DataType.TUPLE);
                physOp.setPlans(lrPlans);
                physOp.setResultType(DataType.TUPLE);
               
                currentPlan.add(physOp);
                currentPlan.connect(fe, physOp);
                currentPlan.connect(physOp, poGlobal);
            }
        } catch (PlanException e1) {
            int errCode = 2015;
            String msg = "Invalid physical operators in the physical plan" ;
            throw new LogicalToPhysicalTranslatorException(msg, errCode, PigException.BUG, e1);
        } catch (ExecException e) {
          int errCode = 2058;
          String msg = "Unable to set index on newly create POLocalRearrange.";
            throw new VisitorException(msg, errCode, PigException.BUG, e);
        }
       
        poPackage.setKeyType(DataType.TUPLE);
        poPackage.setResultType(DataType.TUPLE);
        poPackage.setNumInps(count);
        boolean inner[] = new boolean[count];
        for (int i=0;i<count;i++) {
            inner[i] = true;
        }
        poPackage.setInner(inner);
       
        List<PhysicalPlan> fePlans = new ArrayList<PhysicalPlan>();
        List<Boolean> flattenLst = new ArrayList<Boolean>();
        for(int i=1;i<=count;i++){
            PhysicalPlan fep1 = new PhysicalPlan();
            POProject feproj1 = new POProject(new OperatorKey(scope, nodeGen.getNextNodeId(scope)), cs.getRequestedParallelism(), i);
            feproj1.setAlias(cs.getAlias());
            feproj1.setResultType(DataType.BAG);
            feproj1.setOverloaded(false);
            fep1.add(feproj1);
            fePlans.add(fep1);
            flattenLst.add(true);
        }
       
        POForEach fe = new POForEach(new OperatorKey(scope, nodeGen.getNextNodeId(scope)), cs.getRequestedParallelism(), fePlans, flattenLst );
        fe.setAlias(cs.getAlias());
        currentPlan.add(fe);
        try{
            currentPlan.connect(poPackage, fe);
        }catch (PlanException e1) {
View Full Code Here

        for (LogicalOperator op : inputs) {
            PhysicalOperator physOp = logToPhyMap.get(op);
            inpPOs.add(physOp);
           
            Collection<LogicalPlan> plans = innerPlans.get(op);
            POLocalRearrange poInnerLR = new POLocalRearrange(new OperatorKey(scope, nodeGen.getNextNodeId(scope)));
            poInnerLR.setAlias(alias);
            // LR will contain list of physical plans, because there could be
            // multiple keys and each key can be an expression.
            List<PhysicalPlan> exprPlans = new ArrayList<PhysicalPlan>();
            currentPlans.push(currentPlan);
            for (LogicalPlan lp : plans) {
                currentPlan = new PhysicalPlan();
                PlanWalker<LogicalOperator, LogicalPlan> childWalker = mCurrentWalker
                        .spawnChildWalker(lp);
                pushWalker(childWalker);
                mCurrentWalker.walk(this);
                exprPlans.add(currentPlan);
                popWalker();
            }
            currentPlan = currentPlans.pop();
            try {
                poInnerLR.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);
            }
            innerLRs[count] = poInnerLR;
            try {
                poInnerLR.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);
            }
            poInnerLR.setKeyType(plans.size() > 1 ? DataType.TUPLE :
                        exprPlans.get(0).getLeaves().get(0).getResultType());
            poInnerLR.setResultType(DataType.TUPLE);
        }
       
        POMergeCogroup poCogrp = new POMergeCogroup(new OperatorKey(
                scope, nodeGen.getNextNodeId(scope)),inpPOs,innerLRs,parallel);
        return poCogrp;
    }
View Full Code Here

   
    private POPackage compileToLR_GR_PackTrio(String scope,List<LogicalOperator> inputs,
            int parallel, String customPartitioner, String alias, boolean[] innerFlags, MultiMap<LogicalOperator,
            LogicalPlan> innerPlans) throws VisitorException {

        POGlobalRearrange poGlobal = new POGlobalRearrange(new OperatorKey(
                scope, nodeGen.getNextNodeId(scope)), parallel);
        poGlobal.setAlias(alias);
        poGlobal.setCustomPartitioner(customPartitioner);
        POPackage poPackage = new POPackage(new OperatorKey(scope, nodeGen
                .getNextNodeId(scope)), parallel);
        poPackage.setAlias(alias);
        currentPlan.add(poGlobal);
        currentPlan.add(poPackage);

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

        int count = 0;
        Byte type = null;
        for (LogicalOperator op : inputs) {
            Collection<LogicalPlan> plans = innerPlans.get(op);
            POLocalRearrange physOp = new POLocalRearrange(new OperatorKey(
                    scope, nodeGen.getNextNodeId(scope)), parallel);
            physOp.setAlias(alias);
            List<PhysicalPlan> exprPlans = new ArrayList<PhysicalPlan>();
            currentPlans.push(currentPlan);
            for (LogicalPlan lp : plans) {
View Full Code Here

        List<LogicalOperator> inputs = cg.getInputs();
       
        // can have only one input
        LogicalOperator op = inputs.get(0);
        List<LogicalPlan> plans = (List<LogicalPlan>) cg.getGroupByPlans().get(op);
        POCollectedGroup physOp = new POCollectedGroup(new OperatorKey(
                scope, nodeGen.getNextNodeId(scope)));
        physOp.setAlias(cg.getAlias());
        List<PhysicalPlan> exprPlans = new ArrayList<PhysicalPlan>();
        currentPlans.push(currentPlan);
        for (LogicalPlan lp : plans) {
View Full Code Here

    }

    if (loj.getJoinType() == LOJoin.JOINTYPE.SKEWED) {
      POSkewedJoin skj;
      try {
        skj = new POSkewedJoin(new OperatorKey(scope,nodeGen.getNextNodeId(scope)),
                                parallel,inp, innerFlags);
        skj.setAlias(alias);
        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);
     
      for (int i=0; i < inputs.size(); i++) {
        LogicalOperator op = inputs.get(i);
        if (!innerFlags[i]) {
          try {
            Schema s = op.getSchema();
            // if the schema cannot be determined
            if (s == null) {
              throw new FrontendException();
            }
            skj.addSchema(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 (LogicalOperator 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 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                     
                      Schema inputSchema = inputs.get(1).getSchema();                     
                     
                      // We check if we have a schema before the join
                      if(inputSchema == null) {
                          int errCode = 1109;
                          String msg = "Input (" + 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)),parallel,
                                          inp, ppLists, keyTypes, null, fragment, isLeftOuter, nullTuple);
              pfrj.setAlias(alias);
          } 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 (LogicalOperator 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 && validateMapSideMerge(inputs,loj.getPlan())) {
           
        PhysicalOperator smj;
        boolean usePOMergeJoin = inputs.size() == 2 && innerFlags[0] && innerFlags[1] ;

        if(usePOMergeJoin){
              // inner join on two sorted inputs. We have less restrictive
            // implementation here in a form of POMergeJoin which doesn't
            // require loaders to implement collectable interface.
            try {
                  smj = new POMergeJoin(new OperatorKey(scope,nodeGen.getNextNodeId(scope)),
                                          parallel,inp,joinPlans,keyTypes);
              }
              catch (PlanException e) {
                  int errCode = 2042;
                  String msg = "Merge Join creation failed";
View Full Code Here

        List<Boolean> flattenLst = new ArrayList<Boolean>();
        POForEach fe;
        try{
            for(int i=0;i< inputs.size();i++){
                PhysicalPlan fep1 = new PhysicalPlan();
                POProject feproj1 = new POProject(new OperatorKey(scope, nodeGen.getNextNodeId(scope)),
                        parallel, i+1); //i+1 since the first column is the "group" field
                feproj1.setAlias(alias);
                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])) {
                    LogicalOperator joinInput = inputs.get(i);
                    // for outer join add a bincond
                    // which will project nulls when bag is
                    // empty
                    updateWithEmptyBagCheck(fep1, joinInput);
                }
                flattenLst.add(true);
            }
           
            fe = new POForEach(new OperatorKey(scope, nodeGen.getNextNodeId(scope)),
                    parallel, fePlans, flattenLst );
            fe.setAlias(alias);

        }catch (PlanException e1) {
            int errCode = 2015;
View Full Code Here

    }
 
  @Override
    protected void visit(LOFilter filter) throws VisitorException {
        String scope = filter.getOperatorKey().scope;
        POFilter poFilter = new POFilter(new OperatorKey(scope, nodeGen
                .getNextNodeId(scope)), filter.getRequestedParallelism());
        poFilter.setAlias(filter.getAlias());
        poFilter.setResultType(filter.getType());
        currentPlan.add(poFilter);
        logToPhyMap.put(filter, poFilter);
View Full Code Here

    }

    @Override
    protected void visit(LOStream stream) throws VisitorException {
        String scope = stream.getOperatorKey().scope;
        POStream poStream = new POStream(new OperatorKey(scope, nodeGen
                .getNextNodeId(scope)), stream.getExecutableManager(),
                stream.getStreamingCommand(), this.pc.getProperties());
        poStream.setAlias(stream.getAlias());
        currentPlan.add(poStream);
        logToPhyMap.put(stream, poStream);
View Full Code Here

TOP

Related Classes of org.apache.pig.impl.plan.OperatorKey

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.