使用的是Hadoop2.7.1以及HBase0.98版本。分开做的测试都可以执行,但是当两者结合,运行到最后job.waitForCompletion(true)?0:1就一直没有响应,看日志文件也没有错误信息。现在想应该是配置文件需要适当的更改,但是不知道改哪里?
[mw_shl_code=actionscript3,true]
public static class Map extends Mapper<LongWritable,Text,Text,IntWritable>{
private IntWritable i = new IntWritable();
public void map(LongWritable key,Text value,Context context)
throws IOException,InterruptedException {
String s[] = value.toString().trim().split(" ");
for(String m : s){
context.write(new Text(m), i);
}
}
}
public static class Reduce extends TableReducer<Text, IntWritable, NullWritable>{
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException{
int sum = 0;
for(IntWritable i : values){
sum += i.get();
}
Put put = new Put(Bytes.toBytes(key.toString()));
put.add(Bytes.toBytes("content"), Bytes.toBytes("count"), Bytes.toBytes(String.valueOf(sum)));
context.write(NullWritable.get(), put);
}
}
public static void createHBaseTable(String tableName) throws IOException{
HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(tableName));
HColumnDescriptor col = new HColumnDescriptor("content");
htd.addFamily(col);
// Configuration config = new Configuration();
// HBaseAdmin admin = new HBaseAdmin(config);
HBaseAdmin admin = new HBaseAdmin(ExConfiguration.configuration);
if(admin.tableExists(tableName)){
System.out.println("table exists, trying recreate table!");
admin.disableTable(tableName);
admin.deleteTable(tableName);
}
System.out.println("create new table " + tableName);
admin.createTable(htd);
}
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException{
String tableName = "wordcount";
Configuration conf = new Configuration();
conf.set(TableOutputFormat.OUTPUT_TABLE, tableName);
createHBaseTable(tableName);
String input = args[0];
// Job job = new Job(conf, "WordCount table with " + input);
Job job = Job.getInstance(conf, "WordCount table with " + input);
job.setJarByClass(WordCountHBase.class);
job.setNumReduceTasks(3);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TableOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(input));
System.exit(job.waitForCompletion(true)?0:1);
}
[/mw_shl_code] |