gpt4 book ai didi

java - 在hadoop中序列化数组

转载 作者:行者123 更新时间:2023-12-02 20:46:21 25 4
gpt4 key购买 nike

我想序列化字符串数组“文本数据”,并将其从映射器发送到reducer

  public void map(LongWritable key, Text value, OutputCollector< IntWritable,Text > 
output, Reporter reporter) throws IOException {

Path pt=new Path("E:\\spambase.txt");
FileSystem fs = FileSystem.get(new Configuration());
BufferedReader textReader=new BufferedReader(new InputStreamReader(fs.open(pt)));


int numberOfLines = readLines( );
String[ ] textData = new String[numberOfLines];
int i;
for (i=0; i < numberOfLines; i++) {
textData[ i ] = textReader.readLine();
}
textReader.close();

最佳答案

您似乎对MapReduce流程的工作方式有一些误解。

理想情况下,映射器不应读取其内部的整个文件。

Job对象为给定的输入路径生成InputSplits的集合。
默认情况下,Hadoop读取路径中每个拆分的一行(输入可以是目录),也可以只读取给定文件。
每行一次以输入的Text value偏移量传递到 map 类的LongWritable key中。

目前尚不清楚您要输出的内容,但您正在寻找ArrayWritable类,并使用output.collect()将数据序列化到reducer。但是,您需要从IntWritable, Text修改映射器输出类型以使用output.collect(some_key, new ArrayWritable(textData))
值得指出的是,您使用的是不推荐使用的mapred库,而不是mapreduce库。该E:\\并非hdfs路径,而是本地文件系统。

关于java - 在hadoop中序列化数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47875393/

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