PageRenderTime 36ms CodeModel.GetById 15ms app.highlight 17ms RepoModel.GetById 2ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/ql/src/java/org/apache/hadoop/hive/ql/plan/HashTableSinkDesc.java

#
Java | 376 lines | 243 code | 72 blank | 61 comment | 2 complexity | 53d61e430e11e60552bae9fb41aa36f0 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 */
 18
 19package org.apache.hadoop.hive.ql.plan;
 20
 21import java.io.Serializable;
 22import java.util.ArrayList;
 23import java.util.HashMap;
 24import java.util.Iterator;
 25import java.util.LinkedHashMap;
 26import java.util.List;
 27import java.util.Map;
 28import java.util.Set;
 29import java.util.Map.Entry;
 30
 31/**
 32 * Map Join operator Descriptor implementation.
 33 *
 34 */
 35@Explain(displayName = "HashTable Sink Operator")
 36public class HashTableSinkDesc extends JoinDesc implements Serializable {
 37  private static final long serialVersionUID = 1L;
 38
 39
 40  // used to handle skew join
 41  private boolean handleSkewJoin = false;
 42  private int skewKeyDefinition = -1;
 43  private Map<Byte, String> bigKeysDirMap;
 44  private Map<Byte, Map<Byte, String>> smallKeysDirMap;
 45  private Map<Byte, TableDesc> skewKeysValuesTables;
 46
 47  // alias to key mapping
 48  private Map<Byte, List<ExprNodeDesc>> exprs;
 49
 50  // alias to filter mapping
 51  private Map<Byte, List<ExprNodeDesc>> filters;
 52
 53  // used for create joinOutputObjectInspector
 54  protected List<String> outputColumnNames;
 55
 56  // key:column output name, value:tag
 57  private transient Map<String, Byte> reversedExprs;
 58
 59  // No outer join involved
 60  protected boolean noOuterJoin;
 61
 62  protected JoinCondDesc[] conds;
 63
 64  protected Byte[] tagOrder;
 65  private TableDesc keyTableDesc;
 66
 67
 68  private Map<Byte, List<ExprNodeDesc>> keys;
 69  private TableDesc keyTblDesc;
 70  private List<TableDesc> valueTblDescs;
 71  private List<TableDesc> valueTblFilteredDescs;
 72
 73
 74  private int posBigTable;
 75
 76  private Map<Byte, List<Integer>> retainList;
 77
 78  private transient String bigTableAlias;
 79
 80  private LinkedHashMap<String, LinkedHashMap<String, ArrayList<String>>> aliasBucketFileNameMapping;
 81  private LinkedHashMap<String, Integer> bucketFileNameMapping;
 82  private float hashtableMemoryUsage;
 83
 84  public HashTableSinkDesc() {
 85    bucketFileNameMapping = new LinkedHashMap<String, Integer>();
 86  }
 87
 88  public HashTableSinkDesc(MapJoinDesc clone) {
 89    this.bigKeysDirMap = clone.getBigKeysDirMap();
 90    this.conds = clone.getConds();
 91    this.exprs= clone.getExprs();
 92    this.handleSkewJoin = clone.getHandleSkewJoin();
 93    this.keyTableDesc = clone.getKeyTableDesc();
 94    this.noOuterJoin = clone.getNoOuterJoin();
 95    this.outputColumnNames = clone.getOutputColumnNames();
 96    this.reversedExprs = clone.getReversedExprs();
 97    this.skewKeyDefinition = clone.getSkewKeyDefinition();
 98    this.skewKeysValuesTables = clone.getSkewKeysValuesTables();
 99    this.smallKeysDirMap = clone.getSmallKeysDirMap();
100    this.tagOrder = clone.getTagOrder();
101    this.filters = clone.getFilters();
102
103    this.keys = clone.getKeys();
104    this.keyTblDesc = clone.getKeyTblDesc();
105    this.valueTblDescs = clone.getValueTblDescs();
106    this.valueTblFilteredDescs = clone.getValueFilteredTblDescs();
107    this.posBigTable = clone.getPosBigTable();
108    this.retainList = clone.getRetainList();
109    this.bigTableAlias = clone.getBigTableAlias();
110    this.aliasBucketFileNameMapping = clone.getAliasBucketFileNameMapping();
111    this.bucketFileNameMapping = clone.getBucketFileNameMapping();
112  }
113
114
115  private void initRetainExprList() {
116    retainList = new HashMap<Byte, List<Integer>>();
117    Set<Entry<Byte, List<ExprNodeDesc>>> set = exprs.entrySet();
118    Iterator<Entry<Byte, List<ExprNodeDesc>>> setIter = set.iterator();
119    while (setIter.hasNext()) {
120      Entry<Byte, List<ExprNodeDesc>> current = setIter.next();
121      List<Integer> list = new ArrayList<Integer>();
122      for (int i = 0; i < current.getValue().size(); i++) {
123        list.add(i);
124      }
125      retainList.put(current.getKey(), list);
126    }
127  }
128
129  public float getHashtableMemoryUsage() {
130    return hashtableMemoryUsage;
131  }
132
133  public void setHashtableMemoryUsage(float hashtableMemoryUsage) {
134    this.hashtableMemoryUsage = hashtableMemoryUsage;
135  }
136
137  public boolean isHandleSkewJoin() {
138    return handleSkewJoin;
139  }
140
141  @Override
142  public void setHandleSkewJoin(boolean handleSkewJoin) {
143    this.handleSkewJoin = handleSkewJoin;
144  }
145
146  @Override
147  public int getSkewKeyDefinition() {
148    return skewKeyDefinition;
149  }
150
151  @Override
152  public void setSkewKeyDefinition(int skewKeyDefinition) {
153    this.skewKeyDefinition = skewKeyDefinition;
154  }
155
156  @Override
157  public Map<Byte, String> getBigKeysDirMap() {
158    return bigKeysDirMap;
159  }
160
161  @Override
162  public void setBigKeysDirMap(Map<Byte, String> bigKeysDirMap) {
163    this.bigKeysDirMap = bigKeysDirMap;
164  }
165
166  @Override
167  public Map<Byte, Map<Byte, String>> getSmallKeysDirMap() {
168    return smallKeysDirMap;
169  }
170
171  @Override
172  public void setSmallKeysDirMap(Map<Byte, Map<Byte, String>> smallKeysDirMap) {
173    this.smallKeysDirMap = smallKeysDirMap;
174  }
175
176  @Override
177  public Map<Byte, TableDesc> getSkewKeysValuesTables() {
178    return skewKeysValuesTables;
179  }
180
181  @Override
182  public void setSkewKeysValuesTables(Map<Byte, TableDesc> skewKeysValuesTables) {
183    this.skewKeysValuesTables = skewKeysValuesTables;
184  }
185
186  @Override
187  public Map<Byte, List<ExprNodeDesc>> getExprs() {
188    return exprs;
189  }
190
191  @Override
192  public void setExprs(Map<Byte, List<ExprNodeDesc>> exprs) {
193    this.exprs = exprs;
194  }
195
196  @Override
197  public Map<Byte, List<ExprNodeDesc>> getFilters() {
198    return filters;
199  }
200
201
202  public List<TableDesc> getValueTblFilteredDescs() {
203    return valueTblFilteredDescs;
204  }
205
206  public void setValueTblFilteredDescs(List<TableDesc> valueTblFilteredDescs) {
207    this.valueTblFilteredDescs = valueTblFilteredDescs;
208  }
209
210  @Override
211  public void setFilters(Map<Byte, List<ExprNodeDesc>> filters) {
212    this.filters = filters;
213  }
214
215  @Override
216  public List<String> getOutputColumnNames() {
217    return outputColumnNames;
218  }
219
220  @Override
221  public void setOutputColumnNames(List<String> outputColumnNames) {
222    this.outputColumnNames = outputColumnNames;
223  }
224
225  @Override
226  public Map<String, Byte> getReversedExprs() {
227    return reversedExprs;
228  }
229
230  @Override
231  public void setReversedExprs(Map<String, Byte> reversedExprs) {
232    this.reversedExprs = reversedExprs;
233  }
234
235  @Override
236  public boolean isNoOuterJoin() {
237    return noOuterJoin;
238  }
239
240  @Override
241  public void setNoOuterJoin(boolean noOuterJoin) {
242    this.noOuterJoin = noOuterJoin;
243  }
244
245  @Override
246  public JoinCondDesc[] getConds() {
247    return conds;
248  }
249
250  @Override
251  public void setConds(JoinCondDesc[] conds) {
252    this.conds = conds;
253  }
254
255  @Override
256  public Byte[] getTagOrder() {
257    return tagOrder;
258  }
259
260  @Override
261  public void setTagOrder(Byte[] tagOrder) {
262    this.tagOrder = tagOrder;
263  }
264
265  @Override
266  public TableDesc getKeyTableDesc() {
267    return keyTableDesc;
268  }
269
270  @Override
271  public void setKeyTableDesc(TableDesc keyTableDesc) {
272    this.keyTableDesc = keyTableDesc;
273  }
274
275
276  public Map<Byte, List<Integer>> getRetainList() {
277    return retainList;
278  }
279
280  public void setRetainList(Map<Byte, List<Integer>> retainList) {
281    this.retainList = retainList;
282  }
283
284  /**
285   * @return the keys
286   */
287  @Explain(displayName = "keys")
288  public Map<Byte, List<ExprNodeDesc>> getKeys() {
289    return keys;
290  }
291
292  /**
293   * @param keys
294   *          the keys to set
295   */
296  public void setKeys(Map<Byte, List<ExprNodeDesc>> keys) {
297    this.keys = keys;
298  }
299
300  /**
301   * @return the position of the big table not in memory
302   */
303  @Explain(displayName = "Position of Big Table")
304  public int getPosBigTable() {
305    return posBigTable;
306  }
307
308  /**
309   * @param posBigTable
310   *          the position of the big table not in memory
311   */
312  public void setPosBigTable(int posBigTable) {
313    this.posBigTable = posBigTable;
314  }
315
316  /**
317   * @return the keyTblDesc
318   */
319  public TableDesc getKeyTblDesc() {
320    return keyTblDesc;
321  }
322
323  /**
324   * @param keyTblDesc
325   *          the keyTblDesc to set
326   */
327  public void setKeyTblDesc(TableDesc keyTblDesc) {
328    this.keyTblDesc = keyTblDesc;
329  }
330
331  /**
332   * @return the valueTblDescs
333   */
334  public List<TableDesc> getValueTblDescs() {
335    return valueTblDescs;
336  }
337
338  /**
339   * @param valueTblDescs
340   *          the valueTblDescs to set
341   */
342  public void setValueTblDescs(List<TableDesc> valueTblDescs) {
343    this.valueTblDescs = valueTblDescs;
344  }
345
346  /**
347   * @return bigTableAlias
348   */
349  public String getBigTableAlias() {
350    return bigTableAlias;
351  }
352
353  /**
354   * @param bigTableAlias
355   */
356  public void setBigTableAlias(String bigTableAlias) {
357    this.bigTableAlias = bigTableAlias;
358  }
359
360  public LinkedHashMap<String, LinkedHashMap<String, ArrayList<String>>> getAliasBucketFileNameMapping() {
361    return aliasBucketFileNameMapping;
362  }
363
364  public void setAliasBucketFileNameMapping(
365      LinkedHashMap<String, LinkedHashMap<String, ArrayList<String>>> aliasBucketFileNameMapping) {
366    this.aliasBucketFileNameMapping = aliasBucketFileNameMapping;
367  }
368
369  public LinkedHashMap<String, Integer> getBucketFileNameMapping() {
370    return bucketFileNameMapping;
371  }
372
373  public void setBucketFileNameMapping(LinkedHashMap<String, Integer> bucketFileNameMapping) {
374    this.bucketFileNameMapping = bucketFileNameMapping;
375  }
376}