Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在使用Hadoop时,如何自定义FileInputFormat以在Java中读取文件的多行?_Java_Hadoop_Mapreduce - Fatal编程技术网

在使用Hadoop时,如何自定义FileInputFormat以在Java中读取文件的多行?

在使用Hadoop时,如何自定义FileInputFormat以在Java中读取文件的多行?,java,hadoop,mapreduce,Java,Hadoop,Mapreduce,我正在使用Java中的MapReduce框架,我想创建一种定制的文件输入格式。 假设我的文件格式如下: -------------- $-标志-$ 什么 我 真的 想要 $-标志-$ 和 另一个 部分 --------------- 在本例中,每个记录都被视为多行的数组 根据教程,我写了以下内容: public class CustomInputFormat extends FileInputFormat<Text, IdxValues> { public RecordRea

我正在使用Java中的MapReduce框架,我想创建一种定制的文件输入格式。
假设我的文件格式如下:
--------------
$-标志-$
什么

真的
想要
$-标志-$

另一个
部分
---------------
在本例中,每个记录都被视为多行的数组
根据教程,我写了以下内容:

public class CustomInputFormat extends FileInputFormat<Text, IdxValues> {
    public RecordReader<Text, IdxValues> getRecordReader(
            InputSplit input, JobConf job, Reporter report) throws IOException {

        report.setStatus(input.toString());
        return new CustomReader(job, (FileSplit)input);
    } 
}
公共类CustomInputFormat扩展了FileInputFormat{
公共记录阅读器getRecordReader(
InputSplit输入、JobConf作业、Reporter报告)引发IOException{
report.setStatus(input.toString());
返回新的CustomReader(作业,(文件拆分)输入);
} 
}

现在我想知道应该如何实现CustomReader类,将[我真正想要的]和[以及另一部分]分别作为两个数组读取?

我已经做了类似的事情。这里我用“$$$”作为分隔符(我将其作为配置参数传递给job)。您可以检查代码及其在同一项目上的具体实现。我自定义了RecordReader和InputFormat。

您的标记是字符还是表达式?@rVr它是一个由常量字符串包围的URI,例如,'$-C:/usr/john-$'。对于每个记录,都有一个唯一的URI。它应该用作分隔符。