数据样例:
[{"beCommentWeiboId":"",
"beForwardWeiboId":"",
"catchTime":"1387157643",
"commentCount":"682",
"content":"喂!2014。。。2014!喂。。。",
"createTime":"1387086483",
"info1":"",
"info2":"",
"info3":"",
"mlevel":"",
"musicurl":[],
"pic_list":["http://ww1.sinaimg.cn/square/47119b17jw1ebkc9b07x9j218g0xcair.jpg","http://ww4.sinaimg.cn/square/47119b17jw1ebkc9ebakij218g0xc113.jpg","http://ww2.sinaimg.cn/square/47119b17jw1ebkc9hml7dj218g0xcgt6.jpg","http://ww3.sinaimg.cn/square/47119b17jw1ebkc9kyakyj218g0xcqb3.jpg"],
"praiseCount":"1122",
"reportCount":"671",
"source":"iPhone客户端",
"userId":"1192336151",
"videourl":[],
"weiboId":"3655768039404271",
"weiboUrl":"http://weibo.com/1192336151/AnoMrDstN"}]2、字段描述
总共19个字段
beCommentWeiboId  是否评论
beForwardWeiboId 是否是转发微博
catchTime 抓取时间
commentCount 评论次数
content 内容
createTime 创建时间
info1 信息字段1
info2信息字段2
info3信息字段3
mlevel   no sure
musicurl    音乐链接
pic_list    照片列表(可以有多个)
praiseCount 点赞人数
reportCount 转发人数
source  数据来源
userId  用户id
videourl    视频链接
weiboId 微博id
weiboUrl    微博网址
1、数据处理:针对数据问题,请给出对应的解决方案(15分)
数据文件过多:要合并,请给出解决方案
输入中小文件过多主要是通过参数调节
set hive.input.format=org.apache.hadoop.hive.ql.io.CombineHiveInputFormat :设置Inputformat。
set mapred.max.split.size=256000000:用来设置每个Map最大的输入大小。
set mapred.min.split.size.per.node=100000000:用来设置每个map中从一个node读取的最小数据量。合并的时候,会优先把一个node下的数据合并到一个split里,这样比较容易保证数据节点和计算节点本地行。
set mapred.min.split.size.per.rack=100000000:用来设置每个map中从一个机架上读取的最小数据量。如果没法保证一个split中数据尽量在一个node上,会尽量保证数据在一个机架上。
2、组织数据
(创建Hive表weibo_json(json string),表只有一个字段,导入所有数据,并验证查询前5条数据)
create external table weibo_json(json  string) location ‘/hw/weibo/wdata/’;
(解析完weibo_json当中的json格式数据到拥有19个字段的weibo表中,写出必要的SQL语句)
给出的数据不是常规json格式,需要去除收尾的'[]',采用substring(json,2,length(json)-2),获取json格式
然后解析,采用hive内置函数get_json_object进行解析,或者使用json_tuple(jsonStr, k1, k2, ...)
创建表:
create table weibo(beCommentWeiboId string,beForwardWeiboId string,
catchTime string,commentCount int,content string, createTime string,
info1 string,info2 string,info3 string,mlevel string,musicurl string,
pic_list string, praiseCount int, reportCount int, source string,
userId string,videourl string, weiboId string,weiboUrl string)
row format delimited fields terminated by '\t';
插入数据
insert into table weibo select json_tuple
(substring(a.json,2,length(a.json)-2),'beCommentWeiboId',
'beForwardWeiboId','catchTime','commentCount','content','createTime',
'info1','info2','info3','mlevel','musicurl','pic_list','praiseCount',
'reportCount','source','userId','videourl','weiboId','weiboUrl')
from weibo_json a limit 2;截取部分加载,总量为117062条
3、统计微博总量 和 独立用户数
select count (*) from weibo;
+---------+
|   _c0   |
+---------+
| 117062  |
+---------+select count(distinct userId) from weibo;
+--------+
|  _c0   |
+--------+
| 10336  |
+--------+
4、统计用户所有微博被转发的次数之和,输出top5用户,并给出次数select userId,sum(reportCount) sumcount from weibo
group by userId
order by sumcount desc
limit 5;
+-------------+-----------+
|   userid    | sumcount  |
+-------------+-----------+
| 1266321801  | 18556781  |
| 1188552450  | 16467001  |
| 1195230310  | 16318202  |
| 1195242865  | 15928934  |
| 1192329374  | 14109943  |
+-------------+-----------+
5、统计带图片的微博数
默认含有[],长度是2select count(*) from weibo
where length(pic_list)>2;
+--------+
|  _c0   |
+--------+
| 67494  |
+--------+
6、统计使用iphone发微博的独立用户数
select count(distinct userId) from weibo
where source like '%iPhone%' or source like '%ipone%';
+------+
| _c0  |
+------+
| 69   |
+------+
7、将微博的点赞人数和转发人数相加求和,
并将相加之和降序排列,取前10条记录,输出userid和总次数
select userId,praiseCount,reportCount,(praiseCount+reportCount) as total
from weibo order by total desc limit 10;
+-------------+--------------+--------------+----------+
|   userid    | praisecount  | reportcount  |  total   |
+-------------+--------------+--------------+----------+
| 2202387347  | 1            | 2692012      | 2692013  |
| 1266286555  | 537628       | 1014922      | 1552550  |
| 1266286555  | 537628       | 1014903      | 1552531  |
| 1266286555  | 537627       | 1014756      | 1552383  |
| 1266286555  | 537627       | 1014734      | 1552361  |
| 1266286555  | 537627       | 1014697      | 1552324  |
| 1793285524  | 530857       | 974092       | 1504949  |
| 1793285524  | 530857       | 974089       | 1504946  |
| 1793285524  | 530857       | 973979       | 1504836  |
| 1793285524  | 530857       | 973978       | 1504835  |
+-------------+--------------+--------------+----------+
8、统计微博中评论次数小于1000的用户ID与数据来源信息,将其放入视图,
然后统计视图中数据来源是”ipad客户端”的用户数目
create view weibo_v_8 as
select userId,source from weibo
where commentCount < 1000;select count(distinct userId) from weibo_v_8
where source like '%ipad%' or source like '%iPad%';
+------+
| _c0  |
+------+
| 34   |
+------+
9、统计微博内容中出现”iphone”次数最多的用户,
最终结果输出用户id和次数(注意:该次数是”iphone”的出现次数,
不是出现”iphone”的微博数目)
select userId,sum((length(content)-length(regexp_replace(content,'iphone','')))/6)s
from weibo group by userId
order by s desc limit 3;
+-------------+-------+
|   userid    |   s   |
+-------------+-------+
| 2120456303  | 13.0  |
| 1287708222  | 7.0   |
| 1567852087  | 6.0   |
+-------------+-------+
10、求每天发微博次数最多的那个家伙的ID和发微博的条数
create view weibo_10_t as
select userId,weiboId,from_unixtime(cast(createTime as Bigint),
'yyyy-MM-dd') dt
from weibo
limit 3;select w.userId,count(*) cc
from weibo_10_t w
group by w.userId,w.dt
order by cc  desc limit 3;
+-------------+------+
|  w.userid   |  cc  |
+-------------+------+
| 1638781994  | 120  |
| 1638781994  | 117  |
| 1618051664  | 95   |
+-------------+------+
11、求出所有被多次引用(同一张照片出现在多条微博中,
超过1条就算多条)的照片的数目
照片引用裂变,进行计数,数目>1就可以
create view weibo_11_t as
select explode(split(substring(pic_list,2,length(pic_list)-2),','))pic
from weibo
limit 5;select count(*) from
(select count(*) cc from weibo_11_t
where length(pic) > 0
group by pic)a
where a.cc > 1;
+-------+
|  _c0  |
+-------+
| 4052  |
+-------+

