【hadoop】基于hive的B站用户行为大数据分析

发布于:2025-04-18 ⋅ 阅读:(24) ⋅ 点赞:(0)

1.需求分析

b站现在积累有用户数据和视频列表数据,为了配合市场部门做好用户运营工作,需要对b站的用户行为进行分析,其具体需求如下所示:

统计b站视频不同评分等级(行转列)的视频数。

统计上传b站视频最多的用户Top10,以及这些用户上传的视频观看次数在前10的视频。

统计b站每个类别视频观看数topn。

统计b站视频分类热度topn。

统计b站视频观看数topn。

2. 表结构

2.1 user 表结构

2.2 video 表结构

 3.准备工作

create database if not exists bibi_db;

3.1 创建 user 表

create table if not exists user
(uid int,
name string,
regtime string,
visitnum int,
lastvisit string,
gender int,
birthday string,
country string,
province string,
city string,
uploadvideos int)
row format delimited fields terminated by ",";

 3.2 创建 video 表

create table if not exists orc_video
(vid string,
uid int,
vday int,
vtype string,
vlength int,
visit int,
score int,
comments int,
collection int,
fabulous int,
forward int)
row format delimited fields terminated by ",";

4. 加载数据

数据集要先传到虚拟机指定位置(略)

load data local inpath "/home/hadoop/hadoop-2.9.2/study-hive-data/user.txt" into table user;
load data local inpath "/home/hadoop/hadoop-2.9.2/study-hive-data/video.txt" into table video;

5. 统计分析

统计b站视频观看数Topn

hive> select vid,visit from orc_video order by visit desc limit 3;

统计b站视频分类热度Topn

hive> select vtype,count(vid) hot from orc_video group by vtype order by hot desc limit 3;

统计每个类别视频观看数Topn

hive>  select v.vtype,v.vid,v.visit from   (select vtype,vid,visit,rank() over(partition by vtype order by visit desc) rk from orc_video) v where rk<=3; 


网站公告

今日签到

点亮在社区的每一天
去签到