Java Code Examples for org.apache.hadoop.hive.metastore.api.Index#getIndexTableName()

The following examples show how to use org.apache.hadoop.hive.metastore.api.Index#getIndexTableName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dropIndex(String dbName, String tblName, String name, boolean deleteData) throws NoSuchObjectException,
      MetaException, TException {
    Index indexToDrop = getIndex(dbName, tblName, name);
    String indexTableName = indexToDrop.getIndexTableName();

    // Drop the index metadata
    org.apache.hadoop.hive.metastore.api.Table originTable = getTable(dbName, tblName);
    Map<String, String> parameters = originTable.getParameters();
    String indexTableObjectName = INDEX_PREFIX + name;
    if (!parameters.containsKey(indexTableObjectName)) {
        throw new NoSuchObjectException("can not find Index: " + name);
    }
    parameters.remove(indexTableObjectName);

    alter_table(dbName, tblName, originTable);

    // Now drop the data associated with the table used to hold the index data
    if(indexTableName != null && indexTableName.length() > 0) {
        dropTable(dbName, indexTableName, deleteData, true);
    }

    return true;
}
 
Example 2
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Override
public boolean dropIndex(String dbName, String tblName, String name, boolean deleteData) throws NoSuchObjectException,
      MetaException, TException {
  Index indexToDrop = getIndex(dbName, tblName, name);
  String indexTableName = indexToDrop.getIndexTableName();

  // Drop the index metadata
  org.apache.hadoop.hive.metastore.api.Table originTable = getTable(dbName, tblName);
  Map<String, String> parameters = originTable.getParameters();
  String indexTableObjectName = INDEX_PREFIX + name;
  if (!parameters.containsKey(indexTableObjectName)) {
    throw new NoSuchObjectException("can not find Index: " + name);
  }
  parameters.remove(indexTableObjectName);

  alter_table(dbName, tblName, originTable);

  // Now drop the data associated with the table used to hold the index data
  if(indexTableName != null && indexTableName.length() > 0) {
    dropTable(dbName, indexTableName, deleteData, true);
  }

  return true;
}
 
Example 3
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Override
public void createIndex(Index index, org.apache.hadoop.hive.metastore.api.Table indexTable) throws InvalidObjectException, MetaException, NoSuchObjectException,
      TException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException {
    boolean dirCreated = glueMetastoreClientDelegate.validateNewTableAndCreateDirectory(indexTable);
    boolean indexTableCreated = false;
    String dbName = index.getDbName();
    String indexTableName = index.getIndexTableName();
    String originTableName = index.getOrigTableName();
    Path indexTablePath = new Path(indexTable.getSd().getLocation());
    Table catalogIndexTableObject = HiveToCatalogConverter.convertIndexToTableObject(index);
    String indexTableObjectName = INDEX_PREFIX + index.getIndexName();

    try {
        org.apache.hadoop.hive.metastore.api.Table originTable = getTable(dbName, originTableName);
        Map<String, String> parameters = originTable.getParameters();
        if (parameters.containsKey(indexTableObjectName)){
            throw new org.apache.hadoop.hive.metastore.api.AlreadyExistsException("Index: " + index.getIndexName() + " already exist");
        }
        createTable(indexTable);
        indexTableCreated = true;
        originTable.getParameters().put(indexTableObjectName, catalogTableToString(catalogIndexTableObject));
        alter_table(dbName, originTableName, originTable);
    } catch (Exception e) {
        if (dirCreated){
            wh.deleteDir(indexTablePath, true);
        }
        if (indexTableCreated) {
            dropTable(dbName, indexTableName);
        }
        String msg = "Unable to create index: ";
        logger.error(msg, e);
        if (e instanceof TException) {
            throw e;
        } else {
            throw new MetaException(msg + e);
        }
    }
}
 
Example 4
Source File: AWSCatalogMetastoreClient.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 5 votes vote down vote up
@Override
public void createIndex(Index index, org.apache.hadoop.hive.metastore.api.Table indexTable) throws InvalidObjectException, MetaException, NoSuchObjectException,
      TException, org.apache.hadoop.hive.metastore.api.AlreadyExistsException {
  boolean dirCreated = glueMetastoreClientDelegate.validateNewTableAndCreateDirectory(indexTable);
  boolean indexTableCreated = false;
  String dbName = index.getDbName();
  String indexTableName = index.getIndexTableName();
  String originTableName = index.getOrigTableName();
  Path indexTablePath = new Path(indexTable.getSd().getLocation());
  Table catalogIndexTableObject = HiveToCatalogConverter.convertIndexToTableObject(index);
  String indexTableObjectName = INDEX_PREFIX + index.getIndexName();

  try {
    org.apache.hadoop.hive.metastore.api.Table originTable = getTable(dbName, originTableName);
    Map<String, String> parameters = originTable.getParameters();
    if (parameters.containsKey(indexTableObjectName)){
      throw new org.apache.hadoop.hive.metastore.api.AlreadyExistsException("Index: " + index.getIndexName() + " already exist");
    }
    createTable(indexTable);
    indexTableCreated = true;
    originTable.getParameters().put(indexTableObjectName, catalogTableToString(catalogIndexTableObject));
    alter_table(dbName, originTableName, originTable);
  } catch (Exception e) {
    if (dirCreated){
      wh.deleteDir(indexTablePath, true);
    }
    if (indexTableCreated) {
      dropTable(dbName, indexTableName);
    }
    String msg = "Unable to create index: ";
    logger.error(msg, e);
    if (e instanceof TException) {
      throw e;
    } else {
      throw new MetaException(msg + e);
    }
  }
}