use of org.apache.crunch.io.PathTarget in project crunch by cloudera.
the class MemPipeline method write.
@Override
public void write(PCollection<?> collection, Target target) {
if (target instanceof PathTarget) {
Path path = ((PathTarget) target).getPath();
try {
FileSystem fs = FileSystem.get(conf);
FSDataOutputStream os = fs.create(new Path(path, "out"));
if (collection instanceof PTable) {
for (Object o : collection.materialize()) {
Pair p = (Pair) o;
os.writeBytes(p.first().toString());
os.writeBytes("\t");
os.writeBytes(p.second().toString());
os.writeBytes("\r\n");
}
} else {
for (Object o : collection.materialize()) {
os.writeBytes(o.toString() + "\r\n");
}
}
os.close();
} catch (IOException e) {
LOG.error("Exception writing target: " + target, e);
}
} else {
LOG.error("Target " + target + " is not a PathTarget instance");
}
}
Aggregations