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