国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術(shù)|正則表達(dá)式|

服務(wù)器之家 - 編程語言 - JAVA教程 - Java執(zhí)行hadoop的基本操作實(shí)例代碼

Java執(zhí)行hadoop的基本操作實(shí)例代碼

2020-09-17 15:46Java之家 JAVA教程

這篇文章主要介紹了Java執(zhí)行hadoop的基本操作實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下

Java執(zhí)行hadoop的基本操作實(shí)例代碼

向HDFS上傳本地文件

 
?
1
 
2
3
4
5
6
7
8
9
public static void uploadInputFile(String localFile) throws IOException{
    Configuration conf = new Configuration();
    String hdfsPath = "hdfs://localhost:9000/";
    String hdfsInput = "hdfs://localhost:9000/user/hadoop/input";
    FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf);
    fs.copyFromLocalFile(new Path(localFile), new Path(hdfsInput));
    fs.close();
    System.out.println("已經(jīng)上傳文件到input文件夾啦");
  }

將output文件下載到本地

 
?
1
 
2
3
4
5
6
7
8
9
10
public static void getOutput(String outputfile) throws IOException{
    String remoteFile = "hdfs://localhost:9000/user/hadoop/output/part-r-00000";
    Path path = new Path(remoteFile);
    Configuration conf = new Configuration();
    String hdfsPath = "hdfs://localhost:9000/";
    FileSystem fs = FileSystem.get(URI.create(hdfsPath),conf);
    fs.copyToLocalFile(path, new Path(outputfile));
    System.out.println("已經(jīng)將輸出文件保留到本地文件");
    fs.close();
  }

刪除hdfs中的文件

 
?
1
 
2
3
4
5
6
7
8
9
10
public static void deleteOutput() throws IOException{
   Configuration conf = new Configuration();
   String hdfsOutput = "hdfs://localhost:9000/user/hadoop/output";
   String hdfsPath = "hdfs://localhost:9000/";
   Path path = new Path(hdfsOutput);
   FileSystem fs = FileSystem.get(URI.create(hdfsPath), conf);
   fs.deleteOnExit(path);
   fs.close();
   System.out.println("output文件已經(jīng)刪除");
 }

執(zhí)行mapReduce程序

創(chuàng)建Mapper類和Reducer類

 
?
1
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
public static class TokenizerMapper extends Mapper<Object, Text, Text, IntWritable>{
 
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();
 
    public void map(Object key, Text value, Context context) throws IOException, InterruptedException{
      String line = value.toString();
      line = line.replace("\\", "");
      String regex = "性別:</span><span class=\"pt_detail\">(.*?)</span>";
      Pattern pattern = Pattern.compile(regex);
      Matcher matcher = pattern.matcher(line);
      while(matcher.find()){
        String term = matcher.group(1);
        word.set(term);
        context.write(word, one);
      }
    }
  }
 
  public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable>{
 
    private IntWritable result = new IntWritable();
 
    public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException{
      int sum = 0;
      for(IntWritable val :values){
        sum+= val.get();
      }
      result.set(sum);
      context.write(key, result);
    }
  }

執(zhí)行mapReduce程序

 
?
1
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public static void runMapReduce(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if(otherArgs.length != 2){
      System.err.println("Usage: wordcount<in> <out>");
      System.exit(2);
    }
    Job job = new Job(conf, "word count");
    job.setJarByClass(WordCount.class);
    job.setMapperClass(TokenizerMapper.class);
    job.setCombinerClass(IntSumReducer.class);
    job.setReducerClass(IntSumReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(IntWritable.class);
    FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
    System.out.println("mapReduce 執(zhí)行完畢!");
    System.exit(job.waitForCompletion(true)?0:1);
 
  }

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

原文鏈接:http://blog.csdn.net/qq_30843221/article/details/54429792

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25
主站蜘蛛池模板: 色二区 | 久久精视频 | 黄色一级毛片在线观看 | 五月婷婷在线视频 | 91精品国产91久久综合 | 中文在线中文a | 久久国产视频精品 | 99久久毛片免费观看 | 91免费在线 | 久草精品在线 | 欧美中文字幕在线 | 少妇精品视频在线观看 | 国产97色在线 | 亚洲 | 日本黄色激情片 | 天堂99x99es久久精品免费 | 久久久久久久久久久国产 | 色性av| 一区二区三区视频 | 精品久久久久久亚洲综合网 | 97久久久| 日日操夜夜操免费视频 | 在线中文字幕第一页 | 久久久精品一区二区三区 | 成人免费视频网址 | 日韩国产在线观看 | 免费黄色在线观看 | 欧美精品1区2区3区 日本电影中文字幕 | 成人免费视频在线观看 | 欧美精品久久久久 | a毛片| 亚洲精品一区二区三区在线 | 99久久成人 | 99热在线播放 | 国产精品极品美女在线观看免费 | 亚洲五码中文字幕 | 一区二区三区视频 | 免费观看一区二区三区毛片 | 久久久久亚洲美女啪啪 | 日韩在线视频一区 | 日本久久综合 | 成人欧美一区二区三区视频xxx |