PageRenderTime 44ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/index/compact/IndexMetadataChangeTask.java

#
Java | 107 lines | 75 code | 15 blank | 17 comment | 11 complexity | 05804ba502148981bd665590eeb6d478 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.index.compact;
  19. import org.apache.hadoop.fs.FileStatus;
  20. import org.apache.hadoop.fs.FileSystem;
  21. import org.apache.hadoop.fs.Path;
  22. import org.apache.hadoop.hive.metastore.TableType;
  23. import org.apache.hadoop.hive.metastore.Warehouse;
  24. import org.apache.hadoop.hive.ql.Context;
  25. import org.apache.hadoop.hive.ql.DriverContext;
  26. import org.apache.hadoop.hive.ql.exec.Task;
  27. import org.apache.hadoop.hive.ql.index.HiveIndex;
  28. import org.apache.hadoop.hive.ql.metadata.Hive;
  29. import org.apache.hadoop.hive.ql.metadata.Partition;
  30. import org.apache.hadoop.hive.ql.metadata.Table;
  31. import org.apache.hadoop.hive.ql.plan.api.StageType;
  32. public class IndexMetadataChangeTask extends Task<IndexMetadataChangeWork>{
  33. private static final long serialVersionUID = 1L;
  34. @Override
  35. protected int execute(DriverContext driverContext) {
  36. try {
  37. Hive db = Hive.get(conf);
  38. IndexMetadataChangeWork work = this.getWork();
  39. String tblName = work.getIndexTbl();
  40. Table tbl = db.getTable(work.getDbName(), tblName);
  41. if (tbl == null ) {
  42. console.printError("Index table can not be null.");
  43. return 1;
  44. }
  45. if (!tbl.getTableType().equals(TableType.INDEX_TABLE)) {
  46. console.printError("Table " + tbl.getTableName() + " not specified.");
  47. return 1;
  48. }
  49. if (tbl.isPartitioned() && work.getPartSpec() == null) {
  50. console.printError("Index table is partitioned, but no partition specified.");
  51. return 1;
  52. }
  53. if (work.getPartSpec() != null) {
  54. Partition part = db.getPartition(tbl, work.getPartSpec(), false);
  55. if (part == null) {
  56. console.printError("Partition " +
  57. Warehouse.makePartName(work.getPartSpec(), false).toString()
  58. + " does not exist.");
  59. return 1;
  60. }
  61. Path url = new Path(part.getDataLocation().toString());
  62. FileSystem fs = url.getFileSystem(conf);
  63. FileStatus fstat = fs.getFileStatus(url);
  64. part.getParameters().put(HiveIndex.INDEX_TABLE_CREATETIME, Long.toString(fstat.getModificationTime()));
  65. db.alterPartition(tbl.getTableName(), part);
  66. } else {
  67. Path url = new Path(tbl.getDataLocation().toString());
  68. FileSystem fs = url.getFileSystem(conf);
  69. FileStatus fstat = fs.getFileStatus(url);
  70. tbl.getParameters().put(HiveIndex.INDEX_TABLE_CREATETIME, Long.toString(fstat.getModificationTime()));
  71. db.alterTable(tbl.getTableName(), tbl);
  72. }
  73. } catch (Exception e) {
  74. e.printStackTrace();
  75. console.printError("Error changing index table/partition metadata "
  76. + e.getMessage());
  77. return 1;
  78. }
  79. return 0;
  80. }
  81. @Override
  82. public String getName() {
  83. return "IndexMetadataChangeTask";
  84. }
  85. @Override
  86. public StageType getType() {
  87. return StageType.DDL;
  88. }
  89. @Override
  90. protected void localizeMRTmpFilesImpl(Context ctx) {
  91. }
  92. }