Created
May 3, 2011 15:00
-
-
Save allen501pc/953484 to your computer and use it in GitHub Desktop.
SortByTemperatureUsingHashPartitioner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package SortData; | |
import java.io.IOException; | |
import org.apache.hadoop.conf.Configured; | |
import org.apache.hadoop.io.IntWritable; | |
import org.apache.hadoop.io.SequenceFile.CompressionType; | |
import org.apache.hadoop.io.compress.*; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.mapred.*; | |
import org.apache.hadoop.util.*; | |
// vv SortByTemperatureUsingHashPartitioner | |
public class SortByTemperatureUsingHashPartitioner extends Configured | |
implements Tool { | |
@Override | |
public int run(String[] args) throws IOException { | |
JobConf conf = new JobConf(getConf(), getClass()); | |
FileInputFormat.addInputPath(conf, new Path(args[0])); | |
FileOutputFormat.setOutputPath(conf, new Path(args[1])); | |
if (conf == null) { | |
return -1; | |
} | |
conf.setInputFormat(SequenceFileInputFormat.class); | |
conf.setOutputKeyClass(IntWritable.class); | |
conf.setOutputFormat(SequenceFileOutputFormat.class); | |
SequenceFileOutputFormat.setCompressOutput(conf, true); | |
SequenceFileOutputFormat.setOutputCompressorClass(conf, GzipCodec.class); | |
SequenceFileOutputFormat.setOutputCompressionType(conf, | |
CompressionType.BLOCK); | |
JobClient.runJob(conf); | |
return 0; | |
} | |
public static void main(String[] args) throws Exception { | |
int exitCode = ToolRunner.run(new SortByTemperatureUsingHashPartitioner(), | |
args); | |
System.exit(exitCode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment