public class Test extends Mapper<LongWritable, Text, LongWritable, Text> {
private Random r = new Random();
@Override
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
if (r.nextInt(10) == 0) {
context.write(key, value);
}
}
}
2条答案
按热度按时间bkkx9g8r1#
如果你想接近10%,你可以使用随机。下面是mapper的一个示例:
d8tt03nd2#
使用以下java代码随机选择10%:
并使用这个bash脚本来运行它
例如,如果我们命名脚本
random_sample.sh
,从文件夹中选择10%/example/
,只需运行