Created
May 20, 2013 01:49
-
-
Save woodywang/5609958 to your computer and use it in GitHub Desktop.
An example for HFileInputFormat
This file contains 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 com.woodywang; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.hbase.KeyValue; | |
import org.apache.hadoop.hbase.io.ImmutableBytesWritable; | |
import org.apache.hadoop.hbase.util.Bytes; | |
import org.apache.hadoop.io.Text; | |
import org.apache.hadoop.mapreduce.Job; | |
import org.apache.hadoop.mapreduce.Mapper; | |
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; | |
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; | |
import java.io.IOException; | |
public class App { | |
private static class HFileMapper extends Mapper<ImmutableBytesWritable, KeyValue, Text, Text> { | |
public void map(ImmutableBytesWritable key, KeyValue keyValue, Context context) throws IOException, InterruptedException { | |
Text row = new Text(key.get()); | |
String column = Bytes.toString(keyValue.getQualifier()); | |
String value = Bytes.toString(keyValue.getValue()); | |
Text outputValue = new Text(column + ": " + value); | |
context.write(row, outputValue); | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
String path = "/Users/woody/hfile"; | |
Job job = new Job(); | |
job.setMapperClass(HFileMapper.class); | |
job.setMapOutputKeyClass(Text.class); | |
job.setMapOutputValueClass(Text.class); | |
job.setNumReduceTasks(0); | |
job.setInputFormatClass(HFileInputFormat.class); | |
FileInputFormat.addInputPath(job, new Path(path)); | |
FileOutputFormat.setOutputPath(job, new Path("/tmp/hfile")); | |
job.waitForCompletion(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment