用户画像 客户基本属性表

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zimiao552147572/article/details/88425780

======================================== 

数据仓库分层:
        BDM 层(源数据层):缓冲数据,源数据的直接映射
        FDM 层(对 BDM 源数据层的数据进行清洗和预处理):基础数据层,数据拉链处理、分区处理
        GDM 层(对 FDM 层数据 进行统计一些指标数据):通用聚合
        ADM 层(对 GDM 层指标数据 进行指标数据的业务汇总分析):高度聚合

---------------------------------------------------------------------

1.客户基本属性表
    SQL目的:时间分区中每天的数据应为每天新增用户和每天访问用户
        1.客户基本属性表 BDM层 bdm.itcast_bdm_user(时间分区)
        2.客户基本属性表 FDM层 fdm.itcast_fdm_user_wide(时间分区)
        3.客户基本属性表 GDM层 gdm.itcast_gdm_user_basic(时间分区)

---------------------------------------------------------------------

客户基本属性表 GDM 层(对 FDM 层数据 进行统计一些指标数据)

    SQL目的:时间分区中每天的数据应为每天新增用户和每天访问用户

    --用户画像-客户基本属性模型表 GDM 层(对 FDM 层数据 进行统计一些指标数据)
    create database if not exists gdm;

    create table if not exists gdm.itcast_gdm_user_basic( 
    user_id string                ,--用户ID
    user_name string            ,--用户登陆名
    user_sex  string            ,--用户性别
    user_birthday string        ,--用户生日
    user_age  bigint            ,--用户年龄
    constellation string        ,--用户星座
    province string                ,--省份
    city string                    ,--城市
    city_level string            ,--城市等级
    hex_mail string                ,--邮箱
    op_mail string                ,--邮箱运营商
    hex_phone string            ,--手机号
    fore_phone string            ,--手机前3位
    op_phone string                ,--手机运营商
    add_time timestamp            ,--注册时间
    login_ip string                ,--登陆ip地址
    login_source string            ,--登陆来源
    request_user string            ,--邀请人
    total_mark bigint            ,--会员积分
    used_mark bigint            ,--已使用积分
    level_name string            ,--会员等级名称
    blacklist bigint            ,--用户黑名单
    is_married bigint            ,--婚姻状况
    education string            ,--学历
    monthly_money double        ,--收入
    profession string            ,--职业
    sex_model bigint            ,--性别模型
    is_pregnant_woman bigint    ,--是否孕妇
    is_have_children bigint        ,--是否有小孩
    children_sex_rate double    ,--孩子性别概率
    children_age_rate double    ,--孩子年龄概率
    is_have_car bigint            ,--是否有车
    potential_car_user_rate double,--潜在汽车用户概率
    phone_brand string            ,--使用手机品牌
    phone_brand_level string    ,--使用手机品牌档次
    phone_cnt bigint            ,--使用多少种不同的手机
    change_phone_rate bigint    ,--更换手机频率
    majia_flag string            ,--马甲标志
    majie_account_cnt bigint,        --马甲账号数量
    loyal_model bigint,        --用户忠诚度
    shopping_type_model bigint    ,    --用户购物类型
    figure_model bigint,        --身材
    stature_model bigint,        --身高
    dw_date timestamp
    ) partitioned by (dt string);

---------------------------------------------------------------------

客户基本属性模型表 BDM层(源数据层)
 
    --客户基本属性模型表BDM层(源数据层)
    create database if not exists bdm;

    create external table if not exists bdm.itcast_bdm_user( 
    user_id string                ,--用户ID
    user_name string            ,--用户登陆名
    user_sex  string            ,--用户性别
    user_birthday string        ,--用户生日
    user_age  bigint            ,--用户年龄
    constellation string        ,--用户星座
    province string            ,--省份
    city string            ,--城市
    city_level string            ,--城市等级
    hex_mail string            ,--邮箱
    op_mail string            ,--邮箱运营商
    hex_phone string            ,--手机号
    fore_phone string            ,--手机前3位
    op_phone string            ,--手机运营商
    add_time string            ,--注册时间
    login_ip string            ,--登陆ip地址
    login_source string        ,--登陆来源
    request_user string        ,--邀请人
    total_mark bigint            ,--会员积分
    used_mark bigint            ,--已使用积分
    level_name string            ,--会员等级名称
    blacklist bigint            ,--用户黑名单
    is_married bigint            ,--婚姻状况
    education string            ,--学历
    monthly_money double        ,--收入
    profession string            --职业
    ) partitioned by (dt string)
    row format delimited fields terminated by ','
    location '/business/bdm/itcast_bdm_user' ; //外部分区表

    //添加分区
    alter table bdm.itcast_bdm_user add partition (dt='2017-01-01');
    //把BDM层源数据文件导入到 BDM层 外部分区表中
    hdfs dfs -put /root/source_data/itcast_bdm_user.txt /business/bdm/itcast_bdm_user/dt=2017-01-01

---------------------------------------------------------------------
客户基本属性表 FDM层(对 BDM 源数据层的数据进行清洗和预处理)

    --客户基本属性表 FDM层(对 BDM 源数据层的数据进行清洗和预处理)
    create database if not exists fdm;

    create table if not exists fdm.itcast_fdm_user_wide( 
    user_id string                ,--用户ID
    user_name string            ,--用户登陆名
    user_sex  string            ,--用户性别
    user_birthday string        ,--用户生日
    user_age  bigint            ,--用户年龄
    constellation string        ,--用户星座
    province string                ,--省份
    city string                    ,--城市
    city_level string            ,--城市等级
    hex_mail string                ,--邮箱
    op_mail string                ,--邮箱运营商
    hex_phone string            ,--手机号
    fore_phone string            ,--手机前3位
    op_phone string                ,--手机运营商
    add_time string                ,--注册时间
    login_ip string                ,--登陆ip地址
    login_source string            ,--登陆来源
    request_user string            ,--邀请人
    total_mark bigint            ,--会员积分
    used_mark bigint            ,--已使用积分
    level_name string            ,--会员等级名称
    blacklist bigint            ,--用户黑名单
    is_married bigint            ,--婚姻状况
    education string            ,--学历
    monthly_money double        ,--收入
    profession string            ,--职业
    dw_date  timestamp
    ) partitioned by (dt string);

