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