国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

hadoop實(shí)現(xiàn)grep示例分享

2019-11-26 15:34:22
字體:
供稿:網(wǎng)友

hadoop做的一個(gè)簡單grep程序,可從文檔中提取包含某些字符串的行

復(fù)制代碼 代碼如下:

/*
 * 一個(gè)簡單grep程序,可從文檔中提取包含莫些字符串的行
 */

public class grep extends Configured  implements Tool{

 public static  class grepMap extends Mapper<LongWritable, Text, Text,NullWritable>{

  public void map(LongWritable line,Text value,Context context) throws IOException, InterruptedException{
   //通過Configuration獲取參數(shù)
   String str = context.getConfiguration().get("grep");
   if(value.toString().contains(str)){
    context.write(value, NullWritable.get());
   }
  }
 }
 @Override
 public int run(String[] args) throws Exception {

  if(args.length!=3){
   System.out.println("ERROR");
   System.exit(1);
  }

  Configuration configuration = getConf();
  //傳遞參數(shù)
  configuration.set("grep", args[2]);
  Job job = new Job(configuration,"grep");

  job.setJarByClass(grep.class);
  job.setMapperClass(grepMap.class);
  job.setNumReduceTasks(0);

  job.setMapOutputKeyClass(Text.class);
  job.setOutputValueClass(NullWritable.class);

  Path in = new Path(args[0]);
  Path out = new Path(args[1]);
  FileSystem fileSystem = out.getFileSystem(configuration);
  if(fileSystem.exists(out))
   fileSystem.delete(out, true);

  FileInputFormat.addInputPath(job, in);
  FileOutputFormat.setOutputPath(job, out);

  System.exit(job.waitForCompletion(true)?0:1);
  return 0;
 }

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 日喀则市| 赤峰市| 马山县| 西平县| 界首市| 寻乌县| 赣州市| 宁蒗| 宁远县| 抚宁县| 丽江市| 萨嘎县| 康保县| 密云县| 凯里市| 西畴县| 高密市| 鄂托克旗| 南漳县| 宜章县| 钟祥市| 白水县| 南康市| 甘肃省| 泰兴市| 大兴区| 曲沃县| 永城市| 泸水县| 河曲县| 科技| 奉节县| 临桂县| 古田县| 沁水县| 民丰县| 洪洞县| 瓦房店市| 大化| 吉林市| 清原|