hadoop實(shí)現(xiàn)grep示例分享
hadoop做的一個(gè)簡(jiǎn)單grep程序,可從文檔中提取包含某些字符串的行
/*
* 一個(gè)簡(jiǎn)單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{
//通過(guò)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;
}
相關(guān)文章
SpringBoot如何配置獲取request中body的json格式參數(shù)
這篇文章主要介紹了SpringBoot如何配置獲取request中body的json格式參數(shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-06-06Java事務(wù)管理學(xué)習(xí)之Spring和Hibernate詳解
這篇文章主要給大家介紹了Java事務(wù)管理學(xué)習(xí)之Spring和Hibernate的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友們可以參考借鑒,下面來(lái)一起看看吧。2017-03-03Springboot自動(dòng)配置與@Configuration配置類(lèi)詳解
這篇文章主要介紹了SpringBoot中的@Configuration與自動(dòng)配置,在進(jìn)行項(xiàng)目編寫(xiě)前,我們還需要知道一個(gè)東西,就是SpringBoot對(duì)我們的SpringMVC還做了哪些配置,包括如何擴(kuò)展,如何定制,只有把這些都搞清楚了,我們?cè)谥笫褂貌艜?huì)更加得心應(yīng)手2022-07-07springboot項(xiàng)目中mapper.xml文件找不到的三種解決方案
這篇文章主要介紹了springboot項(xiàng)目中mapper.xml文件找不到的三種解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01Java HashMap實(shí)現(xiàn)原理分析(一)
這篇文章主要介紹了Java HashMap實(shí)現(xiàn)原理的分析,幫助大家更好的理解和使用Java,感興趣的朋友可以了解下2020-08-08Java Swing中的表格(JTable)和樹(shù)(JTree)組件使用實(shí)例
這篇文章主要介紹了Java Swing中的表格(JTable)和樹(shù)(JTree)組件使用實(shí)例,本文同時(shí)講解了表格和樹(shù)的基本概念、常用方法、代碼實(shí)例,需要的朋友可以參考下2014-10-10Classloader隔離技術(shù)在業(yè)務(wù)監(jiān)控中的應(yīng)用詳解
這篇文章主要為大家介紹了Classloader隔離技術(shù)在業(yè)務(wù)監(jiān)控中的應(yīng)用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08