gpt4 book ai didi

hadoop - 在较早的帖子中进行了澄清(处理输入文件中的前N行)

转载 作者:行者123 更新时间:2023-12-02 21:49:45 24 4
gpt4 key购买 nike

我想创建一个仅处理输入文件中前k行的映射器。我碰到了这篇文章:

Hadoop-> Mapper->How can we read only Top N rows from each file from given input path?
它说覆盖如下的run方法:

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

int rows = 0;
while (context.nextKeyValue()) {
if (rows++ == 10) {
break;
}

map(context.getCurrentKey(), context.getCurrentValue(), context);
}

cleanup(context);
}

因此,我尝试了该解决方案,但编译器无法找到我试图导入org.apache.hadoop.mapreduce.Mapper。*的“Context”和“setup()”,但不起作用
也有人可以解释map()函数中的参数吗?

样例代码
public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, Text> 
{
@Override
public void run(Context context) throws IOException, InterruptedException //for reading the first k lines only
{
setup(context);

int k = 5;

int rows = 0;
while (context.nextKeyValue())
{
if (rows++ == k) break;
map(context.getCurrentKey(), context.getCurrentValue(), context);
}

cleanup(context);
}

}

最佳答案

您没有扩展Mapper类。

应该是这样的,例如:

MyMapper extends Mapper<Object, Text, Text, IntWritable>



在这里查看示例:
http://wiki.apache.org/hadoop/WordCount
http://hadoop.apache.org/docs/stable/api/src-html/org/apache/hadoop/mapreduce/lib/map/MultithreadedMapper.html(这也覆盖了运行部分)

关于hadoop - 在较早的帖子中进行了澄清(处理输入文件中的前N行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22088221/

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