zoukankan      html  css  js  c++  java
  • MongDB日志分析导入清洗导到Mysql

    今天做的是MongDB日志分析,今天成功将数据导入到hive并进行一系列的数据清洗,并导入到mysql,最终未完成可视化操作,计划明天完成,下面是要求部分:

    Result文件数据说明:

    Ip106.39.41.166,(城市)

    Date10/Nov/2016:00:01:02 +0800,(日期)

    Day10,(天数)

    Traffic: 54 ,(流量)

    Type: video,(类型:视频video或文章article

    Id: 8701(视频或者文章的id

    测试要求:

    1、 数据清洗:按照进行数据清洗,并将清洗后的数据导入MongDB数据库中

    两阶段数据清洗:

    1)第一阶段:把需要的信息从原始日志中提取出来

    ip:    199.30.25.88

    time:  10/Nov/2016:00:01:03 +0800

    traffic:  62

    文章: article/11325

    视频: video/3235

    2)第二阶段:根据提取出来的信息做精细化操作

    ip--->城市 cityIP

    date--> time:2016-11-10 00:01:03

    day: 10

    traffic:62

    type:article/video

    id:11325

    3MongDB数据库表结构:

    create table data(  ip string,  time string , day string, traffic bigint,

    type string, id   string )

    2、数据处理:

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

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

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

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

    下面是操作流程和步骤:

    创建result

    create table result (ip String,data String,day String,traffic String,type String,id String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    导入数据

    load data local inpath '/opt/software/result.txt' into table result;

    创建result1表用于初步筛选

    create table result1(ip String,data String,traffic String,type String,id String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    type="video"的数据导入result1

    insert into table result1(ip,data,traffic,type,id) (select ip,data,traffic,type,id from result where type="video");

    创建result2

    create table result2(ip String,data String,traffic String,type String,id String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    type="article"的数据导入表

    insert into table result2(ip,data,traffic,type,id) (select ip,data,traffic,type,id from result where type="article");

    清洗result1

    insert overwrite table result1 select ip as ip,sumbstring(data,8,length(data)-7) as data,traffic as traffic,type as type,id as id from result1;

    清洗result2

    insert overwrite table result2 select ip as ip,substring(data,8,length(data)-7) as data,traffic as traffic,type as type,id as id from result2;

    创建result3表用于进一步清洗

    create table result3 (ip String,data String,day String,traffic String,type String,id String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    result中数据导入result3

    insert into table result3(ip,data,day,traffic,type,id) (select ip,data,day,traffic,type,id from result where type="article"or type="video");

    清洗data数据

    insert overwrite table result3 select ip as ip,concat("2016-11-10 ",substring(data,11,length(data)-10)) as data,day as day,traffic as traffic,type as type,id as id from result3;

     创建result4表用于数据清洗

    create table result4 (ip String,data String,day String,traffic String,type String,id String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    导入数据

    insert into table result4(ip,data,day,traffic,type,id) (select ip,data,day,traffic,type,id from result3);

    select id,count(id)from result3 group by id order by count(id) desc limit 10;

    截图:

    select ip,count(ip)from result3 group by ip order by count(ip) desc limit 10;

     

    导入到mysql

     

  • 相关阅读:
    python使用thrift访问操作hbase
    js打开新页面
    设计模式
    c# dotfuscator 混淆后无法使用
    SQL server清空数据库日志脚本
    SQlserver 行转列
    SQLServer 脚本测试
    C# HttpWebRequest与HttpWebResponse详解
    反射
    SQl server master
  • 原文地址:https://www.cnblogs.com/092e/p/15530457.html
Copyright © 2011-2022 走看看