PageRenderTime 47ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

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

#
Java | 365 lines | 223 code | 59 blank | 83 comment | 24 complexity | 9b9b94a7abdb06a912cda104034b7dbb 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.LinkedHashMap;
  22. import java.util.List;
  23. import java.util.Map;
  24. /**
  25. * Join operator Descriptor implementation.
  26. *
  27. */
  28. @Explain(displayName = "Join Operator")
  29. public class JoinDesc implements Serializable {
  30. private static final long serialVersionUID = 1L;
  31. public static final int INNER_JOIN = 0;
  32. public static final int LEFT_OUTER_JOIN = 1;
  33. public static final int RIGHT_OUTER_JOIN = 2;
  34. public static final int FULL_OUTER_JOIN = 3;
  35. public static final int UNIQUE_JOIN = 4;
  36. public static final int LEFT_SEMI_JOIN = 5;
  37. // used to handle skew join
  38. private boolean handleSkewJoin = false;
  39. private int skewKeyDefinition = -1;
  40. private Map<Byte, String> bigKeysDirMap;
  41. private Map<Byte, Map<Byte, String>> smallKeysDirMap;
  42. private Map<Byte, TableDesc> skewKeysValuesTables;
  43. // alias to key mapping
  44. private Map<Byte, List<ExprNodeDesc>> exprs;
  45. // alias to filter mapping
  46. private Map<Byte, List<ExprNodeDesc>> filters;
  47. // used for create joinOutputObjectInspector
  48. protected List<String> outputColumnNames;
  49. // key:column output name, value:tag
  50. private transient Map<String, Byte> reversedExprs;
  51. // No outer join involved
  52. protected boolean noOuterJoin;
  53. protected JoinCondDesc[] conds;
  54. protected Byte[] tagOrder;
  55. private TableDesc keyTableDesc;
  56. public JoinDesc() {
  57. }
  58. public JoinDesc(final Map<Byte, List<ExprNodeDesc>> exprs,
  59. List<String> outputColumnNames, final boolean noOuterJoin,
  60. final JoinCondDesc[] conds, final Map<Byte, List<ExprNodeDesc>> filters) {
  61. this.exprs = exprs;
  62. this.outputColumnNames = outputColumnNames;
  63. this.noOuterJoin = noOuterJoin;
  64. this.conds = conds;
  65. this.filters = filters;
  66. tagOrder = new Byte[exprs.size()];
  67. for (int i = 0; i < tagOrder.length; i++) {
  68. tagOrder[i] = (byte) i;
  69. }
  70. }
  71. public JoinDesc(final Map<Byte, List<ExprNodeDesc>> exprs,
  72. List<String> outputColumnNames, final boolean noOuterJoin,
  73. final JoinCondDesc[] conds) {
  74. this(exprs, outputColumnNames, noOuterJoin, conds, null);
  75. }
  76. public JoinDesc(final Map<Byte, List<ExprNodeDesc>> exprs,
  77. List<String> outputColumnNames) {
  78. this(exprs, outputColumnNames, true, null);
  79. }
  80. public JoinDesc(final Map<Byte, List<ExprNodeDesc>> exprs,
  81. List<String> outputColumnNames, final JoinCondDesc[] conds) {
  82. this(exprs, outputColumnNames, true, conds, null);
  83. }
  84. public JoinDesc(JoinDesc clone) {
  85. this.bigKeysDirMap = clone.bigKeysDirMap;
  86. this.conds = clone.conds;
  87. this.exprs = clone.exprs;
  88. this.handleSkewJoin = clone.handleSkewJoin;
  89. this.keyTableDesc = clone.keyTableDesc;
  90. this.noOuterJoin = clone.noOuterJoin;
  91. this.outputColumnNames = clone.outputColumnNames;
  92. this.reversedExprs = clone.reversedExprs;
  93. this.skewKeyDefinition = clone.skewKeyDefinition;
  94. this.skewKeysValuesTables = clone.skewKeysValuesTables;
  95. this.smallKeysDirMap = clone.smallKeysDirMap;
  96. this.tagOrder = clone.tagOrder;
  97. this.filters = clone.filters;
  98. }
  99. public Map<Byte, List<ExprNodeDesc>> getExprs() {
  100. return exprs;
  101. }
  102. public Map<String, Byte> getReversedExprs() {
  103. return reversedExprs;
  104. }
  105. public void setReversedExprs(Map<String, Byte> reversedExprs) {
  106. this.reversedExprs = reversedExprs;
  107. }
  108. @Explain(displayName = "condition expressions")
  109. public Map<Byte, String> getExprsStringMap() {
  110. if (getExprs() == null) {
  111. return null;
  112. }
  113. LinkedHashMap<Byte, String> ret = new LinkedHashMap<Byte, String>();
  114. for (Map.Entry<Byte, List<ExprNodeDesc>> ent : getExprs().entrySet()) {
  115. StringBuilder sb = new StringBuilder();
  116. boolean first = true;
  117. if (ent.getValue() != null) {
  118. for (ExprNodeDesc expr : ent.getValue()) {
  119. if (!first) {
  120. sb.append(" ");
  121. }
  122. first = false;
  123. sb.append("{");
  124. sb.append(expr.getExprString());
  125. sb.append("}");
  126. }
  127. }
  128. ret.put(ent.getKey(), sb.toString());
  129. }
  130. return ret;
  131. }
  132. public void setExprs(final Map<Byte, List<ExprNodeDesc>> exprs) {
  133. this.exprs = exprs;
  134. }
  135. /**
  136. * Get the string representation of filters.
  137. *
  138. * Returns null if they are no filters.
  139. *
  140. * @return Map from alias to filters on the alias.
  141. */
  142. @Explain(displayName = "filter predicates")
  143. public Map<Byte, String> getFiltersStringMap() {
  144. if (getFilters() == null || getFilters().size() == 0) {
  145. return null;
  146. }
  147. LinkedHashMap<Byte, String> ret = new LinkedHashMap<Byte, String>();
  148. boolean filtersPresent = false;
  149. for (Map.Entry<Byte, List<ExprNodeDesc>> ent : getFilters().entrySet()) {
  150. StringBuilder sb = new StringBuilder();
  151. boolean first = true;
  152. if (ent.getValue() != null) {
  153. if (ent.getValue().size() != 0) {
  154. filtersPresent = true;
  155. }
  156. for (ExprNodeDesc expr : ent.getValue()) {
  157. if (!first) {
  158. sb.append(" ");
  159. }
  160. first = false;
  161. sb.append("{");
  162. sb.append(expr.getExprString());
  163. sb.append("}");
  164. }
  165. }
  166. ret.put(ent.getKey(), sb.toString());
  167. }
  168. if (filtersPresent) {
  169. return ret;
  170. } else {
  171. return null;
  172. }
  173. }
  174. public Map<Byte, List<ExprNodeDesc>> getFilters() {
  175. return filters;
  176. }
  177. public void setFilters(Map<Byte, List<ExprNodeDesc>> filters) {
  178. this.filters = filters;
  179. }
  180. @Explain(displayName = "outputColumnNames")
  181. public List<String> getOutputColumnNames() {
  182. return outputColumnNames;
  183. }
  184. public void setOutputColumnNames(
  185. List<String> outputColumnNames) {
  186. this.outputColumnNames = outputColumnNames;
  187. }
  188. public boolean getNoOuterJoin() {
  189. return noOuterJoin;
  190. }
  191. public void setNoOuterJoin(final boolean noOuterJoin) {
  192. this.noOuterJoin = noOuterJoin;
  193. }
  194. @Explain(displayName = "condition map")
  195. public List<JoinCondDesc> getCondsList() {
  196. if (conds == null) {
  197. return null;
  198. }
  199. ArrayList<JoinCondDesc> l = new ArrayList<JoinCondDesc>();
  200. for (JoinCondDesc cond : conds) {
  201. l.add(cond);
  202. }
  203. return l;
  204. }
  205. public JoinCondDesc[] getConds() {
  206. return conds;
  207. }
  208. public void setConds(final JoinCondDesc[] conds) {
  209. this.conds = conds;
  210. }
  211. /**
  212. * The order in which tables should be processed when joining.
  213. *
  214. * @return Array of tags
  215. */
  216. public Byte[] getTagOrder() {
  217. return tagOrder;
  218. }
  219. /**
  220. * The order in which tables should be processed when joining.
  221. *
  222. * @param tagOrder
  223. * Array of tags
  224. */
  225. public void setTagOrder(Byte[] tagOrder) {
  226. this.tagOrder = tagOrder;
  227. }
  228. @Explain(displayName = "handleSkewJoin")
  229. public boolean getHandleSkewJoin() {
  230. return handleSkewJoin;
  231. }
  232. /**
  233. * set to handle skew join in this join op.
  234. *
  235. * @param handleSkewJoin
  236. */
  237. public void setHandleSkewJoin(boolean handleSkewJoin) {
  238. this.handleSkewJoin = handleSkewJoin;
  239. }
  240. /**
  241. * @return mapping from tbl to dir for big keys.
  242. */
  243. public Map<Byte, String> getBigKeysDirMap() {
  244. return bigKeysDirMap;
  245. }
  246. /**
  247. * set the mapping from tbl to dir for big keys.
  248. *
  249. * @param bigKeysDirMap
  250. */
  251. public void setBigKeysDirMap(Map<Byte, String> bigKeysDirMap) {
  252. this.bigKeysDirMap = bigKeysDirMap;
  253. }
  254. /**
  255. * @return mapping from tbl to dir for small keys
  256. */
  257. public Map<Byte, Map<Byte, String>> getSmallKeysDirMap() {
  258. return smallKeysDirMap;
  259. }
  260. /**
  261. * set the mapping from tbl to dir for small keys.
  262. *
  263. * @param bigKeysDirMap
  264. */
  265. public void setSmallKeysDirMap(Map<Byte, Map<Byte, String>> smallKeysDirMap) {
  266. this.smallKeysDirMap = smallKeysDirMap;
  267. }
  268. /**
  269. * @return skew key definition. If we see a key's associated entries' number
  270. * is bigger than this, we will define this key as a skew key.
  271. */
  272. public int getSkewKeyDefinition() {
  273. return skewKeyDefinition;
  274. }
  275. /**
  276. * set skew key definition.
  277. *
  278. * @param skewKeyDefinition
  279. */
  280. public void setSkewKeyDefinition(int skewKeyDefinition) {
  281. this.skewKeyDefinition = skewKeyDefinition;
  282. }
  283. /**
  284. * @return the table desc for storing skew keys and their corresponding value;
  285. */
  286. public Map<Byte, TableDesc> getSkewKeysValuesTables() {
  287. return skewKeysValuesTables;
  288. }
  289. /**
  290. * @param skewKeysValuesTable
  291. * set the table desc for storing skew keys and their corresponding
  292. * value;
  293. */
  294. public void setSkewKeysValuesTables(Map<Byte, TableDesc> skewKeysValuesTables) {
  295. this.skewKeysValuesTables = skewKeysValuesTables;
  296. }
  297. public boolean isNoOuterJoin() {
  298. return noOuterJoin;
  299. }
  300. public void setKeyTableDesc(TableDesc keyTblDesc) {
  301. keyTableDesc = keyTblDesc;
  302. }
  303. public TableDesc getKeyTableDesc() {
  304. return keyTableDesc;
  305. }
  306. }