模拟滴滴出行用户数据分析处理

架构过程拆解

  1. 用户的订单数据庞大。所以我们需要选择一个大规模数据的分布式文件来存储这些日志文件,
    此处基于基于Hadoop的HDFS文件系统来存储数据。
  2. 为了方便数据分析,我们要将日志文件的数据映射为一张张的表,所以我们基于Hive来构建数据仓库。
    为了提高数据处理的性能,所有的数据都会在Hive夏来集中进行管理。
  3. 我们将基于Spark引擎来进行数据开发,所有的应用程序都将运行在Spark集群上,这样可以保证数据被高性能地处理。
  4. 我们将使用Zeppelin来快速将数据进行SQL指令交互。
  5. 我们使用Sqoop导出分析后地数据到传统型数据库,便于后期应用
  6. 我们使用Superest来实现数据可视化展示。

数据仓库构建

用户日志数据包括:

  1. 原始日志数据(业务系统中保存地日志文件数据) (ods_didi)
  2. 预处理后的数据(原始日志数据不一定能直接使用,所有要对其预处理) (dw_didi)
  3. 分析结果数据 ( app_didi)

1:创建数据库

  1.1 创建ods库(临时存储层ODS)
    create database if not exists ods_didi;
    1.2 创建dw库(数据仓库层OW)
    create database if not exists dw_didi;
    1.3 创建app库(应用层APP)
    create database if not exists app_didi;

2:创建表

2.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.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 ',' ; 
2.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 ',' ; 

2.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 ',' ; 

3:给表加载数据

3.1、创建本地路径,上传源日志文件
 mkdir -p /export/data/didi

3.2、通过load命令给表加载数据,并指定分区
 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');
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值