PageRenderTime 47ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/src/java/org/apache/hcatalog/mapreduce/HCatTableInfo.java

#
Java | 247 lines | 102 code | 33 blank | 112 comment | 8 complexity | 4d70ad7f8c4574aca2f089b3a7b39364 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.hcatalog.mapreduce;
  19. import java.io.Serializable;
  20. import java.util.Map;
  21. import org.apache.hadoop.hive.metastore.MetaStoreUtils;
  22. /**
  23. *
  24. * HCatTableInfo - class to communicate table information to {@link HowlInputFormat}
  25. * and {@link HowlOutputFormat}
  26. *
  27. */
  28. public class HCatTableInfo implements Serializable {
  29. private static final long serialVersionUID = 1L;
  30. public enum TableInfoType {
  31. INPUT_INFO,
  32. OUTPUT_INFO
  33. };
  34. private final TableInfoType tableInfoType;
  35. /** The Metadata server uri */
  36. private final String serverUri;
  37. /** If the howl server is configured to work with hadoop security, this
  38. * variable will hold the principal name of the server - this will be used
  39. * in the authentication to the howl server using kerberos
  40. */
  41. private final String serverKerberosPrincipal;
  42. /** The db and table names */
  43. private final String dbName;
  44. private final String tableName;
  45. /** The partition filter */
  46. private String filter;
  47. /** The partition predicates to filter on, an arbitrary AND/OR filter, if used to input from*/
  48. private final String partitionPredicates;
  49. /** The information about the partitions matching the specified query */
  50. private JobInfo jobInfo;
  51. /** The partition values to publish to, if used for output*/
  52. private Map<String, String> partitionValues;
  53. /**
  54. * Initializes a new HCatTableInfo instance to be used with {@link HowlInputFormat}
  55. * for reading data from a table.
  56. * @param serverUri the Metadata server uri
  57. * @param serverKerberosPrincipal If the howl server is configured to
  58. * work with hadoop security, the kerberos principal name of the server - else null
  59. * The principal name should be of the form:
  60. * <servicename>/_HOST@<realm> like "howl/_HOST@myrealm.com"
  61. * The special string _HOST will be replaced automatically with the correct host name
  62. * @param dbName the db name
  63. * @param tableName the table name
  64. */
  65. public static HCatTableInfo getInputTableInfo(String serverUri,
  66. String serverKerberosPrincipal,
  67. String dbName,
  68. String tableName) {
  69. return new HCatTableInfo(serverUri, serverKerberosPrincipal, dbName, tableName, (String) null);
  70. }
  71. /**
  72. * Initializes a new HCatTableInfo instance to be used with {@link HowlInputFormat}
  73. * for reading data from a table.
  74. * @param serverUri the Metadata server uri
  75. * @param serverKerberosPrincipal If the howl server is configured to
  76. * work with hadoop security, the kerberos principal name of the server - else null
  77. * The principal name should be of the form:
  78. * <servicename>/_HOST@<realm> like "howl/_HOST@myrealm.com"
  79. * The special string _HOST will be replaced automatically with the correct host name
  80. * @param dbName the db name
  81. * @param tableName the table name
  82. * @param filter the partition filter
  83. */
  84. public static HCatTableInfo getInputTableInfo(String serverUri, String serverKerberosPrincipal, String dbName,
  85. String tableName, String filter) {
  86. return new HCatTableInfo(serverUri, serverKerberosPrincipal, dbName, tableName, filter);
  87. }
  88. private HCatTableInfo(String serverUri, String serverKerberosPrincipal,
  89. String dbName, String tableName, String filter) {
  90. this.serverUri = serverUri;
  91. this.serverKerberosPrincipal = serverKerberosPrincipal;
  92. this.dbName = (dbName == null) ? MetaStoreUtils.DEFAULT_DATABASE_NAME : dbName;
  93. this.tableName = tableName;
  94. this.partitionPredicates = null;
  95. this.partitionValues = null;
  96. this.tableInfoType = TableInfoType.INPUT_INFO;
  97. this.filter = filter;
  98. }
  99. /**
  100. * Initializes a new HCatTableInfo instance to be used with {@link HowlOutputFormat}
  101. * for writing data from a table.
  102. * @param serverUri the Metadata server uri
  103. * @param serverKerberosPrincipal If the howl server is configured to
  104. * work with hadoop security, the kerberos principal name of the server - else null
  105. * The principal name should be of the form:
  106. * <servicename>/_HOST@<realm> like "howl/_HOST@myrealm.com"
  107. * The special string _HOST will be replaced automatically with the correct host name
  108. * @param dbName the db name
  109. * @param tableName the table name
  110. * @param partitionValues The partition values to publish to, can be null or empty Map to
  111. * indicate write to a unpartitioned table. For partitioned tables, this map should
  112. * contain keys for all partition columns with corresponding values.
  113. */
  114. public static HCatTableInfo getOutputTableInfo(String serverUri,
  115. String serverKerberosPrincipal, String dbName, String tableName, Map<String, String> partitionValues){
  116. return new HCatTableInfo(serverUri, serverKerberosPrincipal, dbName,
  117. tableName, partitionValues);
  118. }
  119. private HCatTableInfo(String serverUri, String serverKerberosPrincipal,
  120. String dbName, String tableName, Map<String, String> partitionValues){
  121. this.serverUri = serverUri;
  122. this.serverKerberosPrincipal = serverKerberosPrincipal;
  123. this.dbName = (dbName == null) ? MetaStoreUtils.DEFAULT_DATABASE_NAME : dbName;
  124. this.tableName = tableName;
  125. this.partitionPredicates = null;
  126. this.partitionValues = partitionValues;
  127. this.tableInfoType = TableInfoType.OUTPUT_INFO;
  128. }
  129. /**
  130. * Gets the value of serverUri
  131. * @return the serverUri
  132. */
  133. public String getServerUri() {
  134. return serverUri;
  135. }
  136. /**
  137. * Gets the value of dbName
  138. * @return the dbName
  139. */
  140. public String getDatabaseName() {
  141. return dbName;
  142. }
  143. /**
  144. * Gets the value of tableName
  145. * @return the tableName
  146. */
  147. public String getTableName() {
  148. return tableName;
  149. }
  150. /**
  151. * Gets the value of partitionPredicates
  152. * @return the partitionPredicates
  153. */
  154. public String getPartitionPredicates() {
  155. return partitionPredicates;
  156. }
  157. /**
  158. * Gets the value of partitionValues
  159. * @return the partitionValues
  160. */
  161. public Map<String, String> getPartitionValues() {
  162. return partitionValues;
  163. }
  164. /**
  165. * Gets the value of job info
  166. * @return the job info
  167. */
  168. public JobInfo getJobInfo() {
  169. return jobInfo;
  170. }
  171. /**
  172. * Sets the value of jobInfo
  173. * @param jobInfo the jobInfo to set
  174. */
  175. public void setJobInfo(JobInfo jobInfo) {
  176. this.jobInfo = jobInfo;
  177. }
  178. public TableInfoType getTableType(){
  179. return this.tableInfoType;
  180. }
  181. /**
  182. * Sets the value of partitionValues
  183. * @param partitionValues the partition values to set
  184. */
  185. void setPartitionValues(Map<String, String> partitionValues) {
  186. this.partitionValues = partitionValues;
  187. }
  188. /**
  189. * Gets the value of partition filter
  190. * @return the filter string
  191. */
  192. public String getFilter() {
  193. return filter;
  194. }
  195. /**
  196. * @return the serverKerberosPrincipal
  197. */
  198. public String getServerKerberosPrincipal() {
  199. return serverKerberosPrincipal;
  200. }
  201. @Override
  202. public int hashCode() {
  203. int result = 17;
  204. result = 31*result + (serverUri == null ? 0 : serverUri.hashCode());
  205. result = 31*result + (serverKerberosPrincipal == null ? 0 : serverKerberosPrincipal.hashCode());
  206. result = 31*result + (dbName == null? 0 : dbName.hashCode());
  207. result = 31*result + tableName.hashCode();
  208. result = 31*result + (filter == null? 0 : filter.hashCode());
  209. result = 31*result + (partitionPredicates == null ? 0 : partitionPredicates.hashCode());
  210. result = 31*result + tableInfoType.ordinal();
  211. result = 31*result + (partitionValues == null ? 0 : partitionValues.hashCode());
  212. return result;
  213. }
  214. }