---------------------------------------------------------------------

    --加载 客户基本属性模型表BDM层(源数据层)数据 到 客户基本属性表 FDM层
    insert overwrite table fdm.itcast_fdm_user_wide partition(dt='2017-01-01')
    select 
    t.user_id,
    t.user_name,
    t.user_sex,
    t.user_birthday,
    t.user_age,
    t.constellation,
    t.province,
    t.city,
    t.city_level,
    t.hex_mail,
    t.op_mail,
    t.hex_phone,
    t.fore_phone,
    t.op_phone,
    t.add_time,
    t.login_ip,
    t.login_source,
    t.request_user,
    t.total_mark,
    t.used_mark,
    t.level_name,
    t.blacklist,
    t.is_married,
    t.education,
    t.monthly_money,
    t.profession, 
    from_unixtime(unix_timestamp())  dw_date   // 作为操作时间:返回 Unix时间戳(Unix timestamp),表示将 Unix 时间戳字符串进行格式化
    from bdm.itcast_bdm_user t where dt='2017-01-01';

---------------------------------------------------------------------

用户画像-客户基本属性模型表 GDM层(对 FDM 层数据 进行统计一些指标数据)

    --用户画像-客户基本属性模型表 GDM层(对 FDM 层数据 进行统计一些指标数据)
    create database if not exists gdm;

    create  table if not exists gdm.itcast_gdm_user_basic( 
    user_id string                ,--用户ID
    user_name string            ,--用户登陆名
    user_sex  string            ,--用户性别
    user_birthday string        ,--用户生日
    user_age  bigint            ,--用户年龄
    constellation string        ,--用户星座
    province string                ,--省份
    city string                    ,--城市
    city_level string            ,--城市等级
    hex_mail string                ,--邮箱
    op_mail string                ,--邮箱运营商
    hex_phone string            ,--手机号
    fore_phone string            ,--手机前3位
    op_phone string                ,--手机运营商
    add_time string                ,--注册时间
    login_ip string                ,--登陆ip地址
    login_source string            ,--登陆来源
    request_user string            ,--邀请人
    total_mark bigint            ,--会员积分
    used_mark bigint            ,--已使用积分
    level_name string            ,--会员等级名称
    blacklist bigint            ,--用户黑名单
    is_married bigint            ,--婚姻状况
    education string            ,--学历
    monthly_money double        ,--收入
    profession string            ,--职业
    //下面的该些指标需要通过人工智能算法实现计算得出
    sex_model bigint            ,--性别模型
    is_pregnant_woman bigint    ,--是否孕妇
    is_have_children bigint        ,--是否有小孩
    children_sex_rate double    ,--孩子性别概率
    children_age_rate double    ,--孩子年龄概率
    is_have_car bigint            ,--是否有车
    potential_car_user_rate double,--潜在汽车用户概率
    phone_brand string            ,--使用手机品牌
    phone_brand_level string    ,--使用手机品牌档次
    phone_cnt bigint            ,--使用多少种不同的手机
    change_phone_rate bigint    ,--更换手机频率
    majia_flag string            ,--马甲标志
    majie_account_cnt bigint    ,--马甲账号数量
    loyal_model bigint            ,--用户忠诚度
    shopping_type_model bigint    ,--用户购物类型
    figure_model bigint            ,--身材
    stature_model bigint        ,--身高
    dw_date timestamp  // Unix时间戳(Unix timestamp)
    ) partitioned by (dt string);

---------------------------------------------------------------------

    --加载 FDM 层数据(对 FDM 层数据 进行统计一些指标数据) 到 GDM 层
    insert overwrite table  gdm.itcast_gdm_user_basic partition(dt='2017-01-01') 
    select 
    t.user_id,
    t.user_name,
    t.user_sex,
    t.user_birthday,
    t.user_age,
    t.constellation,
    t.province,
    t.city,
    t.city_level,
    t.hex_mail,
    t.op_mail,
    t.hex_phone,
    t.fore_phone,
    t.op_phone,
    t.add_time,
    t.login_ip,
    t.login_source,
    t.request_user,
    t.total_mark,
    t.used_mark,
    t.level_name,
    t.blacklist,
    t.is_married,
    t.education,
    t.monthly_money,
    t.profession, 
    //下面的该些指标需要通过人工智能算法实现计算得出
    null sex_model,        --数据挖掘模型-开始
    null is_pregnant_woman,
    null is_have_children,
    null children_sex_rate,
    null children_age_rate,
    null is_have_car,
    null potential_car_user_rate,
    null phone_brand,
    null phone_brand_level,
    null phone_cnt,
    null change_phone_rate,
    null majia_flag,
    null majie_account_cnt,
    null loyal_model,
    null shopping_type_model,
    null figure_model,
    null stature_model,        --数据挖掘模型-结束
    from_unixtime(unix_timestamp())  dw_date // 作为操作时间:返回 Unix时间戳(Unix timestamp),表示将 Unix 时间戳字符串进行格式化
    from (select * from fdm.itcast_fdm_user_wide where dt='2017-01-01') t;
 

猜你喜欢

转载自blog.csdn.net/zimiao552147572/article/details/88425780