【发布时间】:2015-04-18 00:49:16
【问题描述】:
我对 Hadoop 比较陌生。我使用这个link 在我的本地机器上设置了hadoop 0.20.2。使用了一个工作代码(在另一台机器上成功测试)并在我的机器上运行它。一切正常,没有错误,除了驱动程序类中的分隔符没有分隔。它假设向我发送输入块,但仍以每行为基础向我发送输入。
我的驱动程序类看起来像这样 -
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf = new Configuration();
conf.set("textinputformat.record.delimiter","\n\n\n");
Job job = new Job(conf);
job.setJobName("Aggregated occurence");
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setJarByClass(EntityCoOccurence.class);
job.setMapperClass(CoOccuringEntityMap.class);
job.setReducerClass(CoOccuringEntityCountReduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.submit();
}
我的输入文件由 3 行文本和 2 行空白组成。像这样 -
abc
def
ghi
abc
dfg
sas
pos
sdf
sfd
分隔符在我的大学 hadoop 集群中完美运行,但在我的本地计算机中不起作用。我打印出输入,发现尽管有分隔符,hadoop 还是将每一行作为输入发送给我。有什么想法吗?
编辑
我仔细研究了一下,发现 hadoop-0.20.2-core jar 的 recordReader 方法中的 TextInputFormat 类看起来像这样 -
@Override
public RecordReader<LongWritable, Text>
createRecordReader(InputSplit split,
TaskAttemptContext context) {
return new LineRecordReader();
}
应该是这样的 -
@Override
public RecordReader<LongWritable, Text>
createRecordReader(InputSplit split,
TaskAttemptContext context) {
// By default,textinputformat.record.delimiter = ‘/n’(Set in configuration file)
String delimiter = context.getConfiguration().get(
"textinputformat.record.delimiter");
byte[] recordDelimiterBytes = null;
if (null != delimiter)
recordDelimiterBytes = delimiter.getBytes();
return new LineRecordReader(recordDelimiterBytes);
}
但是,我受版本约束。有人可以提出建议吗?
【问题讨论】: