@Override
public void run() {
try {
Path p = this.path;
final FileSystem fs = p.getFileSystem();
// initialize output path.
if(this.numTasks == 1 && outDirMode == OutputDirectoryMode.PARONLY) {
// output is not written in parallel and should go to a single file
if(!fs.isDistributedFS()) {
// prepare local output path
// checks for write mode and removes existing files in case of OVERWRITE mode
if(!fs.initOutPathLocalFS(p, writeMode, false)) {
// output preparation failed! Cancel task.
throw new IOException("Output path could not be initialized. Canceling task.");
}
}
} else if(this.numTasks > 1 || outDirMode == OutputDirectoryMode.ALWAYS) {
// output is written in parallel into a directory or should always be written to a directory
if(!fs.isDistributedFS()) {
// File system is not distributed.
// We need to prepare the output path on each executing node.
if(!fs.initOutPathLocalFS(p, writeMode, true)) {
// output preparation failed! Cancel task.
throw new IOException("Output directory could not be created. Canceling task.");
}
}
// Suffix the path with the parallel instance index
p = p.suffix("/" + this.taskIndex);
} else {
// invalid number of subtasks (<= 0)
throw new IllegalArgumentException("Invalid number of subtasks. Canceling task.");
}