aws-glue-datacatalog-hive2-client/src/main/java/com/amazonaws/glue/catalog/metastore/AWSCatalogMetastoreClient.java [607:716]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  @Override
  public void createFunction(org.apache.hadoop.hive.metastore.api.Function function) throws InvalidObjectException, MetaException, TException {
    glueMetastoreClientDelegate.createFunction(function);
  }

  @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);
      }
    }
  }

  @Override
  public void createTable(org.apache.hadoop.hive.metastore.api.Table tbl) throws org.apache.hadoop.hive.metastore.api.AlreadyExistsException, InvalidObjectException, MetaException,
        NoSuchObjectException, TException {
    glueMetastoreClientDelegate.createTable(tbl);
  }

  @Override
  public boolean deletePartitionColumnStatistics(
      String dbName, String tableName, String partName, String colName
  ) throws NoSuchObjectException, MetaException, InvalidObjectException,
      TException, org.apache.hadoop.hive.metastore.api.InvalidInputException {
    return glueMetastoreClientDelegate.deletePartitionColumnStatistics(dbName, tableName, partName, colName);
  }

  @Override
  public boolean deleteTableColumnStatistics(
      String dbName, String tableName, String colName
  ) throws NoSuchObjectException, MetaException, InvalidObjectException,
      TException, org.apache.hadoop.hive.metastore.api.InvalidInputException {
    return glueMetastoreClientDelegate.deleteTableColumnStatistics(dbName, tableName, colName);
  }

  @Override
  public void dropFunction(String dbName, String functionName) throws MetaException, NoSuchObjectException,
        InvalidObjectException, org.apache.hadoop.hive.metastore.api.InvalidInputException, TException {
    glueMetastoreClientDelegate.dropFunction(dbName, functionName);
  }

  @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;
  }

  private void deleteParentRecursive(Path parent, int depth, boolean mustPurge) throws IOException, MetaException {
    if (depth > 0 && parent != null && wh.isWritable(parent) && wh.isEmpty(parent)) {
      wh.deleteDir(parent, true, mustPurge);
      deleteParentRecursive(parent.getParent(), depth - 1, mustPurge);
    }
  }

  // This logic is taken from HiveMetaStore#isMustPurge
  private boolean isMustPurge(org.apache.hadoop.hive.metastore.api.Table table, boolean ifPurge) {
    return (ifPurge || "true".equalsIgnoreCase(table.getParameters().get("auto.purge")));
  }

  @Override
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



aws-glue-datacatalog-spark-client/src/main/java/com/amazonaws/glue/catalog/metastore/AWSCatalogMetastoreClient.java [506:615]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  @Override
  public void createFunction(org.apache.hadoop.hive.metastore.api.Function function) throws InvalidObjectException, MetaException, TException {
    glueMetastoreClientDelegate.createFunction(function);
  }

  @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);
          }
      }
  }

  @Override
  public void createTable(org.apache.hadoop.hive.metastore.api.Table tbl) throws org.apache.hadoop.hive.metastore.api.AlreadyExistsException, InvalidObjectException, MetaException,
        NoSuchObjectException, TException {
    glueMetastoreClientDelegate.createTable(tbl);
  }

  @Override
  public boolean deletePartitionColumnStatistics(
      String dbName, String tableName, String partName, String colName
  ) throws NoSuchObjectException, MetaException, InvalidObjectException,
      TException, org.apache.hadoop.hive.metastore.api.InvalidInputException {
    return glueMetastoreClientDelegate.deletePartitionColumnStatistics(dbName, tableName, partName, colName);
  }

  @Override
  public boolean deleteTableColumnStatistics(
      String dbName, String tableName, String colName
  ) throws NoSuchObjectException, MetaException, InvalidObjectException,
      TException, org.apache.hadoop.hive.metastore.api.InvalidInputException {
    return glueMetastoreClientDelegate.deleteTableColumnStatistics(dbName, tableName, colName);
  }

  @Override
  public void dropFunction(String dbName, String functionName) throws MetaException, NoSuchObjectException,
        InvalidObjectException, org.apache.hadoop.hive.metastore.api.InvalidInputException, TException {
    glueMetastoreClientDelegate.dropFunction(dbName, functionName);
  }

  @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;
  }

  private void deleteParentRecursive(Path parent, int depth, boolean mustPurge) throws IOException, MetaException {
      if (depth > 0 && parent != null && wh.isWritable(parent) && wh.isEmpty(parent)) {
          wh.deleteDir(parent, true, mustPurge);
          deleteParentRecursive(parent.getParent(), depth - 1, mustPurge);
      }
  }

  // This logic is taken from HiveMetaStore#isMustPurge
  private boolean isMustPurge(org.apache.hadoop.hive.metastore.api.Table table, boolean ifPurge) {
      return (ifPurge || "true".equalsIgnoreCase(table.getParameters().get("auto.purge")));
  }

  @Override
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



