热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

SparkSQL电商用户画像(五)之用户画像开发(客户基本属性表)

7、电商用户画像开发7.1用户画像--数据开发的步骤u数据开发前置依赖-需求确

 7、电商用户画像开发
7.1用户画像--数据开发的步骤
u 数据开发前置依赖

-需求确定 pv uv topn

-建模确定表结构 create table t1(pv int,uv int,topn string)

-实现方案确定

u 数据开发过程

-表落地

-写sql语句实现业务逻辑

-部署代码

-数据测试

-试运行与上线

在接下来的客户基本属性表开发中演示开发的流程。

7.2 用户画像开发--客户基本属性表
    `--用户画像-客户基本属性模型表
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层
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 ',';
alter table itcast_bdm_user add partition (dt='2017-01-01') location '/business/itcast_bdm_user/2017-01-01';
--客户基本属性表FDM层
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);
--加载数据
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
from bdm.itcast_bdm_user t where dt='2017-01-01';
--用户画像-客户基本属性模型表GDM层
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
) partitioned by (dt string);
--加载数据
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
from (select * from fdm.itcast_fdm_user_wide where dt='2017-01-01') t;`
itcast_gdm_user_basic.sh
    `演示模型表开发脚本:
######################
#名称:客户基本属性模型表
# itcast_gdm_user_basic.sh
######################
#!/bin/sh
yesterday=`date -d '-1 day' "+%Y-%m-%d"`
if [ $1 ];then
yesterday=$1
fi
SPARK_SUBMIT_INFO="/export/servers/spark/bin/spark-sql --master spark://node1:7077 --executor-memory 1g --total-executor-cores 2 --conf spark.sql.warehouse.dir=hdfs://node1:9000/user/hive/warehouse"
SOURCE_DATA="/root/source_data"
SQL_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='$yesterday');"
SQL_FDM="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);"
##加载数据
LOAD_FDM="
insert overwrite table fdm.itcast_fdm_user_wide partition(dt='$yesterday')
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
from bdm.itcast_bdm_user t where dt='$yesterday';"
SQL_GDM="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
) partitioned by (dt string);"
##加载数据到GDM
LOAD_GDM="insert overwrite table  gdm.itcast_gdm_user_basic partition(dt='$yesterday')
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
from (select * from fdm.itcast_fdm_user_wide where dt='$yesterday') t;"
##创建BDM层表
echo "${SQL_BDM}"
$SPARK_SUBMIT_INFO -e "${SQL_BDM}"
##添加数据到BDM
hdfs dfs -put $SOURCE_DATA/itcast_bdm_user.txt business/bdm/itcast_bdm_user/"dt=$yesterday"
##创建FDM层表
echo "${SQL_FDM}"
$SPARK_SUBMIT_INFO -e "${SQL_FDM}"
##导入数据到FDM
echo "${LOAD_FDM}"
$SPARK_SUBMIT_INFO -e "${LOAD_FDM}"
##创建GDM层表
echo "${SQL_GDM}"
$SPARK_SUBMIT_INFO -e "${SQL_GDM}"
##导入GDM数据
echo "${LOAD_GDM}"
$SPARK_SUBMIT_INFO -e "${LOAD_GDM}"`



推荐阅读
  • 基于PgpoolII的PostgreSQL集群安装与配置教程
    本文介绍了基于PgpoolII的PostgreSQL集群的安装与配置教程。Pgpool-II是一个位于PostgreSQL服务器和PostgreSQL数据库客户端之间的中间件,提供了连接池、复制、负载均衡、缓存、看门狗、限制链接等功能,可以用于搭建高可用的PostgreSQL集群。文章详细介绍了通过yum安装Pgpool-II的步骤,并提供了相关的官方参考地址。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 本文介绍了一个在线急等问题解决方法,即如何统计数据库中某个字段下的所有数据,并将结果显示在文本框里。作者提到了自己是一个菜鸟,希望能够得到帮助。作者使用的是ACCESS数据库,并且给出了一个例子,希望得到的结果是560。作者还提到自己已经尝试了使用"select sum(字段2) from 表名"的语句,得到的结果是650,但不知道如何得到560。希望能够得到解决方案。 ... [详细]
  • ALTERTABLE通过更改、添加、除去列和约束,或者通过启用或禁用约束和触发器来更改表的定义。语法ALTERTABLEtable{[ALTERCOLUMNcolu ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • 【shell】网络处理:判断IP是否在网段、两个ip是否同网段、IP地址范围、网段包含关系
    本文介绍了使用shell脚本判断IP是否在同一网段、判断IP地址是否在某个范围内、计算IP地址范围、判断网段之间的包含关系的方法和原理。通过对IP和掩码进行与计算,可以判断两个IP是否在同一网段。同时,还提供了一段用于验证IP地址的正则表达式和判断特殊IP地址的方法。 ... [详细]
  • Oracle10g备份导入的方法及注意事项
    本文介绍了使用Oracle10g进行备份导入的方法及相关注意事项,同时还介绍了2019年独角兽企业重金招聘Python工程师的标准。内容包括导出exp命令、删用户、创建数据库、授权等操作,以及导入imp命令的使用。详细介绍了导入时的参数设置,如full、ignore、buffer、commit、feedback等。转载来源于https://my.oschina.net/u/1767754/blog/377593。 ... [详细]
  • mysql-cluster集群sql节点高可用keepalived的故障处理过程
    本文描述了mysql-cluster集群sql节点高可用keepalived的故障处理过程,包括故障发生时间、故障描述、故障分析等内容。根据keepalived的日志分析,发现bogus VRRP packet received on eth0 !!!等错误信息,进而导致vip地址失效,使得mysql-cluster的api无法访问。针对这个问题,本文提供了相应的解决方案。 ... [详细]
  • 本文介绍了Java集合库的使用方法,包括如何方便地重复使用集合以及下溯造型的应用。通过使用集合库,可以方便地取用各种集合,并将其插入到自己的程序中。为了使集合能够重复使用,Java提供了一种通用类型,即Object类型。通过添加指向集合的对象句柄,可以实现对集合的重复使用。然而,由于集合只能容纳Object类型,当向集合中添加对象句柄时,会丢失其身份或标识信息。为了恢复其本来面貌,可以使用下溯造型。本文还介绍了Java 1.2集合库的特点和优势。 ... [详细]
  • 1Lock与ReadWriteLock1.1LockpublicinterfaceLock{voidlock();voidlockInterruptibl ... [详细]
  • 获取时间的函数js代码,js获取时区代码
    本文目录一览:1、js获取服务器时间(动态)2 ... [详细]
  • 生产环境下JVM调优参数的设置实例
     正文前先来一波福利推荐: 福利一:百万年薪架构师视频,该视频可以学到很多东西,是本人花钱买的VIP课程,学习消化了一年,为了支持一下女朋友公众号也方便大家学习,共享给大家。福利二 ... [详细]
  • linux时间字符串转正常时间 ... [详细]
  • 数据挖掘研讨课结束了,这门课的考核方法是每个同学根据班里面同学的课堂表现打分,然后老师再取截断平均值作为最后的分数。于是我就想,能否用p ... [详细]
author-avatar
wocaonima傻乎乎
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有