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