全网最详细的Hadoop大数据集群搭建并进行项目分析(基于完全分布式)---终结篇

##所有需要的资料全部已上传到百度网盘上,请自行下载##

获取镜像,https://pan.baidu.com/s/1ho4hMrvIu1V6W4wWdH8nIA,提取码:ygyg
获取Xshell,https://pan.baidu.com/s/1xWRle9chuNtBpE0fDa7DHA,提取码:u3s6
获取Hadoop,https://pan.baidu.com/s/1a5M23KlUMtqKOoWqDnZBHQ,提取码:y1y3
获取jdk,https://pan.baidu.com/s/1ftofkxBKIYuOhooe2tj_1A,提取码:z9y4
获取 MySQL,https://pan.baidu.com/s/19wa564c6Pln1ReJOmHbh-g,提取码:y4k7
获取MySQL配置jar包,https://pan.baidu.com/s/1vFCKEttZNnd5ZfyeompcqQ,提取码:dsj8
获取Hive,https://pan.baidu.com/s/1YcnL07UVg_Czr1mMFfgJsQ,提取码:n4i7
获取Sqoop,https://pan.baidu.com/s/1wY5NcbI6hwKDt6r9BWu0Hg,提取码:u3x9
获取Zeppelin ,https://pan.baidu.com/s/1xjqbw3FO1sNClLSgd1iFhw,提取码:yw52

目录

第四部分:大数据集群搭建完全分布式与项目实施(终结篇)

终结篇:分析滴滴出行项目

如下图为项目业务背景–架构图:
在这里插入图片描述

一、数据仓库构建

1、创建数据库…
-- 1.1 创建ods库
    create database if not exists ods_didi
-- 1.2 创建dw库
    create database if not exists dw_didi
-- 1.3 创建app库
    create database if not exists app_didi

在这里插入图片描述

二、创建表

1 、创建订单表结构…
create table if not exists ods_didi.t_user_order(
        orderId string comment '订单id',
        telephone string comment '打车用户手机',
        lng string comment '用户发起打车的经度',
        lat string comment '用户发起打车的纬度',
        province string comment '所在省份',
        city string comment '所在城市',
        es_money double comment '预估打车费用',
        gender string comment '用户信息 - 性别',
        profession string comment '用户信息 - 行业',
        age_range string comment '年龄段(70后、80后、...)',
        tip double comment '小费',
        subscribe integer comment '是否预约(0 - 非预约、1 - 预约)',
        sub_time string comment '预约时间',
        is_agent integer comment '是否代叫(0 - 本人、1 - 代叫)',
        agent_telephone string comment '预约人手机',
        order_time string comment '预约时间'
    )
    partitioned by (dt string comment '时间分区') 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','

2、 创建取消订单表结构…
create table if not exists ods_didi.t_user_cancel_order(
    orderId string comment '订单ID',
    cstm_telephone string comment '客户联系电话',
    lng string comment '取消订单的经度',
    lat string comment '取消订单的纬度',
    province string comment '所在省份',
    city string comment '所在城市',
    es_distance double comment '预估距离',
    gender string comment '性别',
    profession string comment '行业',
    age_range string comment '年龄段',
    reason integer comment '取消订单原因(1 - 选择了其他交通方式、2 - 与司机达成一致,取消订单、3 - 投诉司机没来接我、4 - 已不需要用车、5 - 无理由取消订单)',
    cancel_time string comment '取消时间'
)
partitioned by (dt string comment '时间分区') 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','

