zoukankan      html  css  js  c++  java
  • mapreduce课上实验

    今天我们课上做了一个关于数据清洗的实验,具体实验内容如下:

    1.数据清洗:按照进行数据清洗,并将清洗后的数据导入hive数据库中;

    2.数据处理:

    ·统计最受欢迎的视频/文章的Top10访问次数 (video/article

    ·按照地市统计最受欢迎的Top10课程 (ip

    ·按照流量统计最受欢迎的Top10课程 (traffic

    3.数据可视化:将统计结果倒入MySql数据库中,通过图形化展示的方式展现出来。

    本次主要是因为自己尚未掌握Hive的操作,之后得以请教本宿舍的大佬将hive 配置完成。

    代码如下:

     1     public static class Map extends Mapper<Object , Text , Text,Text >{ 
     2         private static Text ip=new Text();
     3 //        private static Text date=new Text();
     4 //        private static Text type=new Text();
     5 //        private static Text id=new Text(); 
     6         private static Text traffic=new Text(); 
     7         public void map(Object key,Text value,Context context) throws IOException, InterruptedException{ 
     8             String line=value.toString(); 
     9             String arr[]=line.split(","); 
    10             traffic.set(arr[0]); 
    11             String str[]=arr[1].split("[:]|[/]|[+]");
    12             String s=str[2]+"-"+"11"+"-"+str[0]+" "+str[3]+":"+str[4]+":"+str[5];
    13             ip.set(s+","+str[0]+","+arr[3]+","+arr[4]+","+arr[5]); 
    14             context.write(traffic,ip);
    15         } 
    16     } 
    17     public static class Reduce extends Reducer< IntWritable, Text, Text, Text>{ 
    18         public void reduce(Text key,Iterable<Text> values,Context context) throws IOException, InterruptedException{ 
    19             for(Text val:values){ 
    20                 context.write(key,val); 
    21             } 
    22         } 
    23     } 

    最后得到以下输出结果:

  • 相关阅读:
    Wolfram常用计算
    soapUI接口关联教程
    时间序列预测线上充值数据
    基于MySQL分析线上充值留存率
    更改用户资料需要完善脚本
    MySQL建立RFM模型
    Scrcpy使用入门
    虾皮Shopee社招面经分享(大数据开发方向),附内推方式
    MySQL Binlog 解析工具 Maxwell 详解
    MySQL Binlog 介绍
  • 原文地址:https://www.cnblogs.com/990906lhc/p/11854048.html
Copyright © 2011-2022 走看看