Package org.apache.pig.impl.plan

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


                    int oldNodeColumn = p.getCol();

                    if (mUseOldNode) {
                        // use mOldNode's projection map and find the column number
                        // from the input that
                        ProjectionMap oldNodeMap = mOldNode.getProjectionMap();

                        if (oldNodeMap == null) {
                            // bail out if the projection map is null
                            int errCode = 2156;
                            String msg = "Error while fixing projections. Projection map of node to be replaced is null.";
                            throw new VisitorException(msg, errCode,
                                    PigException.BUG);
                        }

                        if (!oldNodeMap.changes()) {
                            // no change required
                            return;
                        }

                        MultiMap<Integer, ProjectionMap.Column> oldNodeMappedFields = oldNodeMap
                                .getMappedFields();
                        if (oldNodeMappedFields == null) {
                            // there is no mapping available bail out
                            int errCode = 2157;
                            String msg = "Error while fixing projections. No mapping available in old predecessor to replace column.";
                            throw new VisitorException(msg, errCode,
                                    PigException.BUG);

                        }

                        List<ProjectionMap.Column> columns = (List<ProjectionMap.Column>) oldNodeMappedFields.get(oldNodeColumn);
                       
                        if (columns == null) {
                            // there is no mapping for oldNodeColumn
                            // it could be an added field; bail out
                            int errCode = 2158;
                            String msg = "Error during fixing projections. No mapping available in old predecessor for column to be replaced.";
                            throw new VisitorException(msg, errCode,
                                    PigException.BUG);
                        }

                        boolean foundMapping = false;
                        for (ProjectionMap.Column column : columns) {
                          Pair<Integer, Integer> pair = column.getInputColumn();
                            if (pair.first.equals(mPredecessorIndex)) {
                                ArrayList<Integer> newColumns = new ArrayList<Integer>();
                                newColumns.add(pair.second);
                                p.setProjection(newColumns);
                                foundMapping = true;
                                break;
                            }
                        }
                        if (!foundMapping) {
                            // did not find a mapping - bail out
                            int errCode = 2159;
                            String msg = "Error during fixing projections. Could not locate replacement column from the old predecessor.";
                            throw new VisitorException(msg, errCode,
                                    PigException.BUG);
                        } else {
                            // done with adjusting the column number of the
                            // project
                            return;
                        }
                    } else {
                        // here the projection mapping of new node has to be
                        // used to figure out
                        // the reverse mapping. From the newNode projection
                        // mapping search for
                        // the key whose value contains the pair (mOldNodeIndex,
                        // oldNodeColumn)

                        ProjectionMap newNodeMap = mNewNode.getProjectionMap();
                        if (newNodeMap == null) {
                            // did not find a mapping - bail out
                            int errCode = 2160;
                            String msg = "Error during fixing projections. Projection map of new predecessor is null.";
                            throw new VisitorException(msg, errCode,
                                    PigException.BUG);
                        }
                       
                        if (!newNodeMap.changes()) {
                            // no change required
                            return;
                        }

                        MultiMap<Integer, ProjectionMap.Column> newNodeMappedFields = newNodeMap
                                .getMappedFields();
                        if (newNodeMappedFields == null) {
                            // there is no mapping available bail out
                            int errCode = 2161;
                            String msg = "Error during fixing projections. No mapping available in new predecessor to replace column.";
View Full Code Here


       
        if(removedFields.size() == 0) {
            removedFields = null;
        }

        mProjectionMap = new ProjectionMap(mapFields, removedFields, addedFields);
        return mProjectionMap;
    }
View Full Code Here

                    removedFields.add(new Pair<Integer, Integer>(0, i));
                }
            }
        }

        mProjectionMap = new ProjectionMap(mapFields, removedFields, addedFields);
        return mProjectionMap;
    }
View Full Code Here

       
        if(addedFields.size() == 0) {
            addedFields = null;
        }

        mProjectionMap = new ProjectionMap(mapFields, null, addedFields);
        return mProjectionMap;
    }