3 、创建订单支付表…
create table if not exists ods_didi.t_user_pay_order(
    id string comment '支付订单ID',
    orderId string comment '订单ID',
    lng string comment '目的地的经度(支付地址)',
    lat string comment '目的地的纬度(支付地址)',
    province string comment '省份',
    city string comment '城市',
    total_money double comment '车费总价',
    real_pay_money double comment '实际支付总额',
    passenger_additional_money double comment '乘客额外加价',
    base_money double comment '车费合计',
    has_coupon integer comment '是否使用优惠券(0 - 不使用、1 - 使用)',
    coupon_total double comment '优惠券合计',
    pay_way integer comment '支付方式(0 - 微信支付、1 - 支付宝支付、3 - QQ钱包支付、4 - 一网通银行卡支付)',
    mileage double comment '里程(单位公里)',
    pay_time string comment '支付时间'
)
partitioned by (dt string comment '时间分区') 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','

4、创建用户评价表…
create table if not exists ods_didi.t_user_evaluate(
    id string comment '评价日志唯一ID',
    orderId string comment '订单ID',
    passenger_telephone string comment '用户电话',
    passenger_province string comment '用户所在省份',
    passenger_city string comment '用户所在城市',
    eva_level integer comment '评价等级(1 - 一颗星、... 5 - 五星)',
    eva_time string comment '评价时间'
)
partitioned by (dt string comment '时间分区') 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' 

5、在将4个表传入/data/didi文件中…
mkdir -p /export/data/didi

在这里插入图片描述

6、通过load命令给4个表加载数据…
load data local inpath '/export/data/didi/order.csv' into table t_user_order partition (dt='2020-04-12')

load data local inpath '/export/data/didi/cancel_order.csv' into table t_user_cancel_order partition (dt='2020-04-12')

load data local inpath '/export/data/didi/pay.csv' into table t_user_pay_order partition (dt='2020-04-12')

load data local inpath '/export/data/didi/evaluate.csv' into table t_user_evaluate partition (dt='2020-04-12')

7、创建宽表…

create table if not exists dw_didi.t_user_order_wide(
    orderId string comment '订单id',
    telephone string comment '打车用户手机',
    lng string comment '用户发起打车的经度',
    lat string comment '用户发起打车的纬度',
    province string comment '所在省份',
    city string comment '所在城市',
    es_money double comment '预估打车费用',
    gender string comment '用户信息 - 性别',
    profession string comment '用户信息 - 行业',
    age_range string comment '年龄段(70后、80后、...)',
    tip double comment '小费',
    subscribe integer comment '是否预约(0 - 非预约、1 - 预约)',
    subscribe_name string comment '是否预约名称',
    sub_time string comment '预约时间',
    is_agent integer comment '是否代叫(0 - 本人、1 - 代叫)',
    is_agent_name string comment '是否代叫名称',
    agent_telephone string comment '预约人手机',
    order_date string comment '预约时间,yyyy-MM-dd',
    order_year string comment '年',
    order_month string comment '月',
    order_day string comment '日',
    order_hour string comment '小时',
    order_time_range string comment '时间段',
    order_time string comment '预约时间'
)
partitioned by (dt string comment '时间分区') 
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','

