• 课堂测试——HIVE 数据分析


    题目要求:

     

     具体操作:

    ①hive路径下建表:sale

    create table sale

    (day_id String, sale_nbr String, buy_nbr String, cnt String, round String)

    ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    ②导入数据:

    load data local inpath '/opt/module/data/sales.csv' into table sale;

     

    ③数据清洗:

     

    3、数据分析处理:

    (1)统计每天各个机场的销售数量和销售金额。要求的输出字段 day_id,sale_nbr,,cnt,round 日期编号,卖出方代码,数量,金额。

    命令:

    查询语句:

    select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'C%' group by day_id,sale_nbr;

    创建表table1:

    create table table1(day_id String,sale_nbr String, cnt String,round String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    将查询语句保存至table1:

    insert overwrite table table1 select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'C%' group by day_id,sale_nbr;

     

    (2)统计每天各个代理商的销售数量和销售金额.要求的输出字段 day_id,sale_nbr,cnt,round 日期编号,卖出方代码,数量,金额

    命令:

    查询语句:

    select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'O%' or buy_nbr like 'O%' group by day_id,sale_nbr;

    创建表table2:

    create table table2(day_id String,sale_nbr String, cnt String,round String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    将查询结果保存至table2:

    insert overwrite table table2 select day_id,sale_nbr,sum(cnt),sum(round) from sale where sale_nbr like 'O%' or buy_nbr like 'O%' group by day_id,sale_nbr;

     

    3)统计每天各个代理商的销售活跃度。 要求的输出字段 day_id,sale_nbr, sale_number 日期编号,卖出方代码,交易次数(买入或者卖出均算交易次数)

     命令:

    查询语句:

    select day_id,sale_nbr,count(sale_nbr)from sale where sale_nbr like "O%" group by sale_nbr,day_id;

    创建表table3:

    create table table3(day_id String,sale_nbr String, sale_number String) ROW format delimited fields terminated by ',' STORED AS TEXTFILE;

    将查询结果保存至表table3:

    insert overwrite table table3 select day_id,sale_nbr,count(sale_nbr)from sale where sale_nbr like "O%" group by sale_nbr,day_id;

     

    导入mysql:

    1.建表(可视化建表):

    2.sqoop路径下执行命令:

    bin/sqoop export

    > --connect jdbc:mysql://master:3306/mysql

    > --username root

    > --password 000000

    > --table table1

    > --num-mappers 1

    > --export-dir /user/hive/warehouse/table1

    > --input-fields-terminated-by ","

     

     

    bin/sqoop export

    > --connect jdbc:mysql://master:3306/mysql

    > --username root

    > --password 000000

    > --table table2

    > --num-mappers 1

    > --export-dir /user/hive/warehouse/table2

    > --input-fields-terminated-by ","

     

     

    bin/sqoop export

    > --connect jdbc:mysql://master:3306/mysql

    > --username root

    > --password 000000

    > --table table3

    > --num-mappers 1

    > --export-dir /user/hive/warehouse/table3

    > --input-fields-terminated-by ","

     

     

  • 相关阅读:
    迁移模型问题,提示admin已存在
    centos 部署的时候安装不上Mariadb,缺少依赖文件
    collections
    List里面添加子list,子list clear之后竟然会影响主List里面的内容
    Jackson用法详解
    Ouath2.0在SpringCloud下验证获取授权码
    zookeeper原理之Leader选举的getView 的解析流程和ZkServer服务启动的逻辑
    zookeeper原理之Leader选举源码分析
    Spring Integration sftp 专栏详解
    SpringMVC常用注解标签详解
  • 原文地址:https://www.cnblogs.com/zyj3955/p/15370389.html
Copyright © 2020-2023  润新知