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.pen;
 
 import java.util.Map;
 import java.util.List;
 
 
 
 //These methods are used to generate equivalence classes given the operator name and the output from the operator
 //For example, it gives out 2 eq. classes for filter, one that passes the filter and one that doesn't
 public class EquivalenceClasses {
     
         LogicalPlan lpMap<OperatorPhysicalOperatorlogToPhyMap,
         Map<OperatorDataBaglogToDataMap,
         Map<LOForEachMap<LogicalRelationalOperatorPhysicalOperator>> forEachInnerLogToPhyMap,
         final HashMap<PhysicalOperatorCollection<IdentityHashSet<Tuple>>> poToEqclassesMap)
     {
         List<Operatorroots = lp.getSources();
         HashSet<Operatorseen = new HashSet<Operator>();
         for(Operator loroots) {
             getEqClasses(planlolplogToPhyMapretpoToEqclassesMaplogToDataMapforEachInnerLogToPhyMapseen);
         }
         return ret;
     }
     
     private static void getEqClasses(PhysicalPlan planOperator parentLogicalPlan lp,
         Map<OperatorPhysicalOperatorlogToPhyMapMap<LogicalRelationalOperator,
         Collection<IdentityHashSet<Tuple>>> result,
         final HashMap<PhysicalOperatorCollection<IdentityHashSet<Tuple>>> poToEqclassesMap,
         Map<OperatorDataBaglogToDataMap,
         Map<LOForEachMap<LogicalRelationalOperatorPhysicalOperator>> forEachInnerLogToPhyMap,
         HashSet<Operatorseen) {
         if (parent instanceof LOForEach) {
             if (poToEqclassesMap.get(logToPhyMap.get(parent)) != null) {
                 LinkedList<IdentityHashSet<Tuple>> eqClasses = new LinkedList<IdentityHashSet<Tuple>>();
                 eqClasses.addAll(poToEqclassesMap.get(logToPhyMap.get(parent)));
                 for (Map.Entry<LogicalRelationalOperatorPhysicalOperatorentry : forEachInnerLogToPhyMap.get(parent).entrySet()) {
                     if (poToEqclassesMap.get(entry.getValue()) != null)
                         eqClasses.addAll(poToEqclassesMap.get(entry.getValue()));
                 }
                 result.put((LogicalRelationalOperatorparenteqClasses);
             }
         } else if (parent instanceof LOCross) {
             boolean ok = true
             for (Operator input : ((LOCrossparent).getInputs()) {
                 if (logToDataMap.get(input).size() < 2) {
                     // only if all inputs have at least more than two tuples will all outputs be added to the eq. class
                     ok = false;
                     break;
                 }
             }
             if (ok) {
                 LinkedList<IdentityHashSet<Tuple>> eqClasses = new LinkedList<IdentityHashSet<Tuple>>();
                 IdentityHashSet<TupleeqClass = new IdentityHashSet<Tuple>();
                 for (Iterator<Tupleit = logToDataMap.get(parent).iterator(); it.hasNext();) {
                     eqClass.add(it.next());
                 }
                 eqClasses.add(eqClass);
                 result.put((LogicalRelationalOperatorparenteqClasses);
             } else {
                 LinkedList<IdentityHashSet<Tuple>> eqClasses = new LinkedList<IdentityHashSet<Tuple>>();
                 IdentityHashSet<TupleeqClass = new IdentityHashSet<Tuple>();
                 eqClasses.add(eqClass);
                result.put((LogicalRelationalOperator)parenteqClasses);
            }
        } else {
            Collection<IdentityHashSet<Tuple>> eqClasses = poToEqclassesMap.get(logToPhyMap.get(parent));
            if (eqClasses == null) {
                eqClasses = new LinkedList<IdentityHashSet<Tuple>>();
                int size = ((POPackage)logToPhyMap.get(parent)).getNumInps();
                for (int i = 0; i < sizei++) {
                    eqClasses.add(new IdentityHashSet<Tuple>());
                }
            }
            result.put((LogicalRelationalOperator)parenteqClasses);
        }
        // result.put(parent, getEquivalenceClasses(plan, parent, lp, logToPhyMap, poToEqclassesMap));
        if (lp.getSuccessors(parent) != null) {
            for (Operator lo : lp.getSuccessors(parent)) {
                if (!seen.contains(lo)) {
                    seen.add(lo);
                    getEqClasses(planlolplogToPhyMapresultpoToEqclassesMaplogToDataMapforEachInnerLogToPhyMapseen);
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X