文章导航
大三下思特奇菁英班大数据作业实验报告
思特奇大数据作业实验报告
一、 题目
用HIVE/SPARK 2种SQL方式实现以下2个需求:
1、表拼接
ods_hour 表和 dwd_bd_coordinate 表拼接(拼接条件:两张表的 lng、lat 列相等),生成的数据插入 cdm.dwd_hour 表。
-------------------------------------------------------------------------------
ods_hour + dwd_bd_coordinate => cdm.dwd_hour (拼接条件:lng、lat 列相等)
-------------------------------------------------------------------------------
2、条件查询
查询cdm.dwd_hour每个省的最新日期对应的字段,结果数据插入dwd_hour_latest 表。
例如:select * from dwd_hour_latest
province provincecode daytime
云南省 530000 20190531 <<< 注意这里的值:20190531
海省 630000 20190522
-----------------------------------------------------------------
云南省的最新时间是 2019-05-31,如果新增数据中,云南省的最新时间是 2019-06-03,那么就需要更新云南省的时间为 20190603
province provincecode daytime
云南省 530000 20190603 <<< 注意这里的值:20190603
海省 630000 20190522
二、 思路
1.表拼接

2.条件查询

三、 操作步骤与输出结果
1. Hive
表拼接
(1) 进入hive

(2) 创建名为rzh的数据库(之前已创建没有截图,用show databases显示)

(3) 建立四个表

(4) 导入数据
之前总是无法导入数据,在群里与老师交流后学到了要在hdfs中先导入文件
报错图:

成功导入数据

选上10列数据显示

另一个表

选上5列数据显示

(5) 实现表拼接

查看合并后的表
(6) 去除空数据

已无空数据

条件查询
(1) 按省份筛选最新数据


(2) 在日期表中找到最新数据并覆盖


2. Spark
表拼接
(1) 进入spark

发现原来的表格还在,不用重新创建

(2) 拼接操作


条件查询
(1) 按省份筛选最新数据


(2) 在日期表中找到最新数据并覆盖

