PageRenderTime 24ms CodeModel.GetById 18ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/optimizer/GenMRRedSink2.java

#
Java | 84 lines | 45 code | 11 blank | 28 comment | 3 complexity | 2c0d9df9a0a0e83715075aa065716eaa MD5 | raw file
 1/**
 2 * Licensed to the Apache Software Foundation (ASF) under one
 3 * or more contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  The ASF licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.hive.ql.optimizer;
20
21import java.io.Serializable;
22import java.util.Map;
23import java.util.Stack;
24
25import org.apache.hadoop.hive.ql.exec.Operator;
26import org.apache.hadoop.hive.ql.exec.ReduceSinkOperator;
27import org.apache.hadoop.hive.ql.exec.Task;
28import org.apache.hadoop.hive.ql.lib.Node;
29import org.apache.hadoop.hive.ql.lib.NodeProcessor;
30import org.apache.hadoop.hive.ql.lib.NodeProcessorCtx;
31import org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMapRedCtx;
32import org.apache.hadoop.hive.ql.parse.SemanticException;
33
34/**
35 * Processor for the rule - reduce sink followed by reduce sink.
36 */
37public class GenMRRedSink2 implements NodeProcessor {
38
39  public GenMRRedSink2() {
40  }
41
42  /**
43   * Reduce Scan encountered.
44   * 
45   * @param nd
46   *          the reduce sink operator encountered
47   * @param opProcCtx
48   *          context
49   */
50  public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx opProcCtx,
51      Object... nodeOutputs) throws SemanticException {
52    ReduceSinkOperator op = (ReduceSinkOperator) nd;
53    GenMRProcContext ctx = (GenMRProcContext) opProcCtx;
54
55    Map<Operator<? extends Serializable>, GenMapRedCtx> mapCurrCtx = ctx
56        .getMapCurrCtx();
57    GenMapRedCtx mapredCtx = mapCurrCtx.get(op.getParentOperators().get(0));
58    Task<? extends Serializable> currTask = mapredCtx.getCurrTask();
59    Operator<? extends Serializable> currTopOp = mapredCtx.getCurrTopOp();
60    String currAliasId = mapredCtx.getCurrAliasId();
61    Operator<? extends Serializable> reducer = op.getChildOperators().get(0);
62    Map<Operator<? extends Serializable>, Task<? extends Serializable>> opTaskMap = ctx
63        .getOpTaskMap();
64    Task<? extends Serializable> opMapTask = opTaskMap.get(reducer);
65
66    ctx.setCurrTopOp(currTopOp);
67    ctx.setCurrAliasId(currAliasId);
68    ctx.setCurrTask(currTask);
69
70    if (opMapTask == null) {
71      GenMapRedUtils.splitPlan(op, ctx);
72    } else {
73      GenMapRedUtils.joinPlan(op, currTask, opMapTask, ctx, -1, true, false,
74          false);
75      currTask = opMapTask;
76      ctx.setCurrTask(currTask);
77    }
78
79    mapCurrCtx.put(op, new GenMapRedCtx(ctx.getCurrTask(), ctx.getCurrTopOp(),
80        ctx.getCurrAliasId()));
81    return null;
82  }
83
84}