hive案例——微博相关推荐

  1. Hive案例之股票分析

    Hive案例之股票分析 需求 ​ 中国的股票市场日益成熟.最近受美国股票波动冲击,股票也波动比较厉害.请按如下交易明细进行分析. ​ 如下数据保存在gupiao.txt中: 序号 股票号 股票名称 行 ...

  2. Spark 2.2.1 + Hive 案例之不使用现有的Hive环境;使用现有的Hive数据仓库;UDF自定义函数

    Spark 2.2.1 + Hive 案例之不使用现有的Hive环境:使用现有的Hive数据仓库:UDF自定义函数 Spark SQL支持读写存储在Apache Hive中的数据.在Spark 2.2 ...

  3. Hive案例:统计单词个数

    目录 1.文本文件test.txt 2.登录hadoop虚拟机 3.启动hadoop 4.将test.txt文件上传到HDFS的word目录 5.启动Hive

  4. 58 Hive案例(访问时长统计)

    需求 从web日志中统计每日访客平均停留时间 实现步骤 1.由于要从大量请求中分辨出用户的各次访问,逻辑相对复杂,通过hive直接实现有困难,因此编写一个mr程序来求出访客访问信息(详见代码) 启动m ...

  5. hive案例:hive对房产数据进行过滤

    数据: 天通苑北一区 3室2厅 510万 1.01101E+11 天通苑北一区 3-2厅 143.09 平米 南北 简装 有电梯 35642 510 旗胜家园 2室1厅 385万 1.01101E+1 ...

  6. Hive案例-学生成绩表综合案例

    元数据: course数据: 1,数据库 2,数学 3,信息系统 4,操作系统 5,数据结构 6,数据处理 student数据: 95002,刘晨,女,19,IS 95017,王风娟,女,18,IS ...

  7. hive案例——影评

    现有如此三份数据: 1.users.dat 数据格式为: 2::M::56::16::70072 对应字段为:UserID BigInt, Gender String, Age Int, Occupa ...

  8. Hive案例 学生成绩表综合案例

    首先给出各个表的数据 •表1 学生表 <学号,姓名,性别,年龄,系> - <Sno,Sname,Ssex,Sage,Sdepartment> 95001,李勇,男,20,CS ...

  9. 57 Hive案例(数据ETL)

    需求 对web点击流日志基础数据表进行etl(按照仓库模型设计) 按各时间维度统计来源域名top10 已有数据表 "t_orgin_weblog" : col_name data_ ...

