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