List of usage examples for org.apache.hadoop.mapreduce TaskAttemptContext getOutputKeyClass
public Class<?> getOutputKeyClass();
From source file:com.linkedin.cubert.io.rubix.RubixOutputFormat.java
License:Open Source License
@Override public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException { Configuration conf = context.getConfiguration(); String extension = RubixConstants.RUBIX_EXTENSION; CompressionCodec codec = null;/*from ww w. j a va2 s .com*/ boolean isCompressed = getCompressOutput(context); if (isCompressed) { Class<?> codecClass = getOutputCompressorClass(context, DefaultCodec.class); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); extension += codec.getDefaultExtension(); } Path file = getDefaultWorkFile(context, extension); FileSystem fs = file.getFileSystem(conf); FSDataOutputStream fileOut = fs.create(file, false); return new RubixRecordWriter<K, V>(conf, fileOut, context.getOutputKeyClass(), context.getOutputValueClass(), codec); }
From source file:com.linkedin.json.JsonSequenceFileOutputFormat.java
License:Apache License
@Override public RecordWriter<Object, Object> getRecordWriter(final TaskAttemptContext context) throws IOException, InterruptedException { // Shamelessly copy in hadoop code to allow us to set the metadata with our schema Configuration conf = context.getConfiguration(); CompressionCodec codec = null;/*from w w w . j ava 2 s .c o m*/ CompressionType compressionType = CompressionType.NONE; if (getCompressOutput(context)) { // find the kind of compression to do compressionType = SequenceFileOutputFormat.getOutputCompressionType(context); // find the right codec Class<?> codecClass = getOutputCompressorClass(context, DefaultCodec.class); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); } // get the path of the temporary output file Path file = getDefaultWorkFile(context, ""); FileSystem fs = file.getFileSystem(conf); final String keySchema = getSchema("output.key.schema", conf); final String valueSchema = getSchema("output.value.schema", conf); /* begin cheddar's stealing of jay's code */ SequenceFile.Metadata meta = new SequenceFile.Metadata(); meta.set(new Text("key.schema"), new Text(keySchema)); meta.set(new Text("value.schema"), new Text(valueSchema)); final SequenceFile.Writer out = SequenceFile.createWriter(fs, conf, file, context.getOutputKeyClass(), context.getOutputValueClass(), compressionType, codec, context, meta); /* end cheddar's stealing of jay's code */ final JsonTypeSerializer keySerializer = new JsonTypeSerializer(keySchema); final JsonTypeSerializer valueSerializer = new JsonTypeSerializer(valueSchema); return new RecordWriter<Object, Object>() { public void write(Object key, Object value) throws IOException { out.append(new BytesWritable(keySerializer.toBytes(key)), new BytesWritable(valueSerializer.toBytes(value))); context.progress(); } public void close(TaskAttemptContext context) throws IOException { out.close(); } }; }
From source file:com.skp.experiment.common.mapreduce.MapFileOutputFormat.java
License:Apache License
public RecordWriter<WritableComparable<?>, Writable> getRecordWriter(TaskAttemptContext context) throws IOException { Configuration conf = context.getConfiguration(); CompressionCodec codec = null;/* ww w .ja v a 2s. com*/ CompressionType compressionType = CompressionType.NONE; if (getCompressOutput(context)) { // find the kind of compression to do compressionType = SequenceFileOutputFormat.getOutputCompressionType(context); // find the right codec Class<?> codecClass = getOutputCompressorClass(context, DefaultCodec.class); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); } Path file = getDefaultWorkFile(context, ""); FileSystem fs = file.getFileSystem(conf); // ignore the progress parameter, since MapFile is local final MapFile.Writer out = new MapFile.Writer(conf, fs, file.toString(), context.getOutputKeyClass().asSubclass(WritableComparable.class), context.getOutputValueClass().asSubclass(Writable.class), compressionType, codec, context); return new RecordWriter<WritableComparable<?>, Writable>() { public void write(WritableComparable<?> key, Writable value) throws IOException { out.append(key, value); } public void close(TaskAttemptContext context) throws IOException { out.close(); } }; }
From source file:datafu.hourglass.avro.AvroKeyValueWithMetadataOutputFormat.java
License:Apache License
/** {@inheritDoc} */ @Override//from w w w . ja v a 2 s .c o m @SuppressWarnings("unchecked") public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) throws IOException { AvroDatumConverterFactory converterFactory = new AvroDatumConverterFactory(context.getConfiguration()); AvroDatumConverter<K, ?> keyConverter = converterFactory.create((Class<K>) context.getOutputKeyClass()); AvroDatumConverter<V, ?> valueConverter = converterFactory.create((Class<V>) context.getOutputValueClass()); return new AvroKeyValueWithMetadataRecordWriter<K, V>(keyConverter, valueConverter, getCompressionCodec(context), getAvroFileOutputStream(context), context.getConfiguration()); }
From source file:edu.arizona.cs.hadoop.fs.irods.output.HirodsMapFileOutputFormat.java
License:Apache License
@Override public RecordWriter<WritableComparable<?>, Writable> getRecordWriter(TaskAttemptContext context) throws IOException { Configuration conf = context.getConfiguration(); CompressionCodec codec = null;/*from w ww .j av a 2 s . c om*/ CompressionType compressionType = CompressionType.NONE; if (getCompressOutput(context)) { // find the kind of compression to do compressionType = HirodsSequenceFileOutputFormat.getOutputCompressionType(context); // find the right codec Class<?> codecClass = getOutputCompressorClass(context, DefaultCodec.class); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); } Path file = getDefaultWorkFile(context, ""); FileSystem fs = file.getFileSystem(conf); // ignore the progress parameter, since MapFile is local final MapFile.Writer out = new MapFile.Writer(conf, fs, file.toString(), context.getOutputKeyClass().asSubclass(WritableComparable.class), context.getOutputValueClass().asSubclass(Writable.class), compressionType, codec, context); return new RecordWriter<WritableComparable<?>, Writable>() { public void write(WritableComparable<?> key, Writable value) throws IOException { out.append(key, value); } public void close(TaskAttemptContext context) throws IOException { out.close(); } }; }
From source file:edu.arizona.cs.hadoop.fs.irods.output.HirodsSequenceFileOutputFormat.java
License:Apache License
@Override public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException { Configuration conf = context.getConfiguration(); CompressionCodec codec = null;// ww w. j a va 2 s. c o m CompressionType compressionType = CompressionType.NONE; if (getCompressOutput(context)) { // find the kind of compression to do compressionType = getOutputCompressionType(context); // find the right codec Class<?> codecClass = getOutputCompressorClass(context, DefaultCodec.class); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); } // get the path of the temporary output file Path file = getDefaultWorkFile(context, ""); FileSystem fs = file.getFileSystem(conf); final SequenceFile.Writer out = SequenceFile.createWriter(fs, conf, file, context.getOutputKeyClass(), context.getOutputValueClass(), compressionType, codec, context); return new RecordWriter<K, V>() { @Override public void write(K key, V value) throws IOException { out.append(key, value); } @Override public void close(TaskAttemptContext context) throws IOException { out.close(); } }; }
From source file:edu.purdue.cs.HSPGiST.HadoopClasses.LocalHSPGiSTOutputFormat.java
License:Apache License
public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException { final Writer out = getWriter(context, context.getOutputKeyClass(), context.getOutputValueClass()); return new RecordWriter<K, V>() { public void write(K key, V value) throws IOException { out.append(key, value);/*from ww w . j av a2s . c om*/ } public void close(TaskAttemptContext context) throws IOException { out.close(); } }; }
From source file:kogiri.common.hadoop.io.format.map.BloomMapFileOutputFormat.java
License:Apache License
@Override public RecordWriter<WritableComparable<?>, Writable> getRecordWriter(TaskAttemptContext context) throws IOException { Configuration conf = context.getConfiguration(); CompressionCodec codec = null;/* w ww .j a v a 2 s .c om*/ CompressionType compressionType = CompressionType.NONE; if (getCompressOutput(context)) { // find the kind of compression to do compressionType = SequenceFileOutputFormat.getOutputCompressionType(context); // find the right codec Class<?> codecClass = getOutputCompressorClass(context, DefaultCodec.class); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); } Path file = getDefaultWorkFile(context, ""); FileSystem fs = file.getFileSystem(conf); // ignore the progress parameter, since MapFile is local final BloomMapFile.Writer out = new BloomMapFile.Writer(conf, fs, file.toString(), context.getOutputKeyClass().asSubclass(WritableComparable.class), context.getOutputValueClass().asSubclass(Writable.class), compressionType, codec, context); return new RecordWriter<WritableComparable<?>, Writable>() { @Override public void write(WritableComparable<?> key, Writable value) throws IOException { out.append(key, value); } @Override public void close(TaskAttemptContext context) throws IOException { out.close(); } }; }
From source file:org.apache.avro.mapreduce.AvroKeyValueOutputFormat.java
License:Apache License
/** {@inheritDoc} */ @Override// w w w .j ava 2s. c o m @SuppressWarnings("unchecked") public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) throws IOException { Configuration conf = context.getConfiguration(); AvroDatumConverterFactory converterFactory = new AvroDatumConverterFactory(conf); AvroDatumConverter<K, ?> keyConverter = converterFactory.create((Class<K>) context.getOutputKeyClass()); AvroDatumConverter<V, ?> valueConverter = converterFactory.create((Class<V>) context.getOutputValueClass()); GenericData dataModel = AvroSerialization.createDataModel(conf); return new AvroKeyValueRecordWriter<K, V>(keyConverter, valueConverter, dataModel, getCompressionCodec(context), getAvroFileOutputStream(context)); }
From source file:org.apache.avro.mapreduce.AvroSequenceFileOutputFormat.java
License:Apache License
/** {@inheritDoc} */ @Override/* w w w .java 2 s . c om*/ public RecordWriter<K, V> getRecordWriter(TaskAttemptContext context) throws IOException, InterruptedException { Configuration conf = context.getConfiguration(); // Configure compression if requested. CompressionCodec codec = null; CompressionType compressionType = CompressionType.NONE; if (getCompressOutput(context)) { // Find the kind of compression to do. compressionType = getOutputCompressionType(conf); // Find the right codec. Class<?> codecClass = getOutputCompressorClass(context, DefaultCodec.class); codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); } // Get the path of the output file. Path outputFile = getDefaultWorkFile(context, ""); FileSystem fs = outputFile.getFileSystem(conf); // Configure the writer. AvroSequenceFile.Writer.Options options = new AvroSequenceFile.Writer.Options().withFileSystem(fs) .withConfiguration(conf).withOutputPath(outputFile).withKeyClass(context.getOutputKeyClass()) .withValueClass(context.getOutputValueClass()).withProgressable(context) .withCompressionType(compressionType).withCompressionCodec(codec); Schema keySchema = AvroJob.getOutputKeySchema(conf); if (null != keySchema) { options.withKeySchema(keySchema); } Schema valueSchema = AvroJob.getOutputValueSchema(conf); if (null != valueSchema) { options.withValueSchema(valueSchema); } final SequenceFile.Writer out = AvroSequenceFile.createWriter(options); return new RecordWriter<K, V>() { @Override public void write(K key, V value) throws IOException { out.append(key, value); } @Override public void close(TaskAttemptContext context) throws IOException { out.close(); } }; }