Package org.apache.pig.impl.logicalLayer

Examples of org.apache.pig.impl.logicalLayer.LogicalOperator


            // return false
            if (predecessors.size() == 0 || predecessors.size() > 1) {
                return false;
            }
               
            LogicalOperator predecessor = predecessors.get(0);

            // if the predecessor is one of LOLoad/LOStore/LOStream/LOLimit/LONative
            // return false
            if (predecessor instanceof LOLoad || predecessor instanceof LOStore
                    || predecessor instanceof LOStream
                    || predecessor instanceof LOLimit
                    || predecessor instanceof LONative) {
                return false;
            }
           
            // TODO
            // for now filters cannot be combined
            // remove this check when filters can be combined
            if (predecessor instanceof LOFilter)
                return false;

            // TODO
            // same rule as filters
            if (predecessor instanceof LOSplitOutput) {
                return false;
            }
            if (predecessor instanceof LOSplit) {
                return false;
            }

            UDFFinder udfFinder = new UDFFinder(filter.getComparisonPlan());
            udfFinder.visit();

            // if the filter's inner plan contains any UDF then return false
            if (udfFinder.foundAnyUDF()) {
                return false;
            }

            CastFinder castFinder = new CastFinder(filter.getComparisonPlan());
            castFinder.visit();

            // if the filter's inner plan contains any casts then return false
            if (castFinder.foundAnyCast()) {
                return false;
            }

            List<RequiredFields> filterRequiredFields = filter
                    .getRequiredFields();
            if (filterRequiredFields == null) {
                return false;
            }
            RequiredFields requiredField = filterRequiredFields.get(0);

            // the filter's conditions contain constant expression
            // return false
            if (requiredField.needNoFields()) {
                return false;
            }

            // if the predecessor is a multi-input operator then detailed
            // checks are required
            if (predecessor instanceof LOCross
                    || predecessor instanceof LOUnion
                    || predecessor instanceof LOCogroup
                    || predecessor instanceof LOJoin) {

                // check if the filter's required fields in conjunction with the
                // predecessor's projection map. If the filter needs more than
                // one input then the filter's expressions have to be split

                List<LogicalOperator> grandParents = mPlan
                        .getPredecessors(predecessor);

                // if the predecessor does not have predecessors return false
                if (grandParents == null || grandParents.size() == 0) {
                    return false;
                }
               
                // check if the predecessor is a group by
                if (grandParents.size() == 1) {
                    if (predecessor instanceof LOCogroup) {
                        mSwap = true;
                        return true;
                    } else {
                        // only a group by can have a single input
                        return false;
                    }
                }

                if (requiredField.needAllFields()) {
                    return false;
                }

                Pair<Boolean, Set<Integer>> mappingResult = isRequiredFieldMapped(requiredField, predecessor.getProjectionMap());
                boolean mapped = mappingResult.first;
                Set<Integer> grandParentIndexes = mappingResult.second;
                if (!mapped) {
                    return false;
                }
               
                // TODO
                // the filter's conditions requires more than one input of its
                // predecessor
                // when the filter's conditions are splittable return true
                if ((grandParentIndexes == null)
                        || (grandParentIndexes.size() == 0)
                        || (grandParentIndexes.size() > 1)) {
                    return false;
                }

                if (predecessor instanceof LOCogroup) {
                    // check for outer
                    if (isAnyOuter((LOCogroup) predecessor)) {
                        return false;
                    }
                }
               
                mPushBeforeInput = grandParentIndexes.iterator().next();
               
                if (predecessor instanceof LOJoin) {
                    boolean otherBranchContainOuter = false;
                    boolean sawInner = false;
                    for (int i=0;i<=mPlan.getSuccessors(predecessor).size();i++) {
                        // We do not push filter if any other branch is outer
                        // See PIG-1289
                        // Also in LOJoin, innerFlag==true indicate that branch is the outer join side
                        // which has the exact opposite semantics
                        // If all innerFlag is true, that implies a regular join
                        // If all innerFlag is false, means a outer join, in this case, we can not push up filter for any path (See PIG-1507)
                        if (i!=mPushBeforeInput && ((LOJoin)predecessor).getInnerFlags()[i]) {
                            otherBranchContainOuter = true;
                        }
                        if (((LOJoin)predecessor).getInnerFlags()[i]==false) {
                            sawInner = true;
                        }
                    }
                    if (!otherBranchContainOuter && ((LOJoin)predecessor).getInnerFlags()[mPushBeforeInput]==false) // all innerFlag is false, implies an outer join
                    {
                        mPushBeforeInput = -1;
                        return false;
                    }
                    if (otherBranchContainOuter && sawInner) // If it is not a regular join and the path we push is on inner side
                    {
                        mPushBeforeInput = -1;
                        return false;
                    }
                }
               
                mPushBefore = true;
                return true;

            } 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;
                    }
                }

                // TODO
                // A better check is to examine each column in the filter's
                // required fields. If the column is the result of a flatten
                // then
                // return false else return true

                // for now if the foreach has a flatten then return false
                if (hasFlatten) {
                    return false;
                }

                Pair<Boolean, Set<Integer>> mappingResult = isRequiredFieldMapped(requiredField, predecessor.getProjectionMap());
                boolean mapped = mappingResult.first;
               
                // Check if it is a direct mapping, that is, project optionally followed by cast, so if project->project, it is not
                // considered as a mapping
                for (Pair<Integer, Integer> pair : requiredField.getFields())