View Full Code Here

            return mProjectionMap;
        }
       
        if(Schema.equals(inputSchema, outputSchema, false, true)) {
            //there is a one is to one mapping between input and output schemas
            mProjectionMap = new ProjectionMap(false);
            return mProjectionMap;
        } else {
            //problem - input and output schemas for a distinct have to match!
            mProjectionMap = null;
            return mProjectionMap;
View Full Code Here

        if(inputSchema == null) {
            if(outputSchema != null) {
                //determine schema returned null and the user specified a schema
                //OR
                //the predecessor did not have a schema and the user specified a schema
                mProjectionMap = new ProjectionMap(false);
                return mProjectionMap;
            }
        }
       
        if(Schema.equals(inputSchema, outputSchema, false, true)) {
            //there is a one is to one mapping between input and output schemas
            mProjectionMap = new ProjectionMap(false);
            return mProjectionMap;
        } else {
            MultiMap<Integer, ProjectionMap.Column> mapFields = new MultiMap<Integer, ProjectionMap.Column>();
            //compute the mapping assuming its a prefix projection
            for(int i = 0; i < inputSchema.size(); ++i) {
                mapFields.put(i, new ProjectionMap.Column(new Pair<Integer, Integer>(0, i)));
            }
           
            mProjectionMap = new ProjectionMap(mapFields, null, null);
            return mProjectionMap;
        }
    }
