FileSystem fs = null;
try {
fs = FileSystem.get(conf);
} catch (IOException e) {
LOG.error("Could not retrieve FileSystem object to check for existing path", e);
throw new CrunchRuntimeException(e);
}
boolean exists = false;
try {
exists = fs.exists(path);
} catch (IOException e) {
LOG.error("Exception checking existence of path: " + path, e);
throw new CrunchRuntimeException(e);
}
if (exists) {
switch (strategy) {
case DEFAULT:
LOG.error("Path " + path + " already exists!");
throw new CrunchRuntimeException("Path already exists: " + path);
case OVERWRITE:
LOG.info("Removing data at existing path: " + path);
try {
fs.delete(path, true);
} catch (IOException e) {
LOG.error("Exception thrown removing data at path: " + path, e);
}
break;
case APPEND:
LOG.info("Adding output files to existing path: " + path);
break;
default:
throw new CrunchRuntimeException("Unknown WriteMode: " + strategy);
}
} else {
LOG.info("Will write output files to new path: " + path);
}
}