Examples of AlterPartitionEvent


Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

      if (part_vals == null || part_vals.size() == 0) {
        try {
          oldPart = ms.getPartition(dbname, name, new_part.getValues());
          ms.alterPartition(dbname, name, new_part.getValues(), new_part);
          for (MetaStoreEventListener listener : listeners) {
            listener.onAlterPartition(new AlterPartitionEvent(oldPart, new_part, true, this));
          }
        } catch (InvalidObjectException e) {
          throw new InvalidOperationException("alter is not possible");
        } catch (NoSuchObjectException e){
          //old partition does not exist
          throw new InvalidOperationException("alter is not possible");
        }
        return;
      }
      //rename partition
      try {
        ms.openTransaction();
        try {
          oldPart = ms.getPartition(dbname, name, part_vals);
        } catch (NoSuchObjectException e) {
          // this means there is no existing partition
          throw new InvalidObjectException(
              "Unable to rename partition because old partition does not exist");
        }
        Partition check_part = null;
        try {
          check_part = ms.getPartition(dbname, name, new_part.getValues());
        } catch(NoSuchObjectException e) {
          // this means there is no existing partition
          check_part = null;
        }
        if (check_part != null) {
          throw new AlreadyExistsException("Partition already exists:" + dbname + "." + name + "." + new_part.getValues());
        }
        tbl = ms.getTable(dbname, name);
        if (tbl == null) {
          throw new InvalidObjectException(
              "Unable to rename partition because table or database do not exist");
        }
        try {
          destPath = new Path(wh.getTablePath(ms.getDatabase(dbname), name), Warehouse.makePartName(tbl.getPartitionKeys(),
            new_part.getValues()));
        } catch (NoSuchObjectException e) {
          LOG.debug(e);
          throw new InvalidOperationException(
              "Unable to change partition or table. Database " + dbname + " does not exist"
                  + " Check metastore logs for detailed stack." + e.getMessage());
        }
        if (destPath != null) {
          newPartLoc = destPath.toString();
          oldPartLoc = oldPart.getSd().getLocation();

          srcPath = new Path(oldPartLoc);

          LOG.info("srcPath:" + oldPartLoc);
          LOG.info("descPath:" + newPartLoc);
          srcFs = wh.getFs(srcPath);
          destFs = wh.getFs(destPath);
          // check that src and dest are on the same file system
          if (srcFs != destFs) {
            throw new InvalidOperationException("table new location " + destPath
                + " is on a different file system than the old location "
                + srcPath + ". This operation is not supported");
          }
          try {
            srcFs.exists(srcPath); // check that src exists and also checks
            if (newPartLoc.compareTo(oldPartLoc) != 0 && destFs.exists(destPath)) {
              throw new InvalidOperationException("New location for this table "
                  + tbl.getDbName() + "." + tbl.getTableName()
                  + " already exists : " + destPath);
            }
          } catch (IOException e) {
            Warehouse.closeFs(srcFs);
            Warehouse.closeFs(destFs);
            throw new InvalidOperationException("Unable to access new location "
                + destPath + " for partition " + tbl.getDbName() + "."
                + tbl.getTableName() + " " + new_part.getValues());
          }
          new_part.getSd().setLocation(newPartLoc);
          ms.alterPartition(dbname, name, part_vals, new_part);
        }

        success = ms.commitTransaction();
      } finally {
        if (!success) {
          ms.rollbackTransaction();
        }
        if (success && newPartLoc.compareTo(oldPartLoc) != 0) {
          //rename the data directory
          try{
            if (srcFs.exists(srcPath)) {
              //if destPath's parent path doesn't exist, we should mkdir it
              Path destParentPath = destPath.getParent();
              if (!wh.mkdirs(destParentPath)) {
                  throw new IOException("Unable to create path " + destParentPath);
              }
              srcFs.rename(srcPath, destPath);
              LOG.info("rename done!");
            }
          } catch (IOException e) {
            boolean revertMetaDataTransaction = false;
            try {
              ms.openTransaction();
              ms.alterPartition(dbname, name, new_part.getValues(), oldPart);
              revertMetaDataTransaction = ms.commitTransaction();
            } catch (Exception e1) {
              LOG.error("Reverting metadata opeation failed During HDFS operation failed", e1);
              if (!revertMetaDataTransaction) {
                ms.rollbackTransaction();
              }
            }
            throw new InvalidOperationException("Unable to access old location "
                + srcPath + " for partition " + tbl.getDbName() + "."
                + tbl.getTableName() + " " + part_vals);
          }
        }
        for (MetaStoreEventListener listener : listeners) {
          listener.onAlterPartition(new AlterPartitionEvent(oldPart, new_part, true, this));
        }
      }
    }
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

        }

        oldPart = alterHandler.alterPartition(getMS(), wh, db_name, tbl_name, part_vals, new_part);

        for (MetaStoreEventListener listener : listeners) {
          listener.onAlterPartition(new AlterPartitionEvent(oldPart, new_part, true, this));
        }
      } catch (InvalidObjectException e) {
        throw new InvalidOperationException(e.getMessage());
      } catch (AlreadyExistsException e) {
        throw new InvalidOperationException(e.getMessage());
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

        }

        oldPart = alterHandler.alterPartition(getMS(), wh, db_name, tbl_name, part_vals, new_part);

        for (MetaStoreEventListener listener : listeners) {
          AlterPartitionEvent alterPartitionEvent =
              new AlterPartitionEvent(oldPart, new_part, true, this);
          alterPartitionEvent.setEnvironmentContext(envContext);
          listener.onAlterPartition(alterPartitionEvent);
        }
      } catch (InvalidObjectException e) {
        ex = e;
        throw new InvalidOperationException(e.getMessage());
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

          }
          else {
            throw new InvalidOperationException("failed to alterpartitions");
          }
          for (MetaStoreEventListener listener : listeners) {
            AlterPartitionEvent alterPartitionEvent =
                new AlterPartitionEvent(oldTmpPart, tmpPart, true, this);
            listener.onAlterPartition(alterPartitionEvent);
          }
        }
      } catch (InvalidObjectException e) {
        ex = e;
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

    //the partition did not change,
    // so the new partition should be similar to the original partition
    Partition origP = msc.getPartition(dbName, tblName, "b=2011");

    AlterPartitionEvent alterPartEvent = (AlterPartitionEvent)notifyList.get(listSize - 1);
    assert alterPartEvent.getStatus();
    validateAlterPartition(origP, origP, alterPartEvent.getOldPartition().getDbName(),
        alterPartEvent.getOldPartition().getTableName(),
        alterPartEvent.getOldPartition().getValues(), alterPartEvent.getNewPartition());


    validateAlterPartition(origP, origP, preAlterPartEvent.getDbName(),
        preAlterPartEvent.getTableName(), preAlterPartEvent.getNewPartition().getValues(),
        preAlterPartEvent.getNewPartition());
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

        }

        oldPart = alterHandler.alterPartition(getMS(), wh, db_name, tbl_name, part_vals, new_part);

        for (MetaStoreEventListener listener : listeners) {
          AlterPartitionEvent alterPartitionEvent =
              new AlterPartitionEvent(oldPart, new_part, true, this);
          alterPartitionEvent.setEnvironmentContext(envContext);
          listener.onAlterPartition(alterPartitionEvent);
        }
      } catch (InvalidObjectException e) {
        ex = e;
        throw new InvalidOperationException(e.getMessage());
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

          }
          else {
            throw new InvalidOperationException("failed to alterpartitions");
          }
          for (MetaStoreEventListener listener : listeners) {
            AlterPartitionEvent alterPartitionEvent =
                new AlterPartitionEvent(oldTmpPart, tmpPart, true, this);
            listener.onAlterPartition(alterPartitionEvent);
          }
        }
      } catch (InvalidObjectException e) {
        ex = e;
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

      if (part_vals == null || part_vals.size() == 0) {
        try {
          oldPart = ms.getPartition(dbname, name, new_part.getValues());
          ms.alterPartition(dbname, name, new_part.getValues(), new_part);
          for (MetaStoreEventListener listener : listeners) {
            listener.onAlterPartition(new AlterPartitionEvent(oldPart, new_part, true, this));
          }
        } catch (InvalidObjectException e) {
          throw new InvalidOperationException("alter is not possible");
        } catch (NoSuchObjectException e){
          //old partition does not exist
          throw new InvalidOperationException("alter is not possible");
        }
        return;
      }
      //rename partition
      try {
        ms.openTransaction();
        try {
          oldPart = ms.getPartition(dbname, name, part_vals);
        } catch (NoSuchObjectException e) {
          // this means there is no existing partition
          throw new InvalidObjectException(
              "Unable to rename partition because old partition does not exist");
        }
        Partition check_part = null;
        try {
          check_part = ms.getPartition(dbname, name, new_part.getValues());
        } catch(NoSuchObjectException e) {
          // this means there is no existing partition
          check_part = null;
        }
        if (check_part != null) {
          throw new AlreadyExistsException("Partition already exists:" + dbname + "." + name + "." + new_part.getValues());
        }
        tbl = ms.getTable(dbname, name);
        if (tbl == null) {
          throw new InvalidObjectException(
              "Unable to rename partition because table or database do not exist");
        }
        try {
          destPath = new Path(wh.getTablePath(ms.getDatabase(dbname), name), Warehouse.makePartName(tbl.getPartitionKeys(),
            new_part.getValues()));
        } catch (NoSuchObjectException e) {
          LOG.debug(e);
          throw new InvalidOperationException(
              "Unable to change partition or table. Database " + dbname + " does not exist"
                  + " Check metastore logs for detailed stack." + e.getMessage());
        }
        if (destPath != null) {
          newPartLoc = destPath.toString();
          oldPartLoc = oldPart.getSd().getLocation();

          srcPath = new Path(oldPartLoc);

          LOG.info("srcPath:" + oldPartLoc);
          LOG.info("descPath:" + newPartLoc);
          srcFs = wh.getFs(srcPath);
          destFs = wh.getFs(destPath);
          // check that src and dest are on the same file system
          if (srcFs != destFs) {
            throw new InvalidOperationException("table new location " + destPath
                + " is on a different file system than the old location "
                + srcPath + ". This operation is not supported");
          }
          try {
            srcFs.exists(srcPath); // check that src exists and also checks
            if (newPartLoc.compareTo(oldPartLoc) != 0 && destFs.exists(destPath)) {
              throw new InvalidOperationException("New location for this table "
                  + tbl.getDbName() + "." + tbl.getTableName()
                  + " already exists : " + destPath);
            }
          } catch (IOException e) {
            Warehouse.closeFs(srcFs);
            Warehouse.closeFs(destFs);
            throw new InvalidOperationException("Unable to access new location "
                + destPath + " for partition " + tbl.getDbName() + "."
                + tbl.getTableName() + " " + new_part.getValues());
          }
          new_part.getSd().setLocation(newPartLoc);
          ms.alterPartition(dbname, name, part_vals, new_part);
        }

        success = ms.commitTransaction();
      } finally {
        if (!success) {
          ms.rollbackTransaction();
        }
        if (success && newPartLoc.compareTo(oldPartLoc) != 0) {
          //rename the data directory
          try{
            if (srcFs.exists(srcPath)) {
              //if destPath's parent path doesn't exist, we should mkdir it
              Path destParentPath = destPath.getParent();
              if (!wh.mkdirs(destParentPath)) {
                  throw new IOException("Unable to create path " + destParentPath);
              }
              srcFs.rename(srcPath, destPath);
              LOG.info("rename done!");
            }
          } catch (IOException e) {
            boolean revertMetaDataTransaction = false;
            try {
              ms.openTransaction();
              ms.alterPartition(dbname, name, new_part.getValues(), oldPart);
              revertMetaDataTransaction = ms.commitTransaction();
            } catch (Exception e1) {
              LOG.error("Reverting metadata opeation failed During HDFS operation failed", e1);
              if (!revertMetaDataTransaction) {
                ms.rollbackTransaction();
              }
            }
            throw new InvalidOperationException("Unable to access old location "
                + srcPath + " for partition " + tbl.getDbName() + "."
                + tbl.getTableName() + " " + part_vals);
          }
        }
        for (MetaStoreEventListener listener : listeners) {
          listener.onAlterPartition(new AlterPartitionEvent(oldPart, new_part, true, this));
        }
      }
    }
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

        }

        oldPart = alterHandler.alterPartition(getMS(), wh, db_name, tbl_name, part_vals, new_part);

        for (MetaStoreEventListener listener : listeners) {
          AlterPartitionEvent alterPartitionEvent =
              new AlterPartitionEvent(oldPart, new_part, true, this);
          alterPartitionEvent.setEnvironmentContext(envContext);
          listener.onAlterPartition(alterPartitionEvent);
        }
      } catch (InvalidObjectException e) {
        ex = e;
        throw new InvalidOperationException(e.getMessage());
View Full Code Here

Examples of org.apache.hadoop.hive.metastore.events.AlterPartitionEvent

          }
          else {
            throw new InvalidOperationException("failed to alterpartitions");
          }
          for (MetaStoreEventListener listener : listeners) {
            AlterPartitionEvent alterPartitionEvent =
                new AlterPartitionEvent(oldTmpPart, tmpPart, true, this);
            listener.onAlterPartition(alterPartitionEvent);
          }
        }
      } catch (InvalidObjectException e) {
        ex = e;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.