Package org.apache.pig.impl.plan.optimizer

Examples of org.apache.pig.impl.plan.optimizer.OptimizerException


   
    private LogicalOperator getOperator(List<LogicalOperator> nodes) throws FrontendException {
        if((nodes == null) || (nodes.size() <= 0)) {
            int errCode = 2052;
            String msg = "Internal error. Cannot retrieve operator from null or empty list.";
            throw new OptimizerException(msg, errCode, PigException.BUG);
        }
       
        LogicalOperator lo = nodes.get(0);
        if(LOLoad.class.getName().equals(operatorClassName)) {
            if (lo == null || !(lo instanceof LOLoad)) {
                int errCode = 2005;
                String msg = "Expected " + LOLoad.class.getSimpleName()
                        + ", got "
                        + (lo == null ? lo : lo.getClass().getSimpleName());
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }
   
            return lo;
        } else if(LOStream.class.getName().equals(operatorClassName)){
            if (lo == null || !(lo instanceof LOStream)) {
                int errCode = 2005;
                String msg = "Expected " + LOStream.class.getSimpleName()
                        + ", got "
                        + (lo == null ? lo : lo.getClass().getSimpleName());
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }
   
            return lo;
        } else {
            // we should never be called with any other operator class name
            int errCode = 1034;
            String msg = "TypeCastInserter invoked with an invalid operator class name:" + operatorClassName;
            throw new OptimizerException(msg, errCode, PigException.INPUT);
        }
  
    }
View Full Code Here


                                HandleSpec streamOutputSpec = command.getOutputSpec();
                                loadFuncSpec = new FuncSpec(streamOutputSpec.getSpec());
                            } else {
                                int errCode = 2006;
                                String msg = "TypeCastInserter invoked with an invalid operator class name: " + lo.getClass().getSimpleName();
                                throw new OptimizerException(msg, errCode, PigException.BUG);
                            }
                            cast.setLoadFuncSpec(loadFuncSpec);
                            typeChanges.put(fs.canonicalName, fs.type);
                            if(determinedSchema == null) {
                                // Reset the loads field schema to byte array so that it
                                // will reflect reality.
                                fs.type = DataType.BYTEARRAY;
                            } else {
                                // Reset the type to what determinedSchema says it is
                                fs.type = determinedSchema.getField(i).type;
                            }
                        }
                }
            }

            // Build a foreach to insert after the load, giving it a cast for each
            // position that has a type other than byte array.
            LOForEach foreach = new LOForEach(mPlan,
                OperatorKey.genOpKey(scope), genPlans, flattens);
            foreach.setAlias(lo.getAlias());
            // Insert the foreach into the plan and patch up the plan.
            insertAfter(lo, foreach, null);

            rebuildSchemas();

        } catch (OptimizerException oe) {
            throw oe;
        } catch (Exception e) {
            int errCode = 2007;
            String msg = "Unable to insert type casts into plan";
            throw new OptimizerException(msg, errCode, PigException.BUG, e);
        }
    }
View Full Code Here

                                ((LogicalTransformer)rule.getTransformer()).rebuildSchemas();
                                ((LogicalTransformer)rule.getTransformer()).rebuildProjectionMaps();
                            } catch (FrontendException fee) {
                                int errCode = 2145;
                                String msg = "Problem while rebuilding projection map or schema in logical optimizer.";
                                throw new OptimizerException(msg, errCode, PigException.BUG, fee);
                            }

                        }
                        rule.getTransformer().reset();
                    }
View Full Code Here

    @Override
    public boolean check(List<LogicalOperator> nodes) throws OptimizerException {
        if((nodes == null) || (nodes.size() <= 0)) {
            int errCode = 2052;
            String msg = "Internal error. Cannot retrieve operator from null or empty list.";
            throw new OptimizerException(msg, errCode, PigException.BUG);
        }
       
        try {
            LogicalOperator lo = nodes.get(0);
            if (lo == null || !(lo instanceof LOLimit)) {
                int errCode = 2005;
                String msg = "Expected " + LOLimit.class.getSimpleName()
                        + ", got "
                        + (lo == null ? lo : lo.getClass().getSimpleName());
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }
            List<LogicalOperator> predecessors = mPlan.getPredecessors(lo);
            if (predecessors.size()!=1) {
                int errCode = 2008;
                String msg = "Limit cannot have more than one input. Found " + predecessors.size() + " inputs.";
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }
            LogicalOperator predecessor = predecessors.get(0);
           
            // Limit cannot be pushed up
            if (predecessor instanceof LOCogroup || predecessor instanceof LOFilter ||
                    predecessor instanceof LOLoad || predecessor instanceof LOSplit ||
                    predecessor instanceof LODistinct || predecessor instanceof LOJoin)
            {
                return false;
            }
            // Limit cannot be pushed in front of ForEach if it has a flatten
            if (predecessor instanceof LOForEach)
            {
                LOForEach loForEach = (LOForEach)predecessor;
                List<Boolean> mFlatten = loForEach.getFlatten();
                boolean hasFlatten = false;
                for (Boolean b:mFlatten)
                    if (b.equals(true)) hasFlatten = true;
               
                if (hasFlatten) {
                    return false;
                }
            }
        } catch (Exception e) {
            int errCode = 2049;
            String msg = "Error while performing checks to optimize limit operator.";
            throw new OptimizerException(msg, errCode, PigException.BUG);
        }

        return true;
    }
