Search in sources :

Example 6 with FileAlreadyExistsException

use of org.apache.hadoop.mapred.FileAlreadyExistsException in project hadoop by apache.

the class TeraOutputFormat method checkOutputSpecs.

@Override
public void checkOutputSpecs(JobContext job) throws InvalidJobConfException, IOException {
    // Ensure that the output directory is set
    Path outDir = getOutputPath(job);
    if (outDir == null) {
        throw new InvalidJobConfException("Output directory not set in JobConf.");
    }
    final Configuration jobConf = job.getConfiguration();
    // get delegation token for outDir's file system
    TokenCache.obtainTokensForNamenodes(job.getCredentials(), new Path[] { outDir }, jobConf);
    final FileSystem fs = outDir.getFileSystem(jobConf);
    try {
        // existing output dir is considered empty iff its only content is the
        // partition file.
        //
        final FileStatus[] outDirKids = fs.listStatus(outDir);
        boolean empty = false;
        if (outDirKids != null && outDirKids.length == 1) {
            final FileStatus st = outDirKids[0];
            final String fname = st.getPath().getName();
            empty = !st.isDirectory() && TeraInputFormat.PARTITION_FILENAME.equals(fname);
        }
        if (TeraSort.getUseSimplePartitioner(job) || !empty) {
            throw new FileAlreadyExistsException("Output directory " + outDir + " already exists");
        }
    } catch (FileNotFoundException ignored) {
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileAlreadyExistsException(org.apache.hadoop.mapred.FileAlreadyExistsException) FileStatus(org.apache.hadoop.fs.FileStatus) Configuration(org.apache.hadoop.conf.Configuration) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) InvalidJobConfException(org.apache.hadoop.mapred.InvalidJobConfException)

Aggregations

Path (org.apache.hadoop.fs.Path)6 FileAlreadyExistsException (org.apache.hadoop.mapred.FileAlreadyExistsException)6 FileSystem (org.apache.hadoop.fs.FileSystem)5 Configuration (org.apache.hadoop.conf.Configuration)3 PrintWriter (java.io.PrintWriter)2 Statement (java.sql.Statement)2 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)2 FileStatus (org.apache.hadoop.fs.FileStatus)2 InvalidJobConfException (org.apache.hadoop.mapred.InvalidJobConfException)2 Test (org.junit.Test)2 PartitionKey (co.cask.cdap.api.dataset.lib.PartitionKey)1 PartitionOutput (co.cask.cdap.api.dataset.lib.PartitionOutput)1 Partitioning (co.cask.cdap.api.dataset.lib.Partitioning)1 BasicMapReduceTaskContext (co.cask.cdap.internal.app.runtime.batch.BasicMapReduceTaskContext)1 MapReduceClassLoader (co.cask.cdap.internal.app.runtime.batch.MapReduceClassLoader)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)1 Job (org.apache.hadoop.mapreduce.Job)1