数据筛选

数据准备

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

转载于:https://www.cnblogs.com/LgyBean/p/5037081.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值