【发布时间】:2016-12-28 06:06:04
【问题描述】:
我的 hbase 表如下所示:
key---------value
id1/bla value1
id1/blabla value2
id2/bla value3
id2/blabla value4
....
有数百万个以 id1 开头的键和数百万个以 id2 开头的键。
我想使用 mapReduce 从 hbase 读取数据,因为有很多以相同 Id 开头的键每个 id 一张地图还不够好。我更喜欢每个 ID 100 个映射器
我希望超过 1 个映射器将在已按 id 过滤的同一个scannerResult 上运行。
我阅读了 TableMapReduceUtil 并尝试了以下内容:
Configuration config = HBaseConfiguration.create();
Job job = new Job(config,"ExampleSummary");
job.setJarByClass(MySummaryJob.class); // class that contains mapper and reducer
Scan scan = new Scan();
scan.setCaching(500); // 1 is the default in Scan, which will be bad for MapReduce jobs
scan.setCacheBlocks(false); // don't set to true for MR jobs
// set other scan attrs
TableMapReduceUtil.initTableMapperJob(
sourceTable, // input table
scan, // Scan instance to control CF and attribute selection
MyMapper.class, // mapper class
Text.class, // mapper output key
IntWritable.class, // mapper output value
job);
使用看起来像这样的地图功能(它应该迭代扫描仪结果):
public static class MyMapper extends TableMapper<Text, IntWritable> {
private final IntWritable ONE = new IntWritable(1);
private Text text = new Text();
public void map(ImmutableBytesWritable row, Result value, Context context) throws IOException, InterruptedException {
text.set("123"); // we can only emit Writables...
context.write(text, ONE);
}
}
<br>
我的问题是:
- map 函数如何作为输入 Result 而不是 ResultScanner?我知道扫描的结果可以通过ResultScanner进行迭代,ResultScanner可以通过Result进行迭代。 ResultScanner 有 Result 的 list\array 不是吗?
- 如何在 map 函数中迭代扫描仪的结果?
- 如何控制此函数的拆分次数。如果它只打开 10 个映射器,而我想要 20 个,是否可以进行更改?
- 有没有最简单的方法可以实现我的目标?
【问题讨论】:
标签: java hadoop mapreduce hbase hdfs