hadoop新手-我正在尝试以块的形式读取我的HDFS文件,例如,一次读取100行,然后在映射器中使用apache OLSMultipleLinearRegression对数据运行回归。我使用这里显示的代码读取多行内容:http://bigdatacircus.com/2012/08/01/wordcount-with-custom-record-reader-of-textinputformat/
我的映射器定义为:
public void map(LongWritable key, Text value,Context context) throws java.io.IOException ,InterruptedException
{
String lines = value.toString();
String []lineArr = lines.split("\n");
int lcount = lineArr.length;
System.out.println(lcount); // prints out "1"
context.write(new Text(new Integer(lcount).toString()),new IntWritable(1));
}我的问题是: system.out.println的lcount==1是怎么来的?我的文件由"\n“分隔,并且我在记录读取器中设置了NLINESTOPROCESS =3。我的输入文件格式为:
y x1 x2 x3 x4 x5
y x1 x2 x3 x4 x5
y x1 x2 x3 x4 x5
...如果我一次只读一行,我就不能执行多重回归,因为回归API接受多个数据点……感谢您的帮助
发布于 2013-02-03 12:15:53
String.split()接受正则表达式作为参数。你得加倍逃脱。
String []lineArr = lines.split("\\n");https://stackoverflow.com/questions/14669282
复制相似问题