PageRenderTime 21ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 82 lines | 41 code | 12 blank | 29 comment | 2 complexity | 3c06223ec7422733a8cc70a7ab5e9636 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.lineage;
20
21import java.util.ArrayList;
22import java.util.LinkedHashMap;
23import java.util.Map;
24
25import org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher;
26import org.apache.hadoop.hive.ql.lib.Dispatcher;
27import org.apache.hadoop.hive.ql.lib.GraphWalker;
28import org.apache.hadoop.hive.ql.lib.Node;
29import org.apache.hadoop.hive.ql.lib.NodeProcessor;
30import org.apache.hadoop.hive.ql.lib.PreOrderWalker;
31import org.apache.hadoop.hive.ql.lib.Rule;
32import org.apache.hadoop.hive.ql.lib.RuleRegExp;
33import org.apache.hadoop.hive.ql.optimizer.Transform;
34import org.apache.hadoop.hive.ql.parse.ParseContext;
35import org.apache.hadoop.hive.ql.parse.SemanticException;
36import org.apache.hadoop.hive.ql.session.SessionState;
37
38/**
39 * This class generates the lineage information for the columns
40 * and tables from the plan before it goes through other
41 * optimization phases.
42 */
43public class Generator implements Transform {
44
45  /* (non-Javadoc)
46   * @see org.apache.hadoop.hive.ql.optimizer.Transform#transform(org.apache.hadoop.hive.ql.parse.ParseContext)
47   */
48  @Override
49  public ParseContext transform(ParseContext pctx) throws SemanticException {
50
51    // Create the lineage context
52    LineageCtx lCtx = new LineageCtx(pctx);
53
54    Map<Rule, NodeProcessor> opRules = new LinkedHashMap<Rule, NodeProcessor>();
55    opRules.put(new RuleRegExp("R1", "TS%"), OpProcFactory.getTSProc());
56    opRules.put(new RuleRegExp("R2", "SCR%"), OpProcFactory.getTransformProc());
57    opRules.put(new RuleRegExp("R3", "UDTF%"), OpProcFactory.getTransformProc());
58    opRules.put(new RuleRegExp("R4", "SEL%"), OpProcFactory.getSelProc());
59    opRules.put(new RuleRegExp("R5", "GBY%"), OpProcFactory.getGroupByProc());
60    opRules.put(new RuleRegExp("R6", "UNION%"), OpProcFactory.getUnionProc());
61    opRules.put(new RuleRegExp("R7", "JOIN%|MAPJOIN%"), OpProcFactory.getJoinProc());
62    opRules.put(new RuleRegExp("R8", "RS%"), OpProcFactory.getReduceSinkProc());
63    opRules.put(new RuleRegExp("R9", "LVJ%"), OpProcFactory.getLateralViewJoinProc());
64
65    // The dispatcher fires the processor corresponding to the closest matching rule and passes the context along
66    Dispatcher disp = new DefaultRuleDispatcher(OpProcFactory.getDefaultProc(), opRules, lCtx);
67    GraphWalker ogw = new PreOrderWalker(disp);
68
69    // Create a list of topop nodes
70    ArrayList<Node> topNodes = new ArrayList<Node>();
71    topNodes.addAll(pctx.getTopOps().values());
72    ogw.startWalking(topNodes, null);
73
74    // Transfer the index from the lineage context to the session state.
75    if (SessionState.get() != null) {
76      SessionState.get().getLineageState().setIndex(lCtx.getIndex());
77    }
78
79    return pctx;
80  }
81
82}