gpt4 book ai didi

hadoop - Mapper 类如何将 SequenceFile 识别为 hadoop 中的输入文件?

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

在我的一个 MapReduce 任务中,我将 BytesWritable 重写为 KeyBytesWritable,并将 ByteWritable 重写为 ValueBytesWritable。然后我使用 SequenceFileOutputFormat 输出结果。

我的问题是当我开始下一个 MapReduce 任务时,我想使用这个 SequenceFile 作为输入文件。那么如何设置作业类,Mapper 类如何识别我之前覆盖的 SequenceFile 中的键和值?

我知道我可以使用 SequenceFile.Reader 来读取键和值。

Configuration config = new Configuration();
Path path = new Path(PATH_TO_YOUR_FILE);
SequenceFile.Reader reader = new SequenceFile.Reader(FileSystem.get(config), path, config);
WritableComparable key = (WritableComparable) reader.getKeyClass().newInstance();
Writable value = (Writable) reader.getValueClass().newInstance();
while (reader.next(key, value))

但是我不知道如何使用这个 Reader 将键和值作为参数传递给 Mapper 类。如何将 conf.setInputFormat 设置为 SequenceFileInputFormat,然后让 Mapper 获取键和值?

谢谢

最佳答案

您不需要手动读取序列文件。只需设置序列文件的输入格式类:

job.setInputFormatClass(SequenceFileInputFormat.class);

并将输入路径设置为包含您的序列文件的目录。

FileInputFormat.setInputPaths(<path to the dir containing your sequence files>);

您需要注意 Mapper 类的参数化类型的输入的 (Key,Value) 类型,以匹配序列文件中的 (key,value) 元组。

关于hadoop - Mapper 类如何将 SequenceFile 识别为 hadoop 中的输入文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15179456/

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