zoukankan      html  css  js  c++  java
  • 数据筛选

    数据准备

    route_log

    Apr 23 11:49:54 hostapd: wlan0: STA 14:7d:c5:9e:fb:84

    Apr 23 11:49:52 hostapd: wlan0: STA 74:e5:0b:04:28:f2

    Apr 23 11:49:50 hostapd: wlan0: STA cc:af:78:cc:d5:5d

    Apr 23 11:49:44 hostapd: wlan0: STA cc:af:78:cc:d5:5d

    Apr 23 11:49:43 hostapd: wlan0: STA 14:7d:c5:9e:fb:84

    Apr 23 11:49:42 hostapd: wlan0: STA 74:e5:0b:04:28:f2

    将route_log上传到HDFS上,从route_log中筛选  : month day mac 

    代码编写

    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.conf.Configured;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.LongWritable;
    import org.apache.hadoop.io.NullWritable;
    import org.apache.hadoop.io.Text;
    import org.apache.hadoop.mapreduce.Job;
    import org.apache.hadoop.mapreduce.Mapper;
    import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
    import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
    import org.apache.hadoop.util.Tool;
    import org.apache.hadoop.util.ToolRunner;
    
    public class Route_filter extends Configured implements Tool {
    
    @Override
    public int run(String[] args) throws Exception {
    // TODO Auto-generated method stub
    Configuration conf = getConf();
    Job job = new Job(conf, "route_filter");
    job.setJarByClass(Route_filter.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(NullWritable.class);
    job.setMapperClass(RouteMap.class);
    FileInputFormat.addInputPath(job, new Path("/value/route_log"));
    FileOutputFormat.setOutputPath(job, new Path("/outvalue/outroute_log"));
    job.submit();
    return job.isSuccessful() ? 0 : 1;
    }
    
    public static void main(String[] args) throws Exception {
    ToolRunner.run(new Configuration(), new Route_filter(), null);
    }
    }
    
    class RouteMap extends Mapper<LongWritable, Text, Text, NullWritable> {
    private Text result = new Text();
    
    protected void map(LongWritable key, Text value, Context context)
    throws java.io.IOException, InterruptedException {
    String lineValue = value.toString();
    String[] lineSplit = lineValue.split(" ");
    String month = lineSplit[0];
    String day = lineSplit[1];
    String mac = lineSplit[6];
    result.set(month + " " + day + " " + mac);
    context.write(result, NullWritable.get());
    }
    }
    

      

    最终输出结果:

    Apr 23 14:7d:c5:9e:fb:84
    Apr 23 14:7d:c5:9e:fb:84
    Apr 23 74:e5:0b:04:28:f2
    Apr 23 74:e5:0b:04:28:f2
    Apr 23 cc:af:78:cc:d5:5d
    Apr 23 cc:af:78:cc:d5:5d

  • 相关阅读:
    轻松实现WCF服务的构造函数依赖注入
    终于找到在Visual Studio 2010中进行“项目重命名”的有效工具
    让Entity Framework不再私闯sys.databases
    AutoMapper使用笔记
    遭遇IE8下的JavaScript兼容问题
    WCF异步调用中客户端关闭带来的性能问题
    Chrome “False Start” 引起的 Error 7 (net::ERR_TIMED_OUT): The operation timed out
    实战ASP.NET访问共享文件夹(含详细操作步骤)
    Entity Framework 理清关系 基于外键关联的单向一对一关系
    在Firefox中通过JavaScript复制到剪贴板(Copy to Clipboard)
  • 原文地址:https://www.cnblogs.com/LgyBean/p/5037081.html
Copyright © 2011-2022 走看看