我的叢集環境 是串了兩台電腦 但我不確定是不是哪裡漏了什麼設定 我跑了一個MapReduce的範例後,只有一台電腦做 Map 想要來請教大家
以下是我跑得範例和資料庫的資料
資料庫: row1 column=hardware:inlat, timestamp=1269528709070, value=111 row2 column=hardware:inlat, timestamp=1269528719747, value=222 row3 column=hardware:inlat, timestamp=1269528728389, value=333 row4 column=hardware:inlat, timestamp=1269528748536, value=444 row5 column=hardware:inlat, timestamp=1269528755122, value=555
程式:
public class LoadHBase{
public static class HtMap extends TableMapper<Text, Text> { public void map(ImmutableBytesWritable key, Result value,Context context)throws IOException, InterruptedException { String res = Bytes.toString(value.getValue(Bytes.toBytes("hardware"),Bytes.toBytes("inlat"))); context.write(new Text(key.toString()), new Text(res)); } } public static class HtReduce extends Reducer<Text, Text, Text, Text> { public void reduce(Text key, Iterable<Text> values, Context context)throws IOException, InterruptedException { String str = new String(""); Text final_key = new Text(key); Text final_value = new Text(); for (Text tmp : values) { str += tmp.toString(); } final_value.set(str); context.write(final_key, final_value); } }
public LoadHBase() throws Exception { String input = "output2"; String tablename = "machine";
Configuration conf = new Configuration(); FileSystem fs = FileSystem.get(conf); fs.delete(new Path(input),true);
Job job = new Job(conf, " hbase data to hdfs"); job.setJarByClass(LoadHBase.class); job.setNumReduceTasks(1); Scan myScan = new Scan(); System.out.println("1234556767"); TableMapReduceUtil.initTableMapperJob(tablename, myScan, HtMap.class,Text.class, Text.class, job); job.setReducerClass(HtReduce.class); job.setOutputFormatClass(TextOutputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); FileOutputFormat.setOutputPath(job, new Path(input)); System.exit(job.waitForCompletion(true) ? 0 : 1); } }
|