gpt4 book ai didi

hadoop - 在 mapreduce 中处理文件的子集

转载 作者:可可西里 更新时间:2023-11-01 15:15:51 26 4
gpt4 key购买 nike

我需要使用 mapreduce 处理一个巨大的文件,我需要离开让最终用户选择他们想要处理的记录数。

问题是没有任何有效的方法可以只处理文件的子集而不“映射”整个文件(25tb 文件)

有没有办法在特定数量的记录后停止映射并继续减少部分?

最佳答案

这个问题有一个非常简单优雅的解决方案:覆盖 org.apache.hadoop.mapreduce.Mapper 类的 run() 并且只执行 map() 直到你想要或只执行那些您需要/想要的记录。

请参阅以下内容:

public static class MapJob extends Mapper<LongWritable, Text, Text, Text> {

private Text outputKey = new Text();
private Text outputValue = new Text();
private int numberOfRecordsToProcess;

// read numberOfRecordsToProcess in setup method from the configuration values set in the driver class after getting input from user

@Override
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
// Do your map thing
}

@Override
public void run(Context context) throws IOException, InterruptedException {

setup(context);
int count = 0 ;
while (context.nextKeyValue()) {
if(count++<numberOfRecordsToProcess){ // check if enough records has been processed already
map(context.getCurrentKey(), context.getCurrentValue(), context);
}else{
break;
}
}
}

cleanup(context);
}

关于hadoop - 在 mapreduce 中处理文件的子集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22511299/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com