PageRenderTime 13ms CodeModel.GetById 8ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/optimizer/pcr/PartitionConditionRemover.java

#
Java | 87 lines | 41 code | 13 blank | 33 comment | 1 complexity | 37ab913bbc14a23bd9d54097f4e8e51c 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.pcr;
20
21import java.util.ArrayList;
22import java.util.LinkedHashMap;
23import java.util.List;
24import java.util.Map;
25
26import org.apache.commons.logging.Log;
27import org.apache.commons.logging.LogFactory;
28import org.apache.hadoop.hive.ql.lib.DefaultGraphWalker;
29import org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher;
30import org.apache.hadoop.hive.ql.lib.Dispatcher;
31import org.apache.hadoop.hive.ql.lib.GraphWalker;
32import org.apache.hadoop.hive.ql.lib.Node;
33import org.apache.hadoop.hive.ql.lib.NodeProcessor;
34import org.apache.hadoop.hive.ql.lib.Rule;
35import org.apache.hadoop.hive.ql.lib.RuleRegExp;
36import org.apache.hadoop.hive.ql.optimizer.Transform;
37import org.apache.hadoop.hive.ql.parse.ParseContext;
38import org.apache.hadoop.hive.ql.parse.SemanticException;
39
40/**
41 * The transformation step that does partition condition remover.
42 *
43 */
44public class PartitionConditionRemover implements Transform {
45
46  // The log
47  private static final Log LOG = LogFactory
48      .getLog("hive.ql.optimizer.pcr.PartitionConditionRemover");
49
50  /*
51   * (non-Javadoc)
52   *
53   * @see
54   * org.apache.hadoop.hive.ql.optimizer.Transform#transform(org.apache.hadoop
55   * .hive.ql.parse.ParseContext)
56   */
57  @Override
58  public ParseContext transform(ParseContext pctx) throws SemanticException {
59
60    // create a the context for walking operators
61    List<PcrOpWalkerCtx.OpToDeleteInfo> opToRemove =
62        new ArrayList<PcrOpWalkerCtx.OpToDeleteInfo>();
63    PcrOpWalkerCtx opWalkerCtx = new PcrOpWalkerCtx(pctx, opToRemove);
64
65    Map<Rule, NodeProcessor> opRules = new LinkedHashMap<Rule, NodeProcessor>();
66    opRules.put(new RuleRegExp("R1", "(TS%FIL%)|(TS%FIL%FIL%)"), PcrOpProcFactory
67        .getFilterProc());
68
69    // The dispatcher fires the processor corresponding to the closest matching
70    // rule and passes the context along
71    Dispatcher disp = new DefaultRuleDispatcher(PcrOpProcFactory.getDefaultProc(),
72        opRules, opWalkerCtx);
73    GraphWalker ogw = new DefaultGraphWalker(disp);
74
75    // Create a list of topop nodes
76    ArrayList<Node> topNodes = new ArrayList<Node>();
77    topNodes.addAll(pctx.getTopOps().values());
78    ogw.startWalking(topNodes, null);
79
80    for (PcrOpWalkerCtx.OpToDeleteInfo entry : opToRemove) {
81      entry.getParent().removeChildAndAdoptItsChildren(entry.getOperator());
82    }
83
84    return pctx;
85  }
86
87}