Search in sources :

Example 1 with PTable

use of org.apache.crunch.PTable 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");
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PathTarget(org.apache.crunch.io.PathTarget) FileSystem(org.apache.hadoop.fs.FileSystem) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IOException(java.io.IOException) PTable(org.apache.crunch.PTable) Pair(org.apache.crunch.Pair)

Aggregations

IOException (java.io.IOException)1 PTable (org.apache.crunch.PTable)1 Pair (org.apache.crunch.Pair)1 PathTarget (org.apache.crunch.io.PathTarget)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1