private Table validateTablePaths(Table table) throws MetaException {
    Database db = null;
    String tableLocation = table.isSetSd()? table.getSd().getLocation() : null;
    try {
      db = hmsHandler.get_database_core(table.getCatName(), table.getDbName());
    } catch (NoSuchObjectException e) {
      throw new MetaException("Database " + table.getDbName() + " for table " + table.getTableName() + " could not be found");
    }

    if (TableType.MANAGED_TABLE.name().equals(table.getTableType())) {
      if (db.getManagedLocationUri() != null) {
        if (tableLocation != null) {
          if (!FileUtils.isSubdirectory(db.getManagedLocationUri(), tableLocation)) {
            throw new MetaException(
                "Illegal location for managed table, it has to be within database's managed location");
          }
        } else {
          Path path = hmsHandler.getWh().getDefaultTablePath(db, table.getTableName(), false);
          table.getSd().setLocation(path.toString());
          return table;
        }
      } else {
        if (tableLocation != null) {
          Path tablePath = Path.getPathWithoutSchemeAndAuthority(new Path(tableLocation));
          if (!FileUtils.isSubdirectory(hmsHandler.getWh().getWhRoot().toString(), tableLocation)) {
            throw new MetaException(
                "A managed table's location should be located within managed warehouse root directory or within its database's "
                    + "managedLocationUri. Table " + table.getTableName() + "'s location is not valid:" + tableLocation
                    + ", managed warehouse:" + hmsHandler.getWh().getWhRoot());
          }
        } else {
          Path path = hmsHandler.getWh().getDefaultManagedTablePath(db, table.getTableName());
          table.getSd().setLocation(path.toString());
        }
      }
    } else { // EXTERNAL TABLE
      Path whRootPath = Path.getPathWithoutSchemeAndAuthority(hmsHandler.getWh().getWhRoot());
      Path dbLocation = Path.getPathWithoutSchemeAndAuthority(new Path(db.getLocationUri()));
      LOG.debug("ValidateTablePaths: whRoot={} dbLocation={} tableLocation={} ", whRootPath.toString(), dbLocation.toString(), tableLocation);
      if (tableLocation != null) {
        Path tablePath = Path.getPathWithoutSchemeAndAuthority(new Path(tableLocation));
        if (isTenantBasedStorage) {
          if (!FileUtils.isSubdirectory(dbLocation.toString(), tablePath.toString())) { // location outside dblocation
            throw new MetaException(
                "An external table's location should not be located outside the location specified on its database, table:"
                    + table.getTableName() + ",location:" + tablePath + ",Database location for external tables:" + dbLocation);
          }

          dbLocation = Path.getPathWithoutSchemeAndAuthority(hmsHandler.getWh().getDatabaseManagedPath(db));
          if (dbLocation != null && FileUtils.isSubdirectory(dbLocation.toString(), tablePath.toString())) {
            throw new MetaException(
                "An external table's location should not be located within managed warehouse root directory of its database, table:"
                    + table.getTableName() + ",location:" + tablePath + ",Database's managed warehouse:" + dbLocation);
          }
        } else {
          if (isExternalWarehouseSet() && FileUtils.isSubdirectory(whRootPath.toString(), tablePath.toString())) {
            throw new MetaException(
                "An external table's location should not be located within managed warehouse root directory, table:"
                    + table.getTableName() + ",location:" + tablePath + ",managed warehouse:" + whRootPath);
          }
          return table;
        }
      } else {
        Path tablePath = hmsHandler.getWh().getDefaultTablePath(db, table.getTableName(), true);
        table.getSd().setLocation(tablePath.toString());
      }
    }
    return table;
  }
Alter location of the database depending on whether or not the processor has ACID capabilities.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/MetastoreDefaultTransformer.java