大数据数据仓库实战项目-电商数仓教程V3.0---快速建表


数据加载脚本见 https://blog.csdn.net/qq_44852767/article/details/108666556

ods层

用户行为数据

-- 日志表
drop table if exists ods_log;
CREATE EXTERNAL TABLE ods_log (`line` string)
PARTITIONED BY (`dt` string) -- 按照时间创建分区
STORED AS -- 指定存储方式,读数据采用 LzoTextInputFormat; INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION '/warehouse/gmall/ods/ods_log'	-- 指定数据在 hdfs 上的存储位置
;

业务数据

一次性创建23张表

-- 1 订单表(增量及更新)
drop table if exists ods_order_info;
create external table ods_order_info ( 
    `id` string COMMENT '订单号', 
    `final_total_amount` decimal(10,2) COMMENT '订单金额', 
    `order_status` string COMMENT '订单状态', 
    `user_id` string COMMENT '用户 id', 
    `out_trade_no` string COMMENT '支付流水号', 
    `create_time` string COMMENT '创建时间', 
    `operate_time` string COMMENT '操作时间', 
    `province_id` string COMMENT '省份 ID', 
    `benefit_reduce_amount` decimal(10,2) COMMENT '优惠金额', 
    `original_total_amount` decimal(10,2) COMMENT '原价金额', 
    `feight_fee` decimal(10,2) COMMENT '运费' 
) COMMENT '订单表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_order_info/';
 

-- 2 订单详情表(增量)

 
drop table if exists ods_order_detail; 
create external table ods_order_detail( 
    `id` string COMMENT '订单编号', 
    `order_id` string COMMENT '订单号', 
    `user_id` string COMMENT '用户 id', 
    `sku_id` string COMMENT '商品 id', 
    `sku_name` string COMMENT '商品名称', 
    `order_price` decimal(10,2) COMMENT '商品价格', 
    `sku_num` bigint COMMENT '商品数量', `create_time` string COMMENT '创建时间' 
) COMMENT '订单详情表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_order_detail/';
 

-- 3 SKU 商品表(全量)

 
drop table if exists ods_sku_info; 
create external table ods_sku_info( 
    `id` string COMMENT 'skuId', 
    `spu_id` string COMMENT 'spuid', 
    `price` decimal(10,2) COMMENT '价格', 
    `sku_name` string COMMENT '商品名称', 
    `sku_desc` string COMMENT '商品描述', 
    `weight` string COMMENT '重量', 
    `tm_id` string COMMENT '品牌 id', 
    `category3_id` string COMMENT '品类 id', 
    `create_time` string COMMENT '创建时间' 
) COMMENT 'SKU 商品表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
location '/warehouse/gmall/ods/ods_sku_info/';
 

-- 4  用户表(增量及更新)

 
drop table if exists ods_user_info; 
create external table ods_user_info( 
    `id` string COMMENT '用户 id', 
    `name` string COMMENT '姓名', 
    `birthday` string COMMENT '生日', 
    `gender` string COMMENT '性别', 
    `email` string COMMENT '邮箱', 
    `user_level` string COMMENT '用户等级', 
    `create_time` string COMMENT '创建时间', 
    `operate_time` string COMMENT '操作时间' 
) COMMENT '用户表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_user_info/';
 

-- 5 商品一级分类表(全量)

 
drop table if exists ods_base_category1; 
create external table ods_base_category1( 
    `id` string COMMENT 'id', 
    `name` string COMMENT '名称' 
) COMMENT '商品一级分类表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_base_category1/';
 

-- 6 商品二级分类表(全量)

 
drop table if exists ods_base_category2; 
create external table ods_base_category2( 
    `id` string COMMENT ' id', 
    `name` string COMMENT '名称', 
    category1_id string COMMENT '一级品类 id' 
) COMMENT '商品二级分类表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_base_category2/';
 



-- 7 商品三级分类表(全量)

 
drop table if exists ods_base_category3; 
create external table ods_base_category3( 
    `id` string COMMENT ' id', 
    `name` string COMMENT '名称', 
    category2_id string COMMENT '二级品类 id'
    ) COMMENT '商品三级分类表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_base_category3/';
 