View Full Code Here

    @Override
    public void transform(List<LogicalOperator> nodes) throws OptimizerException {       
        if((nodes == null) || (nodes.size() <= 0)) {
            int errCode = 2052;
            String msg = "Internal error. Cannot retrieve operator from null or empty list.";
            throw new OptimizerException(msg, errCode, PigException.BUG);
        }
        try {
            LogicalOperator lo = nodes.get(0);
            if (lo == null || !(lo instanceof LOLimit)) {
                int errCode = 2005;
                String msg = "Expected " + LOLimit.class.getSimpleName() + ", got " + (lo == null ? lo : lo.getClass().getSimpleName());
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }

            LOLimit limit = (LOLimit)lo;
           
            processNode(limit);
        } catch (OptimizerException oe) {
            throw oe;
        } catch (Exception e) {
            int errCode = 2050;
            String msg = "Internal error. Unable to optimize limit operator.";
            throw new OptimizerException(msg, errCode, PigException.BUG);
        }
    }
View Full Code Here

      try {
            List<LogicalOperator> predecessors = mPlan.getPredecessors(limit);
            if (predecessors.size()!=1) {
              int errCode = 2008;
              String msg = "Limit cannot have more than one input. Found " + predecessors.size() + " inputs.";
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }
            LogicalOperator predecessor = predecessors.get(0);
           
            // Limit cannot be pushed up
            if (predecessor instanceof LOCogroup || predecessor instanceof LOFilter ||
                predecessor instanceof LOLoad || predecessor instanceof LOSplit ||
                predecessor instanceof LODistinct || predecessor instanceof LOJoin)
            {
              return;
            }
            // Limit can be pushed in front of ForEach if it does not have a flatten
            else if (predecessor instanceof LOForEach)
            {
              LOForEach loForEach = (LOForEach)predecessor;
              List<Boolean> mFlatten = loForEach.getFlatten();
              boolean hasFlatten = false;
              for (Boolean b:mFlatten)
                if (b.equals(true)) hasFlatten = true;
             
              // We can safely move LOLimit up
              if (!hasFlatten)
              {
                // Get operator before LOFilter
                LogicalOperator prepredecessor = mPlan.getPredecessors(predecessor).get(0);
                if (prepredecessor!=null)
                {
                    try {
                      mPlan.removeAndReconnect(limit);
                      insertBetween(prepredecessor, limit, predecessor, null);
                     
                    } catch (Exception e) {
                        int errCode = 2009;
                        String msg = "Can not move LOLimit up";
                      throw new OptimizerException(msg, errCode, PigException.BUG, e);
                    }
                }
                else
                {
                    int errCode = 2010;
                    String msg = "LOForEach should have one input";
                  throw new OptimizerException(msg, errCode, PigException.BUG);
                }
                    // we can move LOLimit even further, recursively optimize LOLimit
                    processNode(limit);
              }
            }
            // Limit can be duplicated, and the new instance pushed in front of an operator for the following operators
            // (that is, if you have X->limit, you can transform that to limit->X->limit):
            else if (predecessor instanceof LOCross || predecessor instanceof LOUnion)
            {
              LOLimit newLimit = null;
              List<LogicalOperator> nodesToProcess = new ArrayList<LogicalOperator>();
              for (LogicalOperator prepredecessor:mPlan.getPredecessors(predecessor))
                nodesToProcess.add(prepredecessor);
              for (LogicalOperator prepredecessor:nodesToProcess)
              {
                try {
                  newLimit = limit.duplicate();
                  insertBetween(prepredecessor, newLimit, predecessor, null);
                } catch (Exception e) {
                    int errCode = 2011;
                    String msg = "Can not insert LOLimit clone";
                  throw new OptimizerException(msg, errCode, PigException.BUG, e);
                }
                // we can move the new LOLimit even further, recursively optimize LOLimit
                processNode(newLimit);
              }
            }
            // Limit can be merged into LOSort, result a "limited sort"
            else if (predecessor instanceof LOSort)
            {
                if(mode == ExecType.LOCAL) {
                    //We don't need this optimisation to happen in the local mode.
                    //so we do nothing here.
                } else {
                    LOSort sort = (LOSort)predecessor;
                    if (sort.getLimit()==-1)
                        sort.setLimit(limit.getLimit());
                    else
                        sort.setLimit(sort.getLimit()<limit.getLimit()?sort.getLimit():limit.getLimit());
                    try {
                        mPlan.removeAndReconnect(limit);
                    } catch (Exception e) {
                        int errCode = 2012;
                        String msg = "Can not remove LOLimit after LOSort";
                        throw new OptimizerException(msg, errCode, PigException.BUG, e);
                    }
                }
            }
            // Limit is merged into another LOLimit
            else if (predecessor instanceof LOLimit)
            {
              LOLimit beforeLimit = (LOLimit)predecessor;
              beforeLimit.setLimit(beforeLimit.getLimit()<limit.getLimit()?beforeLimit.getLimit():limit.getLimit());
              try {
                mPlan.removeAndReconnect(limit);
              } catch (Exception e) {
                  int errCode = 2012;
                  String msg = "Can not remove LOLimit after LOLimit";
                throw new OptimizerException(msg, errCode, PigException.BUG, e);
              }
            }
            // Limit and OrderBy (LOSort) can be separated by split
            else if (predecessor instanceof LOSplitOutput) {              
                if(mode == ExecType.LOCAL) {
                    //We don't need this optimisation to happen in the local mode.
                    //so we do nothing here.
                } else {
                    List<LogicalOperator> grandparants = mPlan
                            .getPredecessors(predecessor);
                    // After insertion of splitters, any node in the plan can
                    // have at most one predecessor
                    if (grandparants != null && grandparants.size() != 0
                            && grandparants.get(0) instanceof LOSplit) {                       
                        List<LogicalOperator> greatGrandparants = mPlan
                                .getPredecessors(grandparants.get(0));
                        if (greatGrandparants != null
                                && greatGrandparants.size() != 0
                                && greatGrandparants.get(0) instanceof LOSort) {                          
                            LOSort sort = (LOSort)greatGrandparants.get(0);
                            LOSort newSort = new LOSort(
                                    sort.getPlan(),
                                    new OperatorKey(
                                            sort.getOperatorKey().scope,
                                            NodeIdGenerator
                                                    .getGenerator()
                                                    .getNextNodeId(
                                                            sort.getOperatorKey().scope)),
                                    sort.getSortColPlans(),
                                    sort.getAscendingCols(),
                                    sort.getUserFunc());
                                                 
                            newSort.setLimit(limit.getLimit());
                            try {
                                mPlan.replace(limit, newSort);
                            } catch (PlanException e) {
                                int errCode = 2012;
                                String msg = "Can not replace LOLimit with LOSort after splitter";
                                throw new OptimizerException(msg, errCode, PigException.BUG, e);
                            }
                        }
                    }
                }
            }
            else {
                int errCode = 2013;
                String msg = "Moving LOLimit in front of " + predecessor.getClass().getSimpleName() + " is not implemented";
              throw new OptimizerException(msg, errCode, PigException.BUG);
            }
      } catch (OptimizerException oe) {
          throw oe;
        }
    }
