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