Example usage for org.apache.hadoop.mapreduce.lib.output TextOutputFormat TextOutputFormat

List of usage examples for org.apache.hadoop.mapreduce.lib.output TextOutputFormat TextOutputFormat

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.lib.output TextOutputFormat TextOutputFormat.

Prototype

TextOutputFormat

Source Link

Usage

From source file:org.apache.flink.test.hadoopcompatibility.mapreduce.WordCountMapreduceITCase.java

License:Apache License

private void internalRun(boolean isTestDeprecatedAPI) throws Exception {
    final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();

    DataSet<Tuple2<LongWritable, Text>> input;
    if (isTestDeprecatedAPI) {
        input = env.createInput(// w w  w.  j a  v  a  2 s.co  m
                HadoopInputs.readHadoopFile(new TextInputFormat(), LongWritable.class, Text.class, textPath));
    } else {
        input = env
                .createInput(readHadoopFile(new TextInputFormat(), LongWritable.class, Text.class, textPath));
    }

    DataSet<String> text = input.map(new MapFunction<Tuple2<LongWritable, Text>, String>() {
        @Override
        public String map(Tuple2<LongWritable, Text> value) throws Exception {
            return value.f1.toString();
        }
    });

    DataSet<Tuple2<String, Integer>> counts =
            // split up the lines in pairs (2-tuples) containing: (word,1)
            text.flatMap(new Tokenizer())
                    // group by the tuple field "0" and sum up tuple field "1"
                    .groupBy(0).sum(1);

    DataSet<Tuple2<Text, LongWritable>> words = counts
            .map(new MapFunction<Tuple2<String, Integer>, Tuple2<Text, LongWritable>>() {

                @Override
                public Tuple2<Text, LongWritable> map(Tuple2<String, Integer> value) throws Exception {
                    return new Tuple2<Text, LongWritable>(new Text(value.f0), new LongWritable(value.f1));
                }
            });

    // Set up Hadoop Output Format
    Job job = Job.getInstance();
    HadoopOutputFormat<Text, LongWritable> hadoopOutputFormat = new HadoopOutputFormat<Text, LongWritable>(
            new TextOutputFormat<Text, LongWritable>(), job);
    job.getConfiguration().set("mapred.textoutputformat.separator", " ");
    TextOutputFormat.setOutputPath(job, new Path(resultPath));

    // Output & Execute
    words.output(hadoopOutputFormat);
    env.execute("Hadoop Compat WordCount");
}

From source file:org.apache.pig.piggybank.storage.FixedWidthStorer.java

License:Apache License

@Override
public OutputFormat getOutputFormat() throws IOException {
    // Key is unused, Text is where the data is stored in
    return new TextOutputFormat<LongWritable, Text>();
}

From source file:pignlproc.storage.AbstractNTriplesStorer.java

License:Apache License

@SuppressWarnings("rawtypes")
@Override/*from  w ww  . j  a va 2 s.  c om*/
public OutputFormat getOutputFormat() {
    return new TextOutputFormat<WritableComparable, Text>();
}