国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 洪江市| 庄河市| 二连浩特市| 湖南省| 九江市| 莱州市| 商南县| 右玉县| 舞钢市| 雅安市| 壤塘县| 玉田县| 桃园市| 洛隆县| 喀喇沁旗| 探索| 阆中市| 海兴县| 宾阳县| 玉龙| 平果县| 蓬莱市| 黔东| 庐江县| 会泽县| 保山市| 饶平县| 嘉祥县| 梓潼县| 永川市| 平遥县| 同德县| 基隆市| 贺州市| 徐水县| 海安县| 金乡县| 中方县| 大竹县| 九龙坡区| 湘阴县|