-- 8 支付流水表(增量)

 
drop table if exists ods_payment_info; 
create external table ods_payment_info( 
    `id` bigint COMMENT '编号', 
    `out_trade_no` string COMMENT '对外业务编号', 
    `order_id` string COMMENT '订单编号', 
    `user_id` string COMMENT '用户编号', 
    `alipay_trade_no` string COMMENT '支付宝交易流水编号', 
    `total_amount` decimal(16,2) COMMENT '支付金额', 
    `subject` string COMMENT '交易内容', 
    `payment_type` string COMMENT '支付类型', 
    `payment_time` string COMMENT '支付时间' 
) COMMENT '支付流水表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_payment_info/';
 

-- 9 省份表(特殊)

 
drop table if exists ods_base_province; 
create external table ods_base_province ( 
    `id` bigint COMMENT '编号', 
    `name` string COMMENT '省份名称', 
    `region_id` string COMMENT '地区 ID', 
    `area_code` string COMMENT '地区编码', 
    `iso_code` string COMMENT 'iso 编码' 
    ) COMMENT '省份表' 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_base_province/';
 

-- 10 地区表(特殊)

drop table if exists ods_base_region; 
create external table ods_base_region ( 
    `id` bigint COMMENT '编号', 
    `region_name` string COMMENT '地区名称' 
    ) COMMENT '地区表' 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_base_region/';
 

-- 11 品牌表(全量)

drop table if exists ods_base_trademark; 
create external table ods_base_trademark ( 
    `tm_id` bigint COMMENT '编号', 
    `tm_name` string COMMENT '品牌名称' 
    ) COMMENT '品牌表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_base_trademark/';
 

-- 12 订单状态表(增量)
 
drop table if exists ods_order_status_log; 
create external table ods_order_status_log ( 
    `id` bigint COMMENT '编号', 
    `order_id` string COMMENT '订单 ID', 
    `order_status` string COMMENT '订单状态', 
    `operate_time` string COMMENT '修改时间' 
    ) COMMENT '订单状态表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_order_status_log/';
 


-- 13 SPU 商品表(全量)
 
drop table if exists ods_spu_info; 
create external table ods_spu_info( 
    `id` string COMMENT 'spuid', 
    `spu_name` string COMMENT 'spu 名称', 
    `category3_id` string COMMENT '品类 id', 
    `tm_id` string COMMENT '品牌 id' 
    ) COMMENT 'SPU 商品表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_spu_info/';
 

-- 14 商品评论表(增量)

drop table if exists ods_comment_info; 
create external table ods_comment_info( 
    `id` string COMMENT '编号', 
    `user_id` string COMMENT '用户 ID', 
    `sku_id` string COMMENT '商品 sku', 
    `spu_id` string COMMENT '商品 spu', 
    `order_id` string COMMENT '订单 ID', 
    `appraise` string COMMENT '评价', 
    `create_time` string COMMENT '评价时间'
    ) COMMENT '商品评论表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_comment_info/';
 

-- 15 退单表(增量)

drop table if exists ods_order_refund_info; 
create external table ods_order_refund_info( 
    `id` string COMMENT '编号', 
    `user_id` string COMMENT '用户 ID', 
    `order_id` string COMMENT '订单 ID', 
    `sku_id` string COMMENT '商品 ID', 
    `refund_type` string COMMENT '退款类型', 
    `refund_num` bigint COMMENT '退款件数', 
    `refund_amount` decimal(16,2) COMMENT '退款金额', 
    `refund_reason_type` string COMMENT '退款原因类型', 
    `create_time` string COMMENT '退款时间' ) COMMENT '退单表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_order_refund_info/';
 

-- 16 加购表(全量)

drop table if exists ods_cart_info; 
create external table ods_cart_info( 
    `id` string COMMENT '编号', 
    `user_id` string COMMENT '用户 id', 
    `sku_id` string COMMENT 'skuid', 
    `cart_price` string COMMENT '放入购物车时价格', 
    `sku_num` string COMMENT '数量', 
    `sku_name` string COMMENT 'sku 名称 (冗余)', 
    `create_time` string COMMENT '创建时间', 
    `operate_time` string COMMENT '修改时间', 
    `is_ordered` string COMMENT '是否已经下单', 
    `order_time` string COMMENT '下单时间' 
    ) COMMENT '加购表' 
PARTITIONED BY (`dt` string) 
row format delimited fields terminated by '\t' 
STORED AS 
    INPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat' 
    OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat' 
location '/warehouse/gmall/ods/ods_cart_info/';



-- 17 商品收藏表(全量)

drop table if exists ods_favor_info; 
create external table ods_favor_info( 
    `id` string COMMENT '编号', 
    `user_id` string COMMENT '用户 id', 
    `sku_id` string COMMENT 'skuid',
    `spu_id` string COMMENT '
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值