婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > Hadoop計數(shù)器的應(yīng)用以及數(shù)據(jù)清洗

Hadoop計數(shù)器的應(yīng)用以及數(shù)據(jù)清洗

熱門標(biāo)簽:外呼系統(tǒng)不彈窗 申請400電話價格多少 安陽ai電銷機器人軟件 柳州市機器人外呼系統(tǒng)報價 云會外呼系統(tǒng) 廈門營銷外呼系統(tǒng)平臺 外呼系統(tǒng)的經(jīng)營范圍 智能電話機器人坐席 涪陵商都400電話開通辦理

數(shù)據(jù)清洗(ETL)

在運行核心業(yè)務(wù)MapReduce程序之前,往往要先對數(shù)據(jù)進行清洗,清理掉不符合用戶要求的數(shù)據(jù)。清理的過程往往只需要運行Mapper程序,不需要運行Reduce程序。

1.需求

去除日志中字段長度小于等于11的日志。

(1)輸入數(shù)據(jù)

web.log

(2)期望輸出數(shù)據(jù)

每行字段長度都大于11

2.需求分析

需要在Map階段對輸入的數(shù)據(jù)根據(jù)規(guī)則進行過濾清洗。

3.實現(xiàn)代碼

(1)編寫LogMapper類

package com.atguigu.mapreduce.weblog;
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class LogMapper extends Mapper<LongWritable, Text, Text, NullWritable>{
  Text k = new Text();
  @Override
  protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
   // 1 獲取1行數(shù)據(jù)
   String line = value.toString();
   // 2 解析日志
   boolean result = parseLog(line,context);
   // 3 日志不合法退出
   if (!result) {
     return;
   }
   // 4 設(shè)置key
   k.set(line);
   // 5 寫出數(shù)據(jù)
   context.write(k, NullWritable.get());
  }
  // 2 解析日志
  private boolean parseLog(String line, Context context) {
   // 1 截取
   String[] fields = line.split(" ");
   // 2 日志長度大于11的為合法
    if (fields.length > 11) {
     // 系統(tǒng)計數(shù)器
     context.getCounter("map", "true").increment(1);
     return true;
   }else {
     context.getCounter("map", "false").increment(1);
     return false;
   }
  }
}

(2)編寫LogDriver類

package com.atguigu.mapreduce.weblog;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class LogDriver {
  public static void main(String[] args) throws Exception {
// 輸入輸出路徑需要根據(jù)自己電腦上實際的輸入輸出路徑設(shè)置
    args = new String[] { "e:/input/inputlog", "e:/output1" };
   // 1 獲取job信息
   Configuration conf = new Configuration();
   Job job = Job.getInstance(conf);
   // 2 加載jar包
   job.setJarByClass(LogDriver.class);
   // 3 關(guān)聯(lián)map
   job.setMapperClass(LogMapper.class);
   // 4 設(shè)置最終輸出類型
   job.setOutputKeyClass(Text.class);
   job.setOutputValueClass(NullWritable.class);
   // 設(shè)置reducetask個數(shù)為0
   job.setNumReduceTasks(0);
   // 5 設(shè)置輸入和輸出路徑
   FileInputFormat.setInputPaths(job, new Path(args[0]));
   FileOutputFormat.setOutputPath(job, new Path(args[1]));
   // 6 提交
   job.waitForCompletion(true);
  }
}

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接

標(biāo)簽:撫順 蕪湖 晉城 巴中 福州 南充 孝感 綏化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Hadoop計數(shù)器的應(yīng)用以及數(shù)據(jù)清洗》,本文關(guān)鍵詞  Hadoop,計數(shù)器,的,應(yīng)用,以及,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Hadoop計數(shù)器的應(yīng)用以及數(shù)據(jù)清洗》相關(guān)的同類信息!
  • 本頁收集關(guān)于Hadoop計數(shù)器的應(yīng)用以及數(shù)據(jù)清洗的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 万源市| 梧州市| 镶黄旗| 无锡市| 乳山市| 松溪县| 于都县| 昆明市| 桂平市| 中卫市| 修文县| 广丰县| 宜兴市| 墨竹工卡县| 三明市| 正镶白旗| 婺源县| 从江县| 辽宁省| 电白县| 泽普县| 本溪市| 扎赉特旗| 新泰市| 藁城市| 美姑县| 潢川县| 黑水县| 宾川县| 洪江市| 紫金县| 阳江市| 西乌| 衡东县| 泗水县| 新安县| 龙陵县| 南部县| 淅川县| 潮州市| 乐业县|