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 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.hadoop.hive.ql.optimizer.physical;
 import java.util.List;
 import java.util.Map;
Node processor factory for skew join resolver.
 public final class LocalMapJoinProcFactory {
   public static NodeProcessor getJoinProc() {
     return new LocalMapJoinProcessor();
   public static NodeProcessor getGroupByProc() {
     return new MapJoinFollowByProcessor();
   public static NodeProcessor getDefaultProc() {
     return new NodeProcessor() {
       public Object process(Node ndStack<NodestackNodeProcessorCtx procCtx,
           Object... nodeOutputsthrows SemanticException {
         return null;

   public static class MapJoinFollowByProcessor implements NodeProcessor {
     public Object process(Node ndStack<NodestackNodeProcessorCtx ctxObject... nodeOutputs)
         throws SemanticException {
       LocalMapJoinProcCtx context = (LocalMapJoinProcCtxctx;
       if (!nd.getName().equals("GBY")) {
         return null;
       GroupByOperator groupByOp = (GroupByOperatornd;
       float groupByMemoryUsage = context.getParseCtx().getConf().getFloatVar(
       return null;

   public static class LocalMapJoinProcessor implements NodeProcessor {
    public Object process(Node ndStack<NodestackNodeProcessorCtx ctxObject... nodeOutputs)
        throws SemanticException {
      LocalMapJoinProcCtx context = (LocalMapJoinProcCtxctx;
      if (!nd.getName().equals("MAPJOIN")) {
        return null;
      MapJoinOperator mapJoinOp = (MapJoinOperatornd;
      try {
      } catch (Exception e) {
      HashTableSinkDesc hashTableSinkDesc = new HashTableSinkDesc(mapJoinOp.getConf());
      HashTableSinkOperator hashTableSinkOp = (HashTableSinkOperator) OperatorFactory
      // set hashtable memory usage
      float hashtableMemoryUsage;
      if (context.isFollowedByGroupBy()) {
        hashtableMemoryUsage = context.getParseCtx().getConf().getFloatVar(
      } else {
        hashtableMemoryUsage = context.getParseCtx().getConf().getFloatVar(
      // get the last operator for processing big tables
      int bigTable = mapJoinOp.getConf().getPosBigTable();
      Byte[] order = mapJoinOp.getConf().getTagOrder();
      int bigTableAlias = (intorder[bigTable];
      Operator<? extends SerializablebigOp = mapJoinOp.getParentOperators().get(bigTable);
      // the parent ops for hashTableSinkOp
      List<Operator<? extends Serializable>> smallTablesParentOp = new ArrayList<Operator<? extends Serializable>>();
      List<Operator<? extends Serializable>> dummyOperators = new ArrayList<Operator<? extends Serializable>>();
      // get all parents
      List<Operator<? extends Serializable>> parentsOp = mapJoinOp.getParentOperators();
      for (int i = 0; i < parentsOp.size(); i++) {
        if (i == bigTableAlias) {
        Operator<? extends Serializableparent = parentsOp.get(i);
        // let hashtable Op be the child of this parent
        // keep the parent id correct
        // create an new operator: HashTable DummyOpeator, which share the table desc
        HashTableDummyDesc desc = new HashTableDummyDesc();
        HashTableDummyOperator dummyOp = (HashTableDummyOperator) OperatorFactory.get(desc);
        TableDesc tbl;
        if (parent.getSchema() == null) {
          if (parent instanceof TableScanOperator) {
            tbl = ((TableScanOperatorparent).getTableDesc();
          } else {
            throw new SemanticException();
        } else {
          // get parent schema
          RowSchema rowSchema = parent.getSchema();
          tbl = PlanUtils.getIntermediateFileTableDesc(PlanUtils.getFieldSchemasFromRowSchema(
        // let the dummy op be the parent of mapjoin op
        List<Operator<? extends Serializable>> dummyChildren = new ArrayList<Operator<? extends Serializable>>();
        // add this dummy op to the dummp operator list
      for (Operator<? extends Serializableop : dummyOperators) {
      return null;
    public void hasGroupBy(Operator<? extends SerializablemapJoinOp,
        LocalMapJoinProcCtx localMapJoinProcCtxthrows Exception {
      List<Operator<? extends Serializable>> childOps = mapJoinOp.getChildOperators();
      Map<RuleNodeProcessoropRules = new LinkedHashMap<RuleNodeProcessor>();
      opRules.put(new RuleRegExp("R1""GBY%"), LocalMapJoinProcFactory.getGroupByProc());
      // The dispatcher fires the processor corresponding to the closest
      // matching rule and passes the context along
      Dispatcher disp = new DefaultRuleDispatcher(LocalMapJoinProcFactory.getDefaultProc(),
      GraphWalker ogw = new DefaultGraphWalker(disp);
      // iterator the reducer operator tree
      ArrayList<NodetopNodes = new ArrayList<Node>();
  private LocalMapJoinProcFactory() {
    // prevent instantiation
New to GrepCode? Check out our FAQ X