我在hdfs中有一个文件夹,它有两个子文件夹,每个子文件夹有大约30个子文件夹,最后每个子文件夹包含xml文件.我想列出所有只提供主文件夹路径的xml文件.在本地我可以使用apache commons-io的 FileUtils.listFiles()来做到这一点.我试过这个
FileStatus[] status = fs.listStatus( new Path( args[ 0 ] ) );
Run Code Online (Sandbox Code Playgroud)
但它只列出了两个第一个子文件夹,并没有更进一步.在hadoop有没有办法做到这一点?
我认为他们指的是减速机,但在我的程序中我有
public static class MyMapper extends
Mapper< LongWritable, Text, Text, Text >
和
public static class MyReducer extends
Reducer< Text, Text, NullWritable, Text >
所以,如果我有
job.setOutputKeyClass( NullWritable.class );
job.setOutputValueClass( Text.class );
我得到以下例外
Type mismatch in key from map: expected org.apache.hadoop.io.NullWritable, recieved org.apache.hadoop.io.Text
但如果我有
job.setOutputKeyClass( Text.class );
没有问题.
我的代码是否有错误,或者这是因为NullWritable还是其他?
我也必须使用job.setInputFormatClass和job.setOutputFormatClass?因为没有它们我的程序运行正常.
以下是Mappers的代码,从HDFS读取文本文件对吗?如果它是:
InputStreamReader?如果是这样,如何在不关闭文件系统的情况下执行此操作?我的代码是:
Path pt=new Path("hdfs://pathTofile");
FileSystem fs = FileSystem.get(context.getConfiguration());
BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt)));
String line;
line=br.readLine();
while (line != null){
System.out.println(line);
Run Code Online (Sandbox Code Playgroud)