PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Java | 117 lines | 71 code | 10 blank | 36 comment | 11 complexity | 6b2d51a855fa54d18eeee53b27cf8389 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;
  19. import java.io.Serializable;
  20. import java.util.HashSet;
  21. import java.util.Map;
  22. import java.util.Set;
  23. import java.util.Stack;
  24. import org.apache.hadoop.hive.ql.exec.Operator;
  25. import org.apache.hadoop.hive.ql.exec.TableScanOperator;
  26. import org.apache.hadoop.hive.ql.exec.Task;
  27. import org.apache.hadoop.hive.ql.exec.TaskFactory;
  28. import org.apache.hadoop.hive.ql.lib.Node;
  29. import org.apache.hadoop.hive.ql.lib.NodeProcessor;
  30. import org.apache.hadoop.hive.ql.lib.NodeProcessorCtx;
  31. import org.apache.hadoop.hive.ql.metadata.Partition;
  32. import org.apache.hadoop.hive.ql.optimizer.GenMRProcContext.GenMapRedCtx;
  33. import org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.tableSpec;
  34. import org.apache.hadoop.hive.ql.parse.ParseContext;
  35. import org.apache.hadoop.hive.ql.parse.PrunedPartitionList;
  36. import org.apache.hadoop.hive.ql.parse.QBParseInfo;
  37. import org.apache.hadoop.hive.ql.parse.SemanticException;
  38. import org.apache.hadoop.hive.ql.plan.MapredWork;
  39. import org.apache.hadoop.hive.ql.plan.StatsWork;
  40. /**
  41. * Processor for the rule - table scan.
  42. */
  43. public class GenMRTableScan1 implements NodeProcessor {
  44. public GenMRTableScan1() {
  45. }
  46. /**
  47. * Table Sink encountered.
  48. *
  49. * @param nd
  50. * the table sink operator encountered
  51. * @param opProcCtx
  52. * context
  53. */
  54. public Object process(Node nd, Stack<Node> stack, NodeProcessorCtx opProcCtx,
  55. Object... nodeOutputs) throws SemanticException {
  56. TableScanOperator op = (TableScanOperator) nd;
  57. GenMRProcContext ctx = (GenMRProcContext) opProcCtx;
  58. ParseContext parseCtx = ctx.getParseCtx();
  59. Map<Operator<? extends Serializable>, GenMapRedCtx> mapCurrCtx = ctx.getMapCurrCtx();
  60. // create a dummy MapReduce task
  61. MapredWork currWork = GenMapRedUtils.getMapRedWork(parseCtx.getConf());
  62. Task<? extends Serializable> currTask = TaskFactory.get(currWork, parseCtx.getConf());
  63. Operator<? extends Serializable> currTopOp = op;
  64. ctx.setCurrTask(currTask);
  65. ctx.setCurrTopOp(currTopOp);
  66. for (String alias : parseCtx.getTopOps().keySet()) {
  67. Operator<? extends Serializable> currOp = parseCtx.getTopOps().get(alias);
  68. if (currOp == op) {
  69. String currAliasId = alias;
  70. ctx.setCurrAliasId(currAliasId);
  71. mapCurrCtx.put(op, new GenMapRedCtx(currTask, currTopOp, currAliasId));
  72. QBParseInfo parseInfo = parseCtx.getQB().getParseInfo();
  73. if (parseInfo.isAnalyzeCommand()) {
  74. // ANALYZE TABLE T [PARTITION (...)] COMPUTE STATISTICS;
  75. // The plan consists of a simple MapRedTask followed by a StatsTask.
  76. // The MR task is just a simple TableScanOperator
  77. StatsWork statsWork = new StatsWork(parseCtx.getQB().getParseInfo().getTableSpec());
  78. statsWork.setAggKey(op.getConf().getStatsAggPrefix());
  79. Task<StatsWork> statsTask = TaskFactory.get(statsWork, parseCtx.getConf());
  80. currTask.addDependentTask(statsTask);
  81. ctx.getRootTasks().add(currTask);
  82. currWork.setGatheringStats(true);
  83. // NOTE: here we should use the new partition predicate pushdown API to get a list of pruned list,
  84. // and pass it to setTaskPlan as the last parameter
  85. Set<Partition> confirmedPartns = new HashSet<Partition>();
  86. tableSpec tblSpec = parseInfo.getTableSpec();
  87. if (tblSpec.specType == tableSpec.SpecType.STATIC_PARTITION) {
  88. // static partition
  89. confirmedPartns.add(tblSpec.partHandle);
  90. } else if (tblSpec.specType == tableSpec.SpecType.DYNAMIC_PARTITION) {
  91. // dynamic partition
  92. confirmedPartns.addAll(tblSpec.partitions);
  93. }
  94. if (confirmedPartns.size() > 0) {
  95. PrunedPartitionList partList = new PrunedPartitionList(confirmedPartns, new HashSet<Partition>(), null);
  96. GenMapRedUtils.setTaskPlan(currAliasId, currTopOp, currWork, false, ctx, partList);
  97. } else { // non-partitioned table
  98. GenMapRedUtils.setTaskPlan(currAliasId, currTopOp, currWork, false, ctx);
  99. }
  100. }
  101. return null;
  102. }
  103. }
  104. assert false;
  105. return null;
  106. }
  107. }