PageRenderTime 22ms CodeModel.GetById 18ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/parse/GenMapRedWalker.java

#
Java | 73 lines | 27 code | 10 blank | 36 comment | 5 complexity | 59085630b9926a4545ce4f1201d9448a 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.parse;
20
21import java.util.List;
22
23import org.apache.hadoop.hive.ql.exec.ReduceSinkOperator;
24import org.apache.hadoop.hive.ql.lib.DefaultGraphWalker;
25import org.apache.hadoop.hive.ql.lib.Dispatcher;
26import org.apache.hadoop.hive.ql.lib.Node;
27
28/**
29 * Walks the operator tree in pre order fashion.
30 */
31public class GenMapRedWalker extends DefaultGraphWalker {
32
33  /**
34   * constructor of the walker - the dispatcher is passed.
35   * 
36   * @param disp
37   *          the dispatcher to be called for each node visited
38   */
39  public GenMapRedWalker(Dispatcher disp) {
40    super(disp);
41  }
42
43  /**
44   * Walk the given operator.
45   * 
46   * @param nd
47   *          operator being walked
48   */
49  @Override
50  public void walk(Node nd) throws SemanticException {
51    List<? extends Node> children = nd.getChildren();
52
53    // maintain the stack of operators encountered
54    opStack.push(nd);
55    dispatch(nd, opStack);
56
57    // kids of reduce sink operator need not be traversed again
58    if ((children == null)
59        || ((nd instanceof ReduceSinkOperator) && (getDispatchedList()
60        .containsAll(children)))) {
61      opStack.pop();
62      return;
63    }
64
65    // move all the children to the front of queue
66    for (Node ch : children) {
67      walk(ch);
68    }
69
70    // done with this operator
71    opStack.pop();
72  }
73}