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

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/plan/DynamicPartitionCtx.java

#
Java | 194 lines | 137 code | 37 blank | 20 comment | 9 complexity | e38174cf6e2572c1c1be3628725bd750 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.plan;
  19. import java.io.Serializable;
  20. import java.util.ArrayList;
  21. import java.util.HashMap;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import java.util.Map;
  25. import org.apache.hadoop.hive.metastore.Warehouse;
  26. import org.apache.hadoop.hive.ql.exec.ColumnInfo;
  27. import org.apache.hadoop.hive.ql.metadata.Table;
  28. public class DynamicPartitionCtx implements Serializable {
  29. /**
  30. * default serialization ID
  31. */
  32. private static final long serialVersionUID = 1L;
  33. private Map<String, String> partSpec; // partSpec is an ORDERED hash map
  34. private int numDPCols; // number of dynamic partition columns
  35. private int numSPCols; // number of static partition columns
  36. private String spPath; // path name corresponding to SP columns
  37. private String rootPath; // the root path DP columns paths start from
  38. private int numBuckets; // number of buckets in each partition
  39. private Map<String, String> inputToDPCols; // mapping from input column names to DP columns
  40. private List<String> spNames; // sp column names
  41. private List<String> dpNames; // dp column names
  42. private String defaultPartName; // default partition name in case of null or empty value
  43. private int maxPartsPerNode; // maximum dynamic partitions created per mapper/reducer
  44. public DynamicPartitionCtx() {
  45. }
  46. public DynamicPartitionCtx(Table tbl, Map<String, String> partSpec, String defaultPartName,
  47. int maxParts) {
  48. this.partSpec = partSpec;
  49. this.spNames = new ArrayList<String>();
  50. this.dpNames = new ArrayList<String>();
  51. this.numBuckets = 0;
  52. this.maxPartsPerNode = maxParts;
  53. this.defaultPartName = defaultPartName;
  54. for (Map.Entry<String, String> me: partSpec.entrySet()) {
  55. if (me.getValue() == null) {
  56. dpNames.add(me.getKey());
  57. } else {
  58. spNames.add(me.getKey());
  59. }
  60. }
  61. this.numDPCols = dpNames.size();
  62. this.numSPCols = spNames.size();
  63. this.inputToDPCols = new HashMap<String, String>();
  64. if (this.numSPCols > 0) {
  65. this.spPath = Warehouse.makeDynamicPartName(partSpec);
  66. } else {
  67. this.spPath = null;
  68. }
  69. }
  70. public DynamicPartitionCtx(DynamicPartitionCtx dp) {
  71. this.partSpec = dp.partSpec;
  72. this.numDPCols = dp.numDPCols;
  73. this.numSPCols = dp.numSPCols;
  74. this.spPath = dp.spPath;
  75. this.rootPath = dp.rootPath;
  76. this.numBuckets = dp.numBuckets;
  77. this.inputToDPCols = dp.inputToDPCols;
  78. this.spNames = dp.spNames;
  79. this.dpNames = dp.dpNames;
  80. this.defaultPartName = dp.defaultPartName;
  81. this.maxPartsPerNode = dp.maxPartsPerNode;
  82. }
  83. public void mapInputToDP(List<ColumnInfo> fs) {
  84. assert fs.size() == this.numDPCols: "input DP column size != numDPCols";
  85. Iterator<ColumnInfo> itr1 = fs.iterator();
  86. Iterator<String> itr2 = dpNames.iterator();
  87. while (itr1.hasNext() && itr2.hasNext()) {
  88. inputToDPCols.put(itr1.next().getInternalName(), itr2.next());
  89. }
  90. }
  91. public int getMaxPartitionsPerNode() {
  92. return this.maxPartsPerNode;
  93. }
  94. public void setMaxPartitionsPerNode(int maxParts) {
  95. this.maxPartsPerNode = maxParts;
  96. }
  97. public String getDefaultPartitionName() {
  98. return this.defaultPartName;
  99. }
  100. public void setDefaultPartitionName(String pname) {
  101. this.defaultPartName = pname;
  102. }
  103. public void setNumBuckets(int bk) {
  104. this.numBuckets = bk;
  105. }
  106. public int getNumBuckets() {
  107. return this.numBuckets;
  108. }
  109. public void setRootPath(String root) {
  110. this.rootPath = root;
  111. }
  112. public String getRootPath() {
  113. return this.rootPath;
  114. }
  115. public List<String> getDPColNames() {
  116. return this.dpNames;
  117. }
  118. public void setDPColNames(List<String> dp) {
  119. this.dpNames = dp;
  120. }
  121. public List<String> getSPColNames() {
  122. return this.spNames;
  123. }
  124. public void setPartSpec(Map<String, String> ps) {
  125. this.partSpec = ps;
  126. }
  127. public Map<String, String> getPartSpec() {
  128. return this.partSpec;
  129. }
  130. public void setSPColNames(List<String> sp) {
  131. this.spNames = sp;
  132. }
  133. public Map<String, String> getInputToDPCols() {
  134. return this.inputToDPCols;
  135. }
  136. public void setInputToDPCols(Map<String, String> map) {
  137. this.inputToDPCols = map;
  138. }
  139. public void setNumDPCols(int dp) {
  140. this.numDPCols = dp;
  141. }
  142. public int getNumDPCols() {
  143. return this.numDPCols;
  144. }
  145. public void setNumSPCols(int sp) {
  146. this.numSPCols = sp;
  147. }
  148. public int getNumSPCols() {
  149. return this.numSPCols;
  150. }
  151. public void setSPPath(String sp) {
  152. this.spPath = sp;
  153. }
  154. public String getSPPath() {
  155. return this.spPath;
  156. }
  157. }