PageRenderTime 28ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 1ms

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