8、添加宽表数据…
insert overwrite table dw_didi.t_user_order_wide partition(dt='2020-04-12')
select 
    orderId,
    telephone,
    lng,
    lat,
    province,
    city,
    es_money,
    gender,
    profession,
    age_range,
    tip,
    subscribe,
    case when subscribe = 0 then '非预约'
         when subscribe = 1 then'预约'
    end as subscribe_name,
    sub_time,
    is_agent,
    case when is_agent = 0 then '本人'
         when is_agent = 1 then '代叫'
    end as is_agent_name,
    agent_telephone,
    date_format(concat(order_time,':00'), 'yyyy-MM-dd') as order_date,
    year(date_format(concat(order_time,':00'), 'yyyy-MM-dd')) as order_year,
    month(date_format(concat(order_time,':00'), 'yyyy-MM-dd')) as order_month,
    day(date_format(concat(order_time,':00'), 'yyyy-MM-dd')) as order_day,
    hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) as order_hour,
    case when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 1 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 5 then '凌晨'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 5 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 8 then '早上'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 8 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 11 then '上午'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 11 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 13 then '中午'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 13 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 17 then '下午'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 17 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 19 then '晚上'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 19 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 20 then '半夜'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) > 20 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 24 then '深夜'
         when hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) >= 0 and hour(date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss')) <= 1 then '深夜'
         else 'N/A'
    end as order_time_range,
    date_format(concat(order_time,':00'), 'yyyy-MM-dd HH:mm:ss') as order_time
from ods_didi.t_user_order where dt = '2020-04-12' and length(order_time) > 8

9、APP层建表…
-- 创建保存日期对应订单笔数的app表
create table if not exists app_didi.t_order_total(
    `date` string comment '日期(年月日)',
    count integer comment '订单笔数'
)
partitioned by (month string comment '年月,yyyy-MM')
row format delimited fields terminated by ','

10、加载数据到app表(不同时段的占比分析)…
insert overwrite table app_didi.t_order_total partition(month='2020-04')
select 
    '2020-04-12',
    count(orderid) as total_cnt
from
    dw_didi.t_user_order_wide
where
dt = '2020-04-12'

11、创建APP层表…
create table if not exists app_didi.t_order_timerange_total(
    `date` string comment '日期',
    timerange string comment '时间段',
    count integer comment '订单数量'
)
partitioned by (month string comment '年月,yyyy-MM')
row format delimited fields terminated by ','

12、加载数据到APP表(不同地域订单占比)…
insert overwrite table app_didi.t_order_province_total partition(month = '2020-04')
select
    '2020-04-12',
    province,
    count(*) as order_cnt
from
    dw_didi.t_user_order_wide
where
    dt = '2020-04-12'
group by
    province
order by order_cnt desc

13、创建APP表…
create table if not exists app_didi.t_order_age_and_time_range_total(
    `date` string comment '日期',
    age_range string comment '年龄段',
    order_time_range string comment '时段',
    count integer comment '订单数量'
)
partitioned by (month string comment '年月,yyyy-MM')
row format delimited fields terminated by ','

14、数据加载到APP表(不同年龄段,不同时段订单占比)…
insert overwrite table app_didi.t_order_age_and_time_range_total partition(month = '2020-04')
select
      '2020-04-12',
      age_range,
     order_time_range,
    count(*) as order_cnt
from
    dw_didi.t_user_order_wide
where
    dt = '2020-04-12'
group by
    age_range,
order_time_range

15、创建APP表…
-- 创建保存日期对应订单笔数的app表
create table if not exists app_didi.t_order_subscribe_total(
    `date` string comment '日期',
    subscribe_name string comment '是否预约',
    count integer comment '订单数量'
)
partitioned by (month string comment '年月,yyyy-MM')
row format delimited fields terminated by ','


16、加载数据到APP表(预约和非预约用户占比)…
insert overwrite table app_didi.t_order_subscribe_total partition(month = '2020-04')
select
    '2020-04-12',
    subscribe_name,
    count(*) as order_cnt
from
    dw_didi.t_user_order_wide
where
    dt = '2020-04-12'
group by
    subscribe_name

三、superset数据分析

1、安装superset…
#将已有的python环境拷贝到/usr/local下解压
进入vi /etc/profile添加python路径;
export PATH=/export/server/python/bin/:$PATH
source /etc/profile

#初始化数据库——初始化的是自带的sqlsite
superset db upgrade

#superset fab create-admin

# Create default roles and permissions
superset init

#运行superset
nohup superset run -h 192.168.88.100 -p 8099 --with-threads --reload --debugger > ./superset.log 2>&1 &

在databases选项里配置mysql链接:
mysql://root:hadoop@192.168.88.100:3306/superset_local

2、运用superset分析数据…

在这里插入图片描述

在这里插入图片描述

PS:终结篇:打开以下三个网址:

http://192.168.88.100:9090/
http://192.168.88.100:9870/
http://192.168.88.100:8088/
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值