我想序列化一个stringarray“textdata”并将其从Map器发送到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();
1条答案
按热度按时间ui7jx7zq1#
您似乎对mapreduce进程的工作原理有一些误解。
理想情况下,Map程序不应该读取自身中的整个文件。
作业对象为给定的输入路径生成InputSplit集合。
默认情况下,hadoop读取路径中每个分割的一行(输入可以是一个目录),或者只读取给定文件的一行。
每行一次传递一个到
Text value
你的Map课LongWritable key
输入的偏移量。它不清楚你想要输出什么,但是你在寻找
ArrayWritable
类并使用output.collect()
. 但是,您需要从中修改Map器输出类型IntWritable, Text
使用output.collect(some_key, new ArrayWritable(textData))
值得指出的是,您使用的是不推荐的mapred
图书馆,而不是mapreduce
一个。然后呢E:\\
不是hdfs路径,而是本地文件系统。