2014-11-09 89 views
-1

training_set文件夹中输入文件,文件中像这样Hadoop的选择输入文件夹

mv_000000 
mv_000001 
mv_000002 
... 

指数存在是可以在movie_title.txt

movie_title.tx文件中找到的影片ID是这样的:

1,2003,Dinosaur Planet 
2,2004,Isle of Man TT 2004 Review 
3,1997,Character 
4,1994,Paula Abdul's Get Up & Dance 
5,2004,The Rise and Fall of ECW 
... 

第一列是特定电影名称的索引。

我在netplix大赛数据集上练习hadoop基础。 我假设我插入了特定的电影标题,如“生病”。 然后转到movie_titles.txt文件并搜索“sick”的moive title id。 最后设置输入路径电影标题ID。

例如,如果我的hadoop启动程序为:

hadoop jar ~ [input path] [output path] [moiveA name] 

比必须设置输入路径training_set/mv_movieAIndex

正如我所说,电影ID的信息存在于movie_title.txt

请给我一点提示,找出这个问题。

+0

你最终的目标是什么?我的意思是你正在发送邮件地图红色作为输出? – SMA 2014-11-09 06:19:44

回答

0

您的要求似乎与Hadoop根本没有关系。所有你需要的是id针对由hadoop jar命令的第三个参数指定的movieName的查找。下面的代码片段将完成这项工作:

private static Map<String, Integer> getMovieMappings(String filePath) 
     throws IOException { 
    Map<String, Integer> movieMap = new HashMap<String, Integer>(); 
    BufferedReader br = null; 
    try { 
     br = new BufferedReader(new FileReader(filePath)); 
     String line; 
     while ((line = br.readLine()) != null) { 
      String[] temp = line.split(","); 
      movieMap.put(temp[2].trim(), Integer.parseInt(temp[0].trim())); 
     } 
    } finally { 
     if (br != null) br.close(); 
    } 
    return movieMap; 
} 

现在司机,刚刚拿到地图,并相应设置inputPath:

Map<String, Integer> movieMap = getMovieMappings("/pathTo/movie_title.txt"); 
int movieId = movieMap.get(args[2]); 
System.out.println(String.format("mv_%06d", movieId)); 
FileInputFormat.addInputPath(job, 
           new Path("training_set", 
             String.format("mv_%06d", movieId))); 

可以将它帮助。