Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.apache.pig.backend.hadoop.executionengine.physicalLayer.util;
 
 import java.net.URI;
 
 
Utility class with a few helper functions to deal with physical plans.
 
 public class PlanHelper {
 
     private final static Log log = LogFactory.getLog(new PlanHelper().getClass());
 
     private PlanHelper() {}

    
Creates a relative path that can be used to build a temporary place to store the output from a number of map-reduce tasks.
 
     public static String makeStoreTmpPath(String orig) {
        Path path = new Path(orig);
        URI uri = path.toUri();
        uri.normalize();
        String pathStr = uri.getPath();
        if (path.isAbsolute()) {
            return new Path("abs"+pathStr).toString();
        } else {
            return new Path("rel/"+pathStr).toString();
        }
    }
    public static <C extends PhysicalOperatorboolean containsPhysicalOperator(PhysicalPlan plan,
            Class<C> opClassthrows VisitorException {
        OpFinder<C> finder = new OpFinder<C>(planopClass);
        finder.visit();
        return finder.planContainsOp();
    }

    
Returns a LinkedList of operators contained within the physical plan which implement the supplied class, in dependency order. Returns an empty LinkedList of no such operators exist.

Parameters:
plan
opClass
Returns:
a LinkedList of operators contained within the plan which implement the supplied class; empty if no such ops exist.
Throws:
org.apache.pig.impl.plan.VisitorException
    public static <C extends PhysicalOperatorLinkedList<C> getPhysicalOperators(PhysicalPlan plan,
            Class<C> opClassthrows VisitorException {
        OpFinder<C> finder = new OpFinder<C>(planopClass);
        finder.visit();
        return finder.getFoundOps();
    }
    private static class OpFinder<C extends PhysicalOperatorextends PhyPlanVisitor {
        final Class<C> opClass;
        private LinkedList<C> foundOps = Lists.newLinkedList();
        public OpFinder(PhysicalPlan plan,
                Class<C> opClass) {
            super(plannew DependencyOrderWalker<PhysicalOperatorPhysicalPlan>(plan));
            this. = opClass;
        }
        public LinkedList<C> getFoundOps() {
            return ;
        }
        public boolean planContainsOp() {
            return !.isEmpty();
        }
        @SuppressWarnings("unchecked")
        private void visit(PhysicalOperator op) {
            if (.isAssignableFrom(op.getClass())) {
                .add((C) op);
            }
        }
        @Override
        public void visitLoad(POLoad ldthrows VisitorException {
            super.visitLoad(ld);
            visit(ld);
        }
        @Override
        public void visitStore(POStore stthrows VisitorException {
            super.visitStore(st);
            visit(st);
        }
        @Override
        public void visitNative(PONative natthrows VisitorException {
            super.visitNative(nat);
            visit(nat);
        }
        @Override
        public void visitFilter(POFilter flthrows VisitorException {
            super.visitFilter(fl);
            visit(fl);
        }
        @Override
        public void visitCollectedGroup(POCollectedGroup mg)
                throws VisitorException {
            super.visitCollectedGroup(mg);
            visit(mg);
        }
        @Override
        public void visitLocalRearrange(POLocalRearrange lr)
                throws VisitorException {
            super.visitLocalRearrange(lr);
            visit(lr);
        }
        @Override
        public void visitGlobalRearrange(POGlobalRearrange gr)
                throws VisitorException {
            super.visitGlobalRearrange(gr);
            visit(gr);
        }
        @Override
        public void visitPackage(POPackage pkgthrows VisitorException {
            super.visitPackage(pkg);
            visit(pkg);
        }
        @Override
        public void visitCombinerPackage(POCombinerPackage pkg)
                throws VisitorException {
            super.visitCombinerPackage(pkg);
            visit(pkg);
        }
        @Override
        public void visitMultiQueryPackage(POMultiQueryPackage pkg)
                throws VisitorException {
            super.visitMultiQueryPackage(pkg);
            visit(pkg);
        }
        @Override
        public void visitPOForEach(POForEach nfethrows VisitorException {
            super.visitPOForEach(nfe);
            visit(nfe);
        }
        @Override
        public void visitUnion(POUnion unthrows VisitorException {
            super.visitUnion(un);
            visit(un);
        }
        @Override
        public void visitSplit(POSplit splthrows VisitorException {
            super.visitSplit(spl);
            visit(spl);
        }
        @Override
        public void visitDemux(PODemux demuxthrows VisitorException {
            super.visitDemux(demux);
            visit(demux);
        }
        @Override
        public void visitDistinct(PODistinct distinctthrows VisitorException {
            super.visitDistinct(distinct);
            visit(distinct);
        }
        @Override
        public void visitSort(POSort sortthrows VisitorException {
            super.visitSort(sort);
            visit(sort);
        }
        @Override
        public void visitConstant(ConstantExpression cnst)
                throws VisitorException {
            super.visitConstant(cnst);
            visit(cnst);
        }
        @Override
        public void visitProject(POProject projthrows VisitorException {
            super.visitProject(proj);
            visit(proj);
        }
        @Override
        public void visitGreaterThan(GreaterThanExpr grt)
                throws VisitorException {
            super.visitGreaterThan(grt);
            visit(grt);
        }
        @Override
        public void visitLessThan(LessThanExpr ltthrows VisitorException {
            super.visitLessThan(lt);
            visit(lt);
        }
        @Override
        public void visitGTOrEqual(GTOrEqualToExpr gtethrows VisitorException {
            super.visitGTOrEqual(gte);
            visit(gte);
        }
        @Override
        public void visitLTOrEqual(LTOrEqualToExpr ltethrows VisitorException {
            super.visitLTOrEqual(lte);
            visit(lte);
        }
        @Override
        public void visitEqualTo(EqualToExpr eqthrows VisitorException {
            super.visitEqualTo(eq);
            visit(eq);
        }
        @Override
        public void visitNotEqualTo(NotEqualToExpr eqthrows VisitorException {
            super.visitNotEqualTo(eq);
            visit(eq);
        }
        @Override
        public void visitRegexp(PORegexp rethrows VisitorException {
            super.visitRegexp(re);
            visit(re);
        }
        @Override
        public void visitIsNull(POIsNull isNullthrows VisitorException {
            super.visitIsNull(isNull);
            visit(isNull);
        }
        @Override
        public void visitAdd(Add addthrows VisitorException {
            super.visitAdd(add);
            visit(add);
        }
        @Override
        public void visitSubtract(Subtract subthrows VisitorException {
            super.visitSubtract(sub);
            visit(sub);
        }
        @Override
        public void visitMultiply(Multiply multhrows VisitorException {
            super.visitMultiply(mul);
            visit(mul);
        }
        @Override
        public void visitDivide(Divide dvthrows VisitorException {
            super.visitDivide(dv);
            visit(dv);
        }
        @Override
        public void visitMod(Mod modthrows VisitorException {
            super.visitMod(mod);
            visit(mod);
        }
        @Override
        public void visitAnd(POAnd andthrows VisitorException {
            super.visitAnd(and);
            visit(and);
        }
        @Override
        public void visitOr(POOr orthrows VisitorException {
            super.visitOr(or);
            visit(or);
        }
        @Override
        public void visitNot(PONot notthrows VisitorException {
            super.visitNot(not);
            visit(not);
        }
        @Override
        public void visitBinCond(POBinCond binCond) {
            super.visitBinCond(binCond);
            visit(binCond);
        }
        @Override
        public void visitNegative(PONegative negative) {
            super.visitNegative(negative);
            visit(negative);
        }
        @Override
        public void visitUserFunc(POUserFunc userFuncthrows VisitorException {
            super.visitUserFunc(userFunc);
            visit(userFunc);
        }
        @Override
        public void visitComparisonFunc(POUserComparisonFunc compFunc)
                throws VisitorException {
            super.visitComparisonFunc(compFunc);
            visit(compFunc);
    }
        @Override
        public void visitMapLookUp(POMapLookUp mapLookUp) {
            super.visitMapLookUp(mapLookUp);
            visit(mapLookUp);
        }
        @Override
        public void visitJoinPackage(POJoinPackage joinPackage)
                throws VisitorException {
            super.visitJoinPackage(joinPackage);
            visit(joinPackage);
        }
        @Override
        public void visitCast(POCast cast) {
            super.visitCast(cast);
            visit(cast);
        }
        @Override
        public void visitLimit(POLimit limthrows VisitorException {
            super.visitLimit(lim);
            visit(lim);
        }
        @Override
        public void visitCross(POCross crossthrows VisitorException {
            super.visitCross(cross);
            visit(cross);
        }
        @Override
        public void visitFRJoin(POFRJoin jointhrows VisitorException {
            super.visitFRJoin(join);
            visit(join);
        }
        @Override
        public void visitMergeJoin(POMergeJoin jointhrows VisitorException {
            super.visitMergeJoin(join);
            visit(join);
        }
        @Override
        public void visitMergeCoGroup(POMergeCogroup mergeCoGrp)
                throws VisitorException {
            super.visitMergeCoGroup(mergeCoGrp);
            visit(mergeCoGrp);
        }
        @Override
        public void visitStream(POStream streamthrows VisitorException {
            super.visitStream(stream);
            visit(stream);
        }
        @Override
        public void visitSkewedJoin(POSkewedJoin skthrows VisitorException {
            super.visitSkewedJoin(sk);
            visit(sk);
        }
        @Override
        public void visitPartitionRearrange(POPartitionRearrange pr)
                throws VisitorException {
            super.visitPartitionRearrange(pr);
            visit(pr);
        }
        @Override
        public void visitPOOptimizedForEach(POOptimizedForEach optimizedForEach)
                throws VisitorException {
            super.visitPOOptimizedForEach(optimizedForEach);
            visit(optimizedForEach);
        }
        @Override
        public void visitPreCombinerLocalRearrange(
                POPreCombinerLocalRearrange preCombinerLocalRearrange) {
            super.visitPreCombinerLocalRearrange(preCombinerLocalRearrange);
            visit(preCombinerLocalRearrange);
        }
        @Override
        public void visitPartialAgg(POPartialAgg poPartialAgg) {
            super.visitPartialAgg(poPartialAgg);
            visit(poPartialAgg);
        }
    }
New to GrepCode? Check out our FAQ X