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}"

SparkSQL电商用户画像(五)之用户画像开发(客户基本属性表)的更多相关文章

  1. SparkSQL电商用户画像(三)之环境准备

    五. 电商用户画像环境搭建 众所周知,Hive的执行任务是将hql语句转化为MapReduce来计算的,Hive的整体解决方案很不错,但是从查询提交到结果返回需要相当长的时间,查询耗时太长.这个主要原 ...

  2. SparkSQL电商用户画像(二)之如何构建画像

    四. 如何构建电商用户画像 4.1 构建电商用户画像技术和流程 构建一个用户画像,包括数据源端数据收集.数据预处理.行为建模.构建用户画像 有些标签是可以直接获取到的,有些标签需要通过数据挖掘分析到! ...

  3. SparkSQL电商用户画像(四)之电商用户画像数据仓库建立

    六.  电商用户画像数据仓库建立 7.1  数据仓库准备工作 为什么要对数据仓库分层?星型模型 雪花模型 User----->web界面展示指标表 l    用空间换时间,通过大量的预处理来提升 ...

  4. Flink SQL结合Kafka、Elasticsearch、Kibana实时分析电商用户行为

    body { margin: 0 auto; font: 13px / 1 Helvetica, Arial, sans-serif; color: rgba(68, 68, 68, 1); padd ...

  5. Spark项目之电商用户行为分析大数据平台之(一)项目介绍

    一.项目概述 本项目主要用于互联网电商企业中,使用Spark技术开发的大数据统计分析平台,对电商网站的各种用户行为(访问行为.购物行为.广告点击行为等)进行复杂的分析.用统计分析出来的数据,辅助公司中 ...

  6. Spark项目之电商用户行为分析大数据平台之(六)用户访问session分析模块介绍

    一.对用户访问session进行分析 1.可以根据使用者指定的某些条件,筛选出指定的一些用户(有特定年龄.职业.城市): 2.对这些用户在指定日期范围内发起的session,进行聚合统计,比如,统计出 ...

  7. Spark项目之电商用户行为分析大数据平台之(五)实时数据采集

  8. Spark大型项目实战:电商用户行为分析大数据平台

    本项目主要讲解了一套应用于互联网电商企业中,使用Java.Spark等技术开发的大数据统计分析平台,对电商网站的各种用户行为(访问行为.页面跳转行为.购物行为.广告点击行为等)进行复杂的分析.用统计分 ...

  9. Spark项目之电商用户行为分析大数据平台之(十二)Spark上下文构建及模拟数据生成

    一.模拟生成数据 package com.bw.test; import java.util.ArrayList; import java.util.Arrays; import java.util. ...

随机推荐

  1. 解决linux sudo apt-get install xx是2出现无法定位软件包方法

    解决办法: 在etc/apt/sources.list最后一行添加 deb http://archive.ubuntu.com/ubuntu/ trusty main universe restric ...

  2. “/”应用程序中的服务器错误。||分析器错误消息: 未能加载类型“WebApplication1._Default”

    环境VS2008 无法运行WEB项目,Winfrom程序OK. 新创建的WEB项目直接运行报下图错误. 尝试多种方法: 1,重新生成项目,运行.(失败) 2,重装VS2008(默认.完全.自定义)安装 ...

  3. 图解 | 原来这就是 class

    我是一个 .java 文件,名叫 FlashObject.java,叫我小渣就行. public class FlashObject {    private String name;    priv ...

  4. 生产环境中mysql数据库由主从关系切换为主主关系

    目录 一.清除原从数据库数据及主从关系 1.1.关闭主从数据库原有的主从关系 1.2.清除从数据库原有数据 二.将主库上的数据备份到从库 2.1.备份主库数据到从库 2.2.在从库使用tsc.sql文 ...

  5. JS基础学习第四天

    对象(Object) 对象是JS中的引用数据类型对象是一种复合数据类型,在对象中可以保存多个不同数据类型的属性使用typeof检查一个对象时,会返回object 对象的分类: 1.内建对象- 由ES标 ...

  6. Windows Server 2016不小心卸载了.NET Framwork4.6后服务器管理器等功能都不能用的解决方案

    之前卸载IIS的时候手贱把.NET FrameWork 4.6给卸载了,下面有一个比较简单的恢复方法. 可以尝试一下通过cmd命令DISM启用.NET 4.6:1. 首先运行如下命令查看当前的功能安装 ...

  7. 强大的 Guava 工具类

    Java 开发的同学应该都使用或者听说过 Google 提供的 Guava 工具包.日常使用最多的肯定是集合相关的工具类,还有 Guava cache,除了这些之外 Guava 还提供了很多有用的功能 ...

  8. BUAA防脱发第一抗连——团队介绍

    项目 内容 这个作业属于哪个课程 2021学年春季软件工程(罗杰 任健) 这个作业的要求在哪里 团队项目-团队介绍 我在这个课程的目标是 锻炼在大规模开发中的团队协作能力 这个作业在哪个具体方面帮助我 ...

  9. 如何在IDEA中进行时序图分析

    方法一: 使用插件 SequenceDiagram (系统自动生成) 使用方法: 下载插件,我们可以在 Plugins 中找到 选中线程方法名,然后右键就可以创建此方法的时序图了 参数设置 生成效果以 ...

  10. 在Visual Studio 中使用git——什么是Git(一)

    写程序必然需要版本控制,哪怕是个人项目也是必须的,微软从Visual Studio 2019开始默认提供了对Git的支持,Visual Studio 2019之前的版本可以安装相应的插件来实现Git功 ...