PageRenderTime 49ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 90 lines | 39 code | 9 blank | 42 comment | 0 complexity | 2e274ae09f21d8e61e4cf9bf0cfe4d9c 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.unionproc;
  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. /**
  34. * Implementation of the union processor. This can be enhanced later on.
  35. * Currently, it does the following: Identify if both the subqueries of UNION
  36. * are map-only. Store that fact in the unionDesc/UnionOperator. If either of
  37. * the sub-query involves a map-reduce job, a FS is introduced on top of the
  38. * UNION. This can be later optimized to clone all the operators above the
  39. * UNION.
  40. *
  41. * The parse Context is not changed.
  42. */
  43. public class UnionProcessor implements Transform {
  44. /**
  45. * empty constructor.
  46. */
  47. public UnionProcessor() {
  48. }
  49. /**
  50. * Transform the query tree. For each union, store the fact whether both the
  51. * sub-queries are map-only
  52. *
  53. * @param pCtx
  54. * the current parse context
  55. */
  56. public ParseContext transform(ParseContext pCtx) throws SemanticException {
  57. // create a walker which walks the tree in a DFS manner while maintaining
  58. // the operator stack.
  59. Map<Rule, NodeProcessor> opRules = new LinkedHashMap<Rule, NodeProcessor>();
  60. opRules.put(new RuleRegExp(new String("R1"), "RS%.*UNION%"),
  61. UnionProcFactory.getMapRedUnion());
  62. opRules.put(new RuleRegExp(new String("R2"), "UNION%.*UNION%"),
  63. UnionProcFactory.getUnknownUnion());
  64. opRules.put(new RuleRegExp(new String("R3"), "TS%.*UNION%"),
  65. UnionProcFactory.getMapUnion());
  66. opRules.put(new RuleRegExp(new String("R3"), "MAPJOIN%.*UNION%"),
  67. UnionProcFactory.getMapJoinUnion());
  68. // The dispatcher fires the processor for the matching rule and passes the
  69. // context along
  70. UnionProcContext uCtx = new UnionProcContext();
  71. Dispatcher disp = new DefaultRuleDispatcher(UnionProcFactory.getNoUnion(),
  72. opRules, uCtx);
  73. GraphWalker ogw = new PreOrderWalker(disp);
  74. // Create a list of topop nodes
  75. ArrayList<Node> topNodes = new ArrayList<Node>();
  76. topNodes.addAll(pCtx.getTopOps().values());
  77. ogw.startWalking(topNodes, null);
  78. pCtx.setUCtx(uCtx);
  79. return pCtx;
  80. }
  81. }