开发细节当中即伴随着各种各样的风险,并要即时反馈和处理风险,如工作量评估、技术难度评估、人员变更、需求变更等等,故我们将两者放在一起,不可拆分。
一. 开发细节
主要有九部分:
- 确定数据源文件集合
- 将源数据装载到hive仓库
- 编写udf分词
- 生成分词结果表
- 生成wordcount倒排表,按词频降序排列
- 将hive表推送到MySQL表
- 前端展示,搭建spring boot项目
- 前端加入echarts绘图插件
- 前端界面生成
- 集成前端页面
-
确定数据集
-
-
基于项目需求,选择公开数据集即可。
-
- 搜狗搜验室-http://www.sogou.com/labs/
- 多领域公开数据集-http://blog.csdn.net/marleylee/article/details/76587354
- 国外的公开数据集-https://site.douban.com/146782/widget/notes/15524697/note/519440833/
- 自行积累的公共数据集-https://mp.weixin.qq.com/s/8whZsvERs6zlUeYT677YyA
-
-
-
洞查数据本身
- 将数据传输到hadoop客户端机器中,为数据传输到hive仓库做准备
- 总大小
-
-
掌握计算方法
-
准确计算法:看到全部数据后,通过命令求实际大小。
-
评估计算法:通过对部分数据做精细化计算,然后推导到全局数据(解压一个看看压缩比)
ls | wc -l 是看一行有多少,看文件夹下多少文件 du -sh *|sort排序 du -sh *|sort | tail -1最大 du -sh *|sort | head -1最小 du -sh *|sort -h 有单位还能排序
-
-
总记录条数
- 掌握计算方法
-
可预见的最大/最小文件记录数
- 掌握计算方法
-
- zip原始数据批量解压
- 在hive中创建weibo_origin和weibo_product两张同构表
- 将解压完的明文每天数据文件,按天load到weibo_origin载入原始数据层
- 数据检验与校正
- 清洗原始数据表weibo_origin,按天分区插入到weibo_product表中
- zip原始数据批量解压
-
linux中ls相当于Java里的遍历
-
xargs 把左侧字符串转化为右侧的参数,-n1就是转化为一个参数2就是两个
-
将zip包解压批量解压到指定目录/data1/weibo_text下,目标目录如不是空要加个-o在-d前覆盖文件夹
ls weibo/*.zip | xargs -n1 unzip -d weibo_text/
-
- 在hive中创建weibo_origin和weibo_product两张同构表
- 建表语句,weibo_origin表
因为他的数据基于外部,所以他是外表,external
CREATE external TABLE weibo_origin( mid string, retweeted_status_mid string, uid string, retweeted_uid string, source string, image string, text string, geo string, created_at string, deleted_last_seen string, permission_denied string ) comment 'weibo content table' partitioned by (day_seq string comment 'the day sequence') ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' STORED AS textfile;
- 表weibo_product(该表用任意hive支持的数据表格式均可)
CREATE TABLE weibo_product( mid string, retweeted_status_mid string, uid string, retweeted_uid string, source string, image string, text string, geo string, created_at string, deleted_last_seen string, permission_denied string ) comment 'weibo content table' partitioned by (day_seq string comment 'the day sequence') ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' LINES TERMINATED BY 'n' STORED AS orcfile;
- 数据按天分区载入weibo_origin表
- 相关技术解析
-
Shell如何拿到一个文本串的执行结果:用``即可,即将该符号内的所有文本当作shell代码来执行
-
Shell当中如何遍历集合
-
For…do…done
-
Shell当中实现字符串的截取
-
- Cut,Awk,Sed比如${}等等
-
- 相关技术解析
写shell脚本load_to_weibo_origin.sh
#! /bin/bash
#1、定义csv文件所在的目录
csv_root_dir_local=/home/zel/corpus_dw_hive/day_csv_data/
#2、定义csv上传到hdfs空间的目录
csv_root_dir_hdfs=/user/zel/csv_root_dir/
#3、获取csv的文件名称,作为分区表的分区字段值
csv_filename_list=`ls $csv_root_dir_local | cut -d . -f1`
#4、进行遍历csv_filename_list集合,逐个处理csv文件的上传
for filename in $csv_filename_list
do
echo $filename
#嵌入hdfs相关操作
#1、将本地csv上传到hdfs指定路径当中
hdfs dfs -copyFromLocal -f $csv_root_dir_local""$filename".csv" $csv_root_dir_hdfs
#2、将hdfs的csv文件加载到指定的hive表分区当中
hive -e "
use zel;
load data inpath '$csv_root_dir_hdfs$filename.csv' overwrite into table weibo_origin partition(day_seq='$filename');
"
#break
done
#脚本执行完成
shell脚本执行
-
- 常规测试执行
sh load_to_weibo_origin.sh



