private void handlePackage(TezOperator pkgTezOp, POPackage pkg) throws VisitorException { // the LocalRearrange(s) must be in the plan of a predecessor tez op int lrFound = 0; List<TezOperator> preds = this.mPlan.getPredecessors(pkgTezOp); for (Iterator<TezOperator> it = preds.iterator(); it.hasNext(); ) { TezOperator predTezOp = it.next(); if (predTezOp.isVertexGroup()) { // Just get one of the inputs to vertex group predTezOp = getPlan().getOperator(predTezOp.getVertexGroupMembers().get(0)); } lrFound += patchPackage(predTezOp, pkgTezOp, pkg); if (lrFound == pkg.getNumInps()) { break; } } if (lrFound != pkg.getNumInps()) { int errCode = 2086; String msg = "Unexpected problem during optimization. Could not find all LocalRearrange operators."; throw new OptimizerException(msg, errCode, PigException.BUG); } }
@Override public void visitLocalRearrange(POLocalRearrange lrearrange) throws VisitorException { POLocalRearrangeTez lr = (POLocalRearrangeTez) lrearrange; if (!(lr.isConnectedToPackage() && lr.getOutputKey().equals(pkgTezOp.getOperatorKey().toString()))) { return; } loRearrangeFound++; Map<Integer, Pair<Boolean, Map<Integer, Integer>>> keyInfo; if (pkg.getPkgr() instanceof LitePackager) { if (lrearrange.getIndex() != 0) { // Throw some exception here throw new RuntimeException( "POLocalRearrange for POPackageLite cannot have index other than 0, but has index - " + lrearrange.getIndex()); } } // annotate the package with information from the LORearrange // update the keyInfo information if already present in the POPackage keyInfo = pkg.getPkgr().getKeyInfo(); if (keyInfo == null) keyInfo = new HashMap<Integer, Pair<Boolean, Map<Integer, Integer>>>(); if (keyInfo.get(Integer.valueOf(lrearrange.getIndex())) != null) { // something is wrong - we should not be getting key info // for the same index from two different Local Rearranges int errCode = 2087; String msg = "Unexpected problem during optimization." + " Found index:" + lrearrange.getIndex() + " in multiple LocalRearrange operators."; throw new OptimizerException(msg, errCode, PigException.BUG); } keyInfo.put( Integer.valueOf(lrearrange.getIndex()), new Pair<Boolean, Map<Integer, Integer>>( lrearrange.isProjectStar(), lrearrange.getProjectedColsMap())); pkg.getPkgr().setKeyInfo(keyInfo); pkg.getPkgr().setKeyTuple(lrearrange.isKeyTuple()); pkg.getPkgr().setKeyCompound(lrearrange.isKeyCompound()); }