View Full Code Here

           
            if(flattenedColumns == null || flattenedColumns.size() == 0) {
                return false;
            }
           
            ProjectionMap foreachProjectionMap = foreach.getProjectionMap();
           
            if(foreachProjectionMap == null) {
                return false;
            }
           
            List<Integer> foreachAddedFields = foreachProjectionMap.getAddedFields();
            if(foreachAddedFields != null) {
                Set<Integer> foreachAddedFieldsSet = new HashSet<Integer>(foreachAddedFields);
                flattenedColumnSet.removeAll(foreachAddedFieldsSet);
            }
           
            if(flattenedColumnSet.size() == 0) {
                return false;
            }
           
            for(LogicalPlan foreachPlan: foreach.getForEachPlans()) {
                UDFFinder udfFinder = new UDFFinder(foreachPlan);
                udfFinder.visit();
   
                // if any of the foreach's inner plans contain a UDF then return false
                if (udfFinder.foundAnyUDF()) {
                    return false;
                }
               
                CastFinder castFinder = new CastFinder(foreachPlan);
                castFinder.visit();

                // TODO
                // if any of the foreach's inner plans contain a cast then return false
                // in the future the cast should be moved appropriately
                if (castFinder.foundAnyCast()) {
                    return false;
                }
            }

            List<LogicalOperator> successors = (mPlan.getSuccessors(foreach) == null ? null
                    : new ArrayList<LogicalOperator>(mPlan
                            .getSuccessors(foreach)));

            // if the foreach has no successors or more than one successor
            // return false
            if (successors == null || successors.size() == 0 || successors.size() > 1) {
                return false;
            }

            LogicalOperator successor = successors.get(0);

            List<LogicalOperator> peers = (mPlan.getPredecessors(successor) == null ? null
                    : new ArrayList<LogicalOperator>(mPlan.getPredecessors(successor)));
           
            // check if any of the foreach's peers is a foreach flatten
            // if so then this rule does not apply
            if (peers != null){
                for(LogicalOperator peer: peers) {
                    if(!peer.equals(foreach)) {
                        if(peer instanceof LOForEach) {
                            LOForEach peerForeach = (LOForEach)peer;
                            if(peerForeach.hasFlatten().first) {
                                return false;
                            }
                        }
                    }
                }
            }
           
            IndexHelper<LogicalOperator> indexHelper = new IndexHelper<LogicalOperator>(peers);
            Integer foreachPosition = indexHelper.getIndex(foreach);
           
            // Check if flattened fields is required by successor, if so, don't optimize
            List<RequiredFields> requiredFieldsList = ((RelationalOperator)successor).getRequiredFields();
            RequiredFields requiredFields = requiredFieldsList.get(foreachPosition.intValue());
           
            MultiMap<Integer, Column> foreachMappedFields = foreachProjectionMap.getMappedFields();
           
            if (requiredFields.getFields()!=null) {
                for (Pair<Integer, Integer> pair : requiredFields.getFields()) {
                    Collection<Column> columns = foreachMappedFields.get(pair.second);
                    if (columns!=null) {
                        for (Column column : columns) {
                            Pair<Integer, Integer> foreachInputColumn = column.getInputColumn();
                            if (foreach.isInputFlattened(foreachInputColumn.second))
                                return false;
                        }
                    }
                }
            }
           
            // the foreach with flatten can be swapped with an order by
            // as the order by will have lesser number of records to sort
            // also the sort does not alter the records that are processed
           
            // the foreach with flatten can be pushed down a cross or a join
            // for the same reason. In this case the foreach has to be first
            // unflattened and then a new foreach has to be inserted after
            // the cross or join. In both cross and foreach the actual columns
            // from the foreach are not altered but positions might be changed
           
            // in the case of union the column is transformed and as a result
            // the foreach flatten cannot be pushed down
           
            // for distinct the output before flattening and the output
            // after flattening might be different. For example, consider
            // {(1), (1)}. Distinct of this bag is still {(1), (1)}.
            // distinct(flatten({(1), (1)})) is (1). However,
            // flatten(distinct({(1), (1)})) is (1), (1)
           
            // in both cases correctness is not affected
            if(successor instanceof LOSort) {
                LOSort sort = (LOSort) successor;
                RequiredFields sortRequiredField = sort.getRequiredFields().get(0);
               
                if(sortRequiredField.getNeedAllFields()) {
                    return false;
                }
               
                List<Pair<Integer, Integer>> sortInputs = sortRequiredField.getFields();
                Set<Integer> requiredInputs = new HashSet<Integer>();
                for(Pair<Integer, Integer> pair: sortInputs) {
                    requiredInputs.add(pair.second);
                }
               
                requiredInputs.retainAll(flattenedColumnSet);
                // the intersection of the sort's required inputs
                // and the flattened columns in the foreach should
                // be null, i.e., the size of required inputs == 0
                if(requiredInputs.size() != 0) {
                    return false;
                }
               
                mSwap = true;
                return true;
            } else if (successor instanceof LOCross
                    || successor instanceof LOJoin) {
               
                List<LogicalOperator> children = mPlan.getSuccessors(successor);
               
                if(children == null || children.size() > 1) {
                    return false;
                }
               
                ProjectionMap succProjectionMap = successor.getProjectionMap();
               
                if(succProjectionMap == null) {
                    return false;
                }
               
                MultiMap<Integer, ProjectionMap.Column> mappedFields = succProjectionMap.getMappedFields();
               
                if(mappedFields == null) {
                    return false;
                }
View Full Code Here

            //add all the elements of the input schema to the removed fields
            for(int i = 0; i < inputSchema.size(); ++i) {
                removedFields.add(new Pair<Integer, Integer>(0, i));
            }
        }
        mProjectionMap = new ProjectionMap(null, (removedFields.size() == 0? null: removedFields), addedFields);
        return mProjectionMap;
    }
View Full Code Here

            return mProjectionMap;
        }
*/       
        if(Schema.equals(inputSchema, outputSchema, false, true)) {
            //there is a one is to one mapping between input and output schemas
            mProjectionMap = new ProjectionMap(false);
            return mProjectionMap;
        } else {
            //problem - input and output schemas for a split output have to match!
            mProjectionMap = null;
            return mProjectionMap;
View Full Code Here

        }
       
       
        if(Schema.equals(inputSchema, outputSchema, false, true)) {
            //there is a one is to one mapping between input and output schemas
            mProjectionMap = new ProjectionMap(false);
            return mProjectionMap;
        } else {
            //problem - input and output schemas for a store have to match!
            mProjectionMap = null;
            return mProjectionMap;
View Full Code Here

TOP

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

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.