最新文章

  1. 阿里员工吐槽:杭州22k拿到头条35k和shopee33k的offer,怎么选?
  2. cmd运行python程序
  3. 120分的转录组试题,你能得多少
  4. 启科量子加速商业化:量子通信为「盾」,量子计算为「矛」
  5. html 搜索 高亮效果,html5输入框高亮效果
  6. yarn logs -applicationId 无法导出logs日志 Log aggregation has not completed or is not enabled.
  7. 你该学点HTML/CSS知识的9大理由
  8. 联通iptv机顶盒中心服务器连接异常,联通iptv机顶盒连接安装 联通iptv机顶盒使用...
  9. 用友服务器的系统管理,用友软件系统管理模块常见问题解析及方法
  10. 利用windows网络诊断功能修复网络能连接但无Internet
  11. ProcessingJoy —— 油画笔触【JAVA】
  12. Linux中的vim最小集、指令集及其配置
  13. 使用docker搭建sqli-lab环境以及upload-labs环境 xss挑战之旅环境 搭建vulhub环境
  14. 传统分割方法汇总(包括SLIC、Ncut、watershed、graph-based segmentation、Meanshit、最大熵分割)
  15. 【机器学习】--神经网络(NN)
  16. JavaScript 实现 HTMLDecode
  17. CSS的content属性怎么用?
  18. 【洛咕P3400】仓鼠窝【单调栈】
  19. curl -u “username“ https://api.github.com 转换http请求
  20. C++-练习-105

热门文章

  1. 笔经面经_2018春招美团数据分析实习生笔试
  2. VBA把excel中的图表复制到PPT中
  3. Frp实现无域名穿透
  4. ensp配置access口_eNSP仿真软件之VLAN基础配置及Access接口
  5. am最新版安装包_Mamangam手机游戏安装包下载-游戏大玩家
  6. linux下批处理命令详解,Linux top命令批处理模式讲解
  7. Android使用系统自带下载器
  8. android嵌入式开发教程
  9. 解决WINDOWS防火墙开启后Ping不通
  10. ubuntu 16.04彻底卸载nginx