PageRenderTime 50ms CodeModel.GetById 13ms app.highlight 31ms RepoModel.GetById 2ms app.codeStats 0ms

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

#
Java | 539 lines | 262 code | 67 blank | 210 comment | 1 complexity | 5c8af31e483dce4bf76783759a99b530 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.List;
 25
 26import org.apache.hadoop.hive.metastore.api.FieldSchema;
 27import org.apache.hadoop.hive.metastore.api.Order;
 28import org.apache.hadoop.hive.ql.exec.Utilities;
 29
 30/**
 31 * AlterTableDesc.
 32 *
 33 */
 34@Explain(displayName = "Alter Table")
 35public class AlterTableDesc extends DDLDesc implements Serializable {
 36  private static final long serialVersionUID = 1L;
 37
 38  /**
 39   * alterTableTypes.
 40   *
 41   */
 42  public static enum AlterTableTypes {
 43    RENAME, ADDCOLS, REPLACECOLS, ADDPROPS, ADDSERDE, ADDSERDEPROPS,
 44    ADDFILEFORMAT, ADDCLUSTERSORTCOLUMN, RENAMECOLUMN, ADDPARTITION,
 45    TOUCH, ARCHIVE, UNARCHIVE, ALTERPROTECTMODE, ALTERPARTITIONPROTECTMODE, ALTERLOCATION,
 46  };
 47
 48  public static enum ProtectModeType {
 49    NO_DROP, OFFLINE, READ_ONLY
 50  };
 51
 52
 53  AlterTableTypes op;
 54  String oldName;
 55  String newName;
 56  ArrayList<FieldSchema> newCols;
 57  String serdeName;
 58  HashMap<String, String> props;
 59  String inputFormat;
 60  String outputFormat;
 61  String storageHandler;
 62  int numberBuckets;
 63  ArrayList<String> bucketColumns;
 64  ArrayList<Order> sortColumns;
 65
 66  String oldColName;
 67  String newColName;
 68  String newColType;
 69  String newColComment;
 70  boolean first;
 71  String afterCol;
 72  boolean expectView;
 73  HashMap<String, String> partSpec;
 74  private String newLocation;
 75  boolean protectModeEnable;
 76  ProtectModeType protectModeType;
 77
 78  public AlterTableDesc() {
 79  }
 80
 81  /**
 82   * @param tblName
 83   *          table name
 84   * @param oldColName
 85   *          old column name
 86   * @param newColName
 87   *          new column name
 88   * @param newComment
 89   * @param newType
 90   */
 91  public AlterTableDesc(String tblName, String oldColName, String newColName,
 92      String newType, String newComment, boolean first, String afterCol) {
 93    super();
 94    oldName = tblName;
 95    this.oldColName = oldColName;
 96    this.newColName = newColName;
 97    newColType = newType;
 98    newColComment = newComment;
 99    this.first = first;
100    this.afterCol = afterCol;
101    op = AlterTableTypes.RENAMECOLUMN;
102  }
103
104  /**
105   * @param oldName
106   *          old name of the table
107   * @param newName
108   *          new name of the table
109   */
110  public AlterTableDesc(String oldName, String newName) {
111    op = AlterTableTypes.RENAME;
112    this.oldName = oldName;
113    this.newName = newName;
114  }
115
116  /**
117   * @param name
118   *          name of the table
119   * @param newCols
120   *          new columns to be added
121   */
122  public AlterTableDesc(String name, List<FieldSchema> newCols,
123      AlterTableTypes alterType) {
124    op = alterType;
125    oldName = name;
126    this.newCols = new ArrayList<FieldSchema>(newCols);
127  }
128
129  /**
130   * @param alterType
131   *          type of alter op
132   */
133  public AlterTableDesc(AlterTableTypes alterType) {
134    this(alterType, false);
135  }
136
137  /**
138   * @param alterType
139   *          type of alter op
140   */
141  public AlterTableDesc(AlterTableTypes alterType, boolean expectView) {
142    op = alterType;
143    this.expectView = expectView;
144  }
145
146  /**
147   *
148   * @param name
149   *          name of the table
150   * @param inputFormat
151   *          new table input format
152   * @param outputFormat
153   *          new table output format
154   * @param partSpec 
155   */
156  public AlterTableDesc(String name, String inputFormat, String outputFormat,
157      String serdeName, String storageHandler, HashMap<String, String> partSpec) {
158    super();
159    op = AlterTableTypes.ADDFILEFORMAT;
160    oldName = name;
161    this.inputFormat = inputFormat;
162    this.outputFormat = outputFormat;
163    this.serdeName = serdeName;
164    this.storageHandler = storageHandler;
165    this.partSpec = partSpec;
166  }
167
168  public AlterTableDesc(String tableName, int numBuckets,
169      List<String> bucketCols, List<Order> sortCols) {
170    oldName = tableName;
171    op = AlterTableTypes.ADDCLUSTERSORTCOLUMN;
172    numberBuckets = numBuckets;
173    bucketColumns = new ArrayList<String>(bucketCols);
174    sortColumns = new ArrayList<Order>(sortCols);
175  }
176
177  public AlterTableDesc(String tableName, String newLocation,
178      HashMap<String, String> partSpec) {
179    op = AlterTableTypes.ALTERLOCATION;
180    this.oldName = tableName;
181    this.newLocation = newLocation;
182    this.partSpec = partSpec;
183  }
184
185  @Explain(displayName = "new columns")
186  public List<String> getNewColsString() {
187    return Utilities.getFieldSchemaString(getNewCols());
188  }
189
190  @Explain(displayName = "type")
191  public String getAlterTableTypeString() {
192    switch (op) {
193    case RENAME:
194      return "rename";
195    case ADDCOLS:
196      return "add columns";
197    case REPLACECOLS:
198      return "replace columns";
199    }
200
201    return "unknown";
202  }
203
204  /**
205   * @return the old name of the table
206   */
207  @Explain(displayName = "old name")
208  public String getOldName() {
209    return oldName;
210  }
211
212  /**
213   * @param oldName
214   *          the oldName to set
215   */
216  public void setOldName(String oldName) {
217    this.oldName = oldName;
218  }
219
220  /**
221   * @return the newName
222   */
223  @Explain(displayName = "new name")
224  public String getNewName() {
225    return newName;
226  }
227
228  /**
229   * @param newName
230   *          the newName to set
231   */
232  public void setNewName(String newName) {
233    this.newName = newName;
234  }
235
236  /**
237   * @return the op
238   */
239  public AlterTableTypes getOp() {
240    return op;
241  }
242
243  /**
244   * @param op
245   *          the op to set
246   */
247  public void setOp(AlterTableTypes op) {
248    this.op = op;
249  }
250
251  /**
252   * @return the newCols
253   */
254  public ArrayList<FieldSchema> getNewCols() {
255    return newCols;
256  }
257
258  /**
259   * @param newCols
260   *          the newCols to set
261   */
262  public void setNewCols(ArrayList<FieldSchema> newCols) {
263    this.newCols = newCols;
264  }
265
266  /**
267   * @return the serdeName
268   */
269  @Explain(displayName = "deserializer library")
270  public String getSerdeName() {
271    return serdeName;
272  }
273
274  /**
275   * @param serdeName
276   *          the serdeName to set
277   */
278  public void setSerdeName(String serdeName) {
279    this.serdeName = serdeName;
280  }
281
282  /**
283   * @return the props
284   */
285  @Explain(displayName = "properties")
286  public HashMap<String, String> getProps() {
287    return props;
288  }
289
290  /**
291   * @param props
292   *          the props to set
293   */
294  public void setProps(HashMap<String, String> props) {
295    this.props = props;
296  }
297
298  /**
299   * @return the input format
300   */
301  @Explain(displayName = "input format")
302  public String getInputFormat() {
303    return inputFormat;
304  }
305
306  /**
307   * @param inputFormat
308   *          the input format to set
309   */
310  public void setInputFormat(String inputFormat) {
311    this.inputFormat = inputFormat;
312  }
313
314  /**
315   * @return the output format
316   */
317  @Explain(displayName = "output format")
318  public String getOutputFormat() {
319    return outputFormat;
320  }
321
322  /**
323   * @param outputFormat
324   *          the output format to set
325   */
326  public void setOutputFormat(String outputFormat) {
327    this.outputFormat = outputFormat;
328  }
329
330  /**
331   * @return the storage handler
332   */
333  @Explain(displayName = "storage handler")
334  public String getStorageHandler() {
335    return storageHandler;
336  }
337
338  /**
339   * @param storageHandler
340   *          the storage handler to set
341   */
342  public void setStorageHandler(String storageHandler) {
343    this.storageHandler = storageHandler;
344  }
345
346  /**
347   * @return the number of buckets
348   */
349  public int getNumberBuckets() {
350    return numberBuckets;
351  }
352
353  /**
354   * @param numberBuckets
355   *          the number of buckets to set
356   */
357  public void setNumberBuckets(int numberBuckets) {
358    this.numberBuckets = numberBuckets;
359  }
360
361  /**
362   * @return the bucket columns
363   */
364  public ArrayList<String> getBucketColumns() {
365    return bucketColumns;
366  }
367
368  /**
369   * @param bucketColumns
370   *          the bucket columns to set
371   */
372  public void setBucketColumns(ArrayList<String> bucketColumns) {
373    this.bucketColumns = bucketColumns;
374  }
375
376  /**
377   * @return the sort columns
378   */
379  public ArrayList<Order> getSortColumns() {
380    return sortColumns;
381  }
382
383  /**
384   * @param sortColumns
385   *          the sort columns to set
386   */
387  public void setSortColumns(ArrayList<Order> sortColumns) {
388    this.sortColumns = sortColumns;
389  }
390
391  /**
392   * @return old column name
393   */
394  public String getOldColName() {
395    return oldColName;
396  }
397
398  /**
399   * @param oldColName
400   *          the old column name
401   */
402  public void setOldColName(String oldColName) {
403    this.oldColName = oldColName;
404  }
405
406  /**
407   * @return new column name
408   */
409  public String getNewColName() {
410    return newColName;
411  }
412
413  /**
414   * @param newColName
415   *          the new column name
416   */
417  public void setNewColName(String newColName) {
418    this.newColName = newColName;
419  }
420
421  /**
422   * @return new column type
423   */
424  public String getNewColType() {
425    return newColType;
426  }
427
428  /**
429   * @param newType
430   *          new column's type
431   */
432  public void setNewColType(String newType) {
433    newColType = newType;
434  }
435
436  /**
437   * @return new column's comment
438   */
439  public String getNewColComment() {
440    return newColComment;
441  }
442
443  /**
444   * @param newComment
445   *          new column's comment
446   */
447  public void setNewColComment(String newComment) {
448    newColComment = newComment;
449  }
450
451  /**
452   * @return if the column should be changed to position 0
453   */
454  public boolean getFirst() {
455    return first;
456  }
457
458  /**
459   * @param first
460   *          set the column to position 0
461   */
462  public void setFirst(boolean first) {
463    this.first = first;
464  }
465
466  /**
467   * @return the column's after position
468   */
469  public String getAfterCol() {
470    return afterCol;
471  }
472
473  /**
474   * @param afterCol
475   *          set the column's after position
476   */
477  public void setAfterCol(String afterCol) {
478    this.afterCol = afterCol;
479  }
480
481  /**
482   * @return whether to expect a view being altered
483   */
484  public boolean getExpectView() {
485    return expectView;
486  }
487
488  /**
489   * @param expectView
490   *          set whether to expect a view being altered
491   */
492  public void setExpectView(boolean expectView) {
493    this.expectView = expectView;
494  }
495
496  /**
497   * @return part specification
498   */
499  public HashMap<String, String> getPartSpec() {
500    return partSpec;
501  }
502
503  /**
504   * @param partSpec
505   */
506  public void setPartSpec(HashMap<String, String> partSpec) {
507    this.partSpec = partSpec;
508  }
509
510  /**
511   * @return new location
512   */
513  public String getNewLocation() {
514    return newLocation;
515  }
516
517  /**
518   * @param newLocation new location
519   */
520  public void setNewLocation(String newLocation) {
521    this.newLocation = newLocation;
522  }
523
524  public boolean isProtectModeEnable() {
525    return protectModeEnable;
526  }
527
528  public void setProtectModeEnable(boolean protectModeEnable) {
529    this.protectModeEnable = protectModeEnable;
530  }
531
532  public ProtectModeType getProtectModeType() {
533    return protectModeType;
534  }
535
536  public void setProtectModeType(ProtectModeType protectModeType) {
537    this.protectModeType = protectModeType;
538  }
539}