View Full Code Here

        } catch (OptimizerException oe) {
            throw oe;
        } catch (Exception e) {
            int errCode = 2149;
            String msg = "Internal error while trying to check if filters can be pushed up.";
            throw new OptimizerException(msg, errCode, PigException.BUG, e);
        }
    }
View Full Code Here

    private LogicalOperator getOperator(List<LogicalOperator> nodes)
            throws FrontendException {
        if ((nodes == null) || (nodes.size() <= 0)) {
            int errCode = 2052;
            String msg = "Internal error. Cannot retrieve operator from null or empty list.";
            throw new OptimizerException(msg, errCode, PigException.BUG);
        }

        LogicalOperator lo = nodes.get(0);
        if (lo == null || !(lo instanceof LOFilter)) {
            // we should never be called with any other operator class name
            int errCode = 2005;
            String msg = "Expected " + LOFilter.class.getSimpleName()
                    + ", got "
                    + (lo == null ? lo : lo.getClass().getSimpleName());
            throw new OptimizerException(msg, errCode, PigException.INPUT);
        } else {
            return lo;
        }

    }
View Full Code Here

            } else if (mPushBefore) {
                if (mPushBeforeInput == -1) {
                    // something is wrong!
                    int errCode = 2150;
                    String msg = "Internal error. The push before input is not set.";
                    throw new OptimizerException(msg, errCode, PigException.BUG);
                }
                mPlan.pushBefore(predecessor, filter, mPushBeforeInput);
            }
        } catch (OptimizerException oe) {
            throw oe;
        } catch (Exception e) {
            int errCode = 2151;
            String msg = "Internal error while pushing filters up.";
            throw new OptimizerException(msg, errCode, PigException.BUG, e);
        }
    }
View Full Code Here

        TopLevelProjectFinder projectFinder = new TopLevelProjectFinder(lp);
           
        try {
            projectFinder.visit();
        } catch (VisitorException ve) {
            throw new OptimizerException();
        }
        if (projectFinder.getProjectSet()!=null && projectFinder.getProjectSet().size()==1)
        {
            LOProject project = projectFinder.getProjectSet().iterator().next();
            if (lp.getPredecessors(project)==null)
View Full Code Here

TOP

Related Classes of org.apache.pig.impl.plan.optimizer.OptimizerException

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.