View Full Code Here


            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

    @Override
    public void transform(List<LogicalOperator> nodes)
            throws OptimizerException {
        try {
            LOFilter filter = (LOFilter) getOperator(nodes);
            LogicalOperator predecessor = mPlan.getPredecessors(filter).get(0);
            if (mSwap) {
                mPlan.swap(predecessor, filter);
            } else if (mPushBefore) {
                if (mPushBeforeInput == -1) {
                    // something is wrong!
View Full Code Here

        if (projectFinder.getProjectSet()!=null && projectFinder.getProjectSet().size()==1)
        {
            LOProject project = projectFinder.getProjectSet().iterator().next();
            if (lp.getPredecessors(project)==null)
            {
                LogicalOperator pred = project;
                while (lp.getSuccessors(pred)!=null)
                {
                    if (lp.getSuccessors(pred).size()!=1)
                        return false;
                    if (!(lp.getSuccessors(pred).get(0) instanceof LOCast))
View Full Code Here

            List<Integer> columnNums = new ArrayList<Integer>();
            columnNums.add(col);
            pe = new DereferenceExpression(exprPlan, columnNums);
        }
        else {
            LogicalOperator lg = project.getExpression();
            int input;
            if (oldAttachedRelationalOp instanceof LOSplitOutput) {
                LOSplit split = (LOSplit)outerPlan.getPredecessors(oldAttachedRelationalOp).get(0);
                input = outerPlan.getPredecessors(split).indexOf(lg);
            }
View Full Code Here

        childWalker.walk(childPlanVisitor);
        return childPlanVisitor.exprPlan;
    }
   
    public void visit(LOProject project) throws VisitorException {
        LogicalOperator op = project.getExpression();
       
        if (op == outerPlan.getPredecessors(oldForeach).get(0)) {
            // if this projection is to get a field from outer plan, change it
            // to LOInnerLoad
           
            LOInnerLoad innerLoad = new LOInnerLoad(newInnerPlan,
                    (org.apache.pig.newplan.logical.relational.LOForEach)attachedRelationalOp,
                    project.isStar()?-1:project.getCol());
           
            newInnerPlan.add(innerLoad);
            innerOpsMap.put(project, innerLoad);
           
            // The logical plan part for this foreach plan is done, add ProjectExpression
            // into expression plan.
                                 
            // The logical plan part is done, add this sub plan under LOGenerate,
            // and prepare for the expression plan
            newInnerPlan.connect(innerLoad, gen);
           
            ProjectExpression pe = new ProjectExpression(exprPlan, inputNo++, -1, gen);
            exprPlan.add(pe);
            exprOpsMap.put(project, pe);
            try {
                translateInnerPlanConnection(project, pe);
            } catch (FrontendException e) {
                throw new VisitorException(e);
            }
        }

        // 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
        else if( op instanceof LOProject ) {
            LogicalExpression expOper = exprOpsMap.get(op);
           
            if (expOper!=null) {
                // Add the dereference in the plan
                DereferenceExpression dereferenceExp = new DereferenceExpression(
                        exprPlan, project.getProjection());
                exprOpsMap.put(project, dereferenceExp);
                exprPlan.add(dereferenceExp);
                exprPlan.connect(dereferenceExp, expOper);
            }
        } else {
            if (op instanceof RelationalOperator && project.isSendEmptyBagOnEOP()) {
                LogicalOperator currentOp = op;
                while (currentOp instanceof RelationalOperator) {
                    List<LogicalOperator> preds = mPlan.getPredecessors(currentOp);
                    if (preds!=null)
                        currentOp = preds.get(0);
                    else break;
View Full Code Here

            String msg = "Cannot retrieve operator from null or empty list.";
            throw new OptimizerException(msg, errCode, PigException.BUG);
        }
       
        try {
            LogicalOperator lo = nodes.get(0);
            if (lo == null) {
                int errCode = 2178;
                String msg = "The matching node from the optimizor framework is null";
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }
            if ((lo instanceof LOForEach||lo instanceof LOSplit)&&lo.getSchema()!=null)
                return true;
            return false;
        } catch (Exception e) {
            int errCode = 2179;
            String msg = "Error while performing checks to prune columns.";
View Full Code Here

            int errCode = 2177;
            String msg = "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 LOForEach || lo instanceof LOSplit)) {
                int errCode = 2178;
                String msg = "Expected " + LOForEach.class.getSimpleName() + " or " + LOSplit.class.getSimpleName();
                throw new OptimizerException(msg, errCode, PigException.BUG);
            }
View Full Code Here

        {
            LOProject project = projectFinder.getProjectSet().iterator().next();
            if (innerPlan.getPredecessors(project)==null)
            {
                relayingMapKeys = true;
                LogicalOperator pred = project;
                while (innerPlan.getSuccessors(pred)!=null)
                {
                    if (innerPlan.getSuccessors(pred).size()!=1)
                        return false;
                    if (!(innerPlan.getSuccessors(pred).get(0) instanceof LOCast))
View Full Code Here

                log.warn("fieldsToRead on "+load+" throw an exception, skip it");
            }
        }
       
        // Loader does not support column pruning, insert foreach
        LogicalOperator forEach = null;
        if (response==null || !response.getRequiredFieldResponse())
        {
            List<Integer> columnsToProject = new ArrayList<Integer>();
            for (RequiredField rf : requiredFieldList.getFields())
                columnsToProject.add(rf.getIndex());
View Full Code Here

TOP

Related Classes of org.apache.pig.impl.logicalLayer.LogicalOperator

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.