当前位置:   article > 正文

五、数据仓库电商项目——DWT层、可与DWS合并一层_数据仓库分层,dwd、dws这两层是否可以放一块

数据仓库分层,dwd、dws这两层是否可以放一块

DWT层 

DWT层将DWS层每日聚合的数据进行积累,DWT层不是分区表,是一个累积型全量表,并且数据来源与DWS层。

累积性全量表:查询要改动的旧数据,查询新增和变化的新数据,新旧关联,以新换旧,导入覆盖。

DWT设备主题宽表

在这里插入图片描述

用户主题宽表

 

  1. drop table if exists dwt_user_topic;
  2. create external table dwt_user_topic
  3. (
  4. user_id string comment '用户id',
  5. login_date_first string comment '首次登录时间',
  6. login_date_last string comment '末次登录时间',
  7. login_count bigint comment '累积登录天数',
  8. login_last_30d_count bigint comment '最近30日登录天数',
  9. order_date_first string comment '首次下单时间',
  10. order_date_last string comment '末次下单时间',
  11. order_count bigint comment '累积下单次数',
  12. order_amount decimal(16,2) comment '累积下单金额',
  13. order_last_30d_count bigint comment '最近30日下单次数',
  14. order_last_30d_amount bigint comment '最近30日下单金额',
  15. payment_date_first string comment '首次支付时间',
  16. payment_date_last string comment '末次支付时间',
  17. payment_count decimal(16,2) comment '累积支付次数',
  18. payment_amount decimal(16,2) comment '累积支付金额',
  19. payment_last_30d_count decimal(16,2) comment '最近30日支付次数',
  20. payment_last_30d_amount decimal(16,2) comment '最近30日支付金额'
  21. )COMMENT '用户主题宽表'
  22. stored as parquet
  23. location '/warehouse/gmall/dwt/dwt_user_topic/'
  24. tblproperties ("parquet.compression"="lzo");
  25. insert overwrite table dwt_user_topic
  26. select
  27. nvl(new.user_id,old.user_id),
  28. if(old.login_date_first is null and new.login_count>0,'2020-03-29',old.login_date_first),
  29. if(new.login_count>0,'2020-03-29',old.login_date_last),
  30. nvl(old.login_count,0)+if(new.login_count>0,1,0),
  31. nvl(new.login_last_30d_count,0),
  32. if(old.order_date_first is null and new.order_count>0,'2020-03-29',old.order_date_first),
  33. if(new.order_count>0,'2020-03-29',old.order_date_last),
  34. nvl(old.order_count,0)+nvl(new.order_count,0),
  35. nvl(old.order_amount,0)+nvl(new.order_amount,0),
  36. nvl(new.order_last_30d_count,0),
  37. nvl(new.order_last_30d_amount,0),
  38. if(old.payment_date_first is null and new.payment_count>0,'2020-03-29',old.payment_date_first),
  39. if(new.payment_count>0,'2020-03-29',old.payment_date_last),
  40. nvl(old.payment_count,0)+nvl(new.payment_count,0),
  41. nvl(old.payment_amount,0)+nvl(new.payment_amount,0),
  42. nvl(new.payment_last_30d_count,0),
  43. nvl(new.payment_last_30d_amount,0)
  44. from
  45. dwt_user_topic old
  46. full outer join
  47. (
  48. select
  49. user_id,
  50. sum(if(dt='2020-03-29',login_count,0)) login_count,
  51. sum(if(dt='2020-03-29',order_count,0)) order_count,
  52. sum(if(dt='2020-03-29',order_amount,0)) order_amount,
  53. sum(if(dt='2020-03-29',payment_count,0)) payment_count,
  54. sum(if(dt='2020-03-29',payment_amount,0)) payment_amount,
  55. sum(if(login_count>0,1,0)) login_last_30d_count,
  56. sum(order_count) order_last_30d_count,
  57. sum(order_amount) order_last_30d_amount,
  58. sum(payment_count) payment_last_30d_count,
  59. sum(payment_amount) payment_last_30d_amount
  60. from dws_user_action_daycount
  61. where dt>=date_add( '2020-03-29',-30)
  62. group by user_id
  63. )new
  64. on old.user_id=new.user_id;

商品主题宽表

  1. hive (gmall)>
  2. drop table if exists dwt_sku_topic;
  3. create external table dwt_sku_topic
  4. (
  5. sku_id string comment 'sku_id',`在这里插入代码片`
  6. spu_id string comment 'spu_id',
  7. order_last_30d_count bigint comment '最近30日被下单次数',
  8. order_last_30d_num bigint comment '最近30日被下单件数',
  9. order_last_30d_amount decimal(16,2) comment '最近30日被下单金额',
  10. order_count bigint comment '累积被下单次数',
  11. order_num bigint comment '累积被下单件数',
  12. order_amount decimal(16,2) comment '累积被下单金额',
  13. payment_last_30d_count bigint comment '最近30日被支付次数',
  14. payment_last_30d_num bigint comment '最近30日被支付件数',
  15. payment_last_30d_amount decimal(16,2) comment '最近30日被支付金额',
  16. payment_count bigint comment '累积被支付次数',
  17. payment_num bigint comment '累积被支付件数',
  18. payment_amount decimal(16,2) comment '累积被支付金额',
  19. refund_last_30d_count bigint comment '最近三十日退款次数',
  20. refund_last_30d_num bigint comment '最近三十日退款件数',
  21. refund_last_30d_amount decimal(10,2) comment '最近三十日退款金额',
  22. refund_count bigint comment '累积退款次数',
  23. refund_num bigint comment '累积退款件数',
  24. refund_amount decimal(10,2) comment '累积退款金额',
  25. cart_last_30d_count bigint comment '最近30日被加入购物车次数',
  26. cart_last_30d_num bigint comment '最近30日被加入购物车件数',
  27. cart_count bigint comment '累积被加入购物车次数',
  28. cart_num bigint comment '累积被加入购物车件数',
  29. favor_last_30d_count bigint comment '最近30日被收藏次数',
  30. favor_count bigint comment '累积被收藏次数',
  31. appraise_last_30d_good_count bigint comment '最近30日好评数',
  32. appraise_last_30d_mid_count bigint comment '最近30日中评数',
  33. appraise_last_30d_bad_count bigint comment '最近30日差评数',
  34. appraise_last_30d_default_count bigint comment '最近30日默认评价数',
  35. appraise_good_count bigint comment '累积好评数',
  36. appraise_mid_count bigint comment '累积中评数',
  37. appraise_bad_count bigint comment '累积差评数',
  38. appraise_default_count bigint comment '累积默认评价数'
  39. )COMMENT '商品主题宽表'
  40. stored as parquet
  41. location '/warehouse/gmall/dwt/dwt_sku_topic/'
  42. tblproperties ("parquet.compression"="lzo");
  1. INSERT OVERWRITE INTO dwt_sku_topic
  2. SELECT nvl(new.sku_id, old.sku_id), dwd_dim_sku_info.spu_id
  3. , nvl(new.order_count30, 0)
  4. , nvl(new.order_num30, 0)
  5. , nvl(new.order_amount30, 0)
  6. , nvl(old.order_count, 0) + nvl(new.order_count, 0)
  7. , nvl(old.order_num, 0) + nvl(new.order_num, 0)
  8. , nvl(old.order_amount, 0) + nvl(new.order_amount, 0)
  9. , nvl(new.payment_count30, 0)
  10. , nvl(new.payment_num30, 0)
  11. , nvl(new.payment_amount30, 0)
  12. , nvl(old.payment_count, 0) + nvl(new.payment_count, 0)
  13. , nvl(old.payment_num, 0) + nvl(new.payment_count, 0)
  14. , nvl(old.payment_amount, 0) + nvl(new.payment_count, 0)
  15. , nvl(new.refund_count30, 0)
  16. , nvl(new.refund_num30, 0)
  17. , nvl(new.refund_amount30, 0)
  18. , nvl(old.refund_count, 0) + nvl(new.refund_count, 0)
  19. , nvl(old.refund_num, 0) + nvl(new.refund_num, 0)
  20. , nvl(old.refund_amount, 0) + nvl(new.refund_amount, 0)
  21. , nvl(new.cart_count30, 0)
  22. , nvl(new.cart_num30, 0)
  23. , nvl(old.cart_count, 0) + nvl(new.cart_count, 0)
  24. , nvl(old.cart_num, 0) + nvl(new.cart_num, 0)
  25. , nvl(new.favor_count30, 0)
  26. , nvl(old.favor_count, 0) + nvl(new.favor_count, 0)
  27. , nvl(new.appraise_good_count30, 0)
  28. , nvl(new.appraise_mid_count30, 0)
  29. , nvl(new.appraise_bad_count30, 0)
  30. , nvl(new.appraise_default_count30, 0)
  31. , nvl(old.appraise_good_count, 0) + nvl(new.appraise_good_count, 0)
  32. , nvl(old.appraise_mid_count, 0) + nvl(new.appraise_mid_count, 0)
  33. , nvl(old.appraise_bad_count, 0) + nvl(new.appraise_bad_count, 0)
  34. , nvl(old.appraise_default_count, 0) + nvl(new.appraise_default_count, 0)
  35. FROM (
  36. SELECT sku_id, spu_id, order_last_30d_count, order_last_30d_num, order_last_30d_amount
  37. , order_count, order_num, order_amount, payment_last_30d_count, payment_last_30d_num
  38. , payment_last_30d_amount, payment_count, payment_num, payment_amount, refund_last_30d_count
  39. , refund_last_30d_num, refund_last_30d_amount, refund_count, refund_num, refund_amount
  40. , cart_last_30d_count, cart_last_30d_num, cart_count, cart_num, favor_last_30d_count
  41. , favor_count, appraise_last_30d_good_count, appraise_last_30d_mid_count, appraise_last_30d_bad_count, appraise_last_30d_default_count
  42. , appraise_good_count, appraise_mid_count, appraise_bad_count, appraise_default_count
  43. FROM dwt_sku_topic
  44. ) old
  45. FULL JOIN (
  46. SELECT sku_id
  47. , sum(if(dt = '2020-03-29', order_count, 0)) AS order_count
  48. , sum(if(dt = '2020-03-29', order_num, 0)) AS order_num
  49. , sum(if(dt = '2020-03-29', order_amount, 0)) AS order_amount
  50. , sum(if(dt = '2020-03-29', payment_count, 0)) AS payment_count
  51. , sum(if(dt = '2020-03-29', payment_num, 0)) AS payment_num
  52. , sum(if(dt = '2020-03-29', payment_amount, 0)) AS payment_amount
  53. , sum(if(dt = '2020-03-29', refund_count, 0)) AS refund_count
  54. , sum(if(dt = '2020-03-29', refund_num, 0)) AS refund_num
  55. , sum(if(dt = '2020-03-29', refund_amount, 0)) AS refund_amount
  56. , sum(if(dt = '2020-03-29', cart_count, 0)) AS cart_count
  57. , sum(if(dt = '2020-03-29', cart_num, 0)) AS cart_num
  58. , sum(if(dt = '2020-03-29', favor_count, 0)) AS favor_count
  59. , sum(if(dt = '2020-03-29', appraise_good_count, 0)) AS appraise_good_count
  60. , sum(if(dt = '2020-03-29', appraise_mid_count, 0)) AS appraise_mid_count
  61. , sum(if(dt = '2020-03-29', appraise_bad_count, 0)) AS appraise_bad_count
  62. , sum(if(dt = '2020-03-29', appraise_default_count, 0)) AS appraise_default_count
  63. , sum(order_count) AS order_count30, sum(order_num) AS order_num30
  64. , sum(order_amount) AS order_amount30, sum(payment_count) AS payment_count30
  65. , sum(payment_num) AS payment_num30, sum(payment_amount) AS payment_amount30
  66. , sum(refund_count) AS refund_count30, sum(refund_num) AS refund_num30
  67. , sum(refund_amount) AS refund_amount30, sum(cart_count) AS cart_count30
  68. , sum(cart_num) AS cart_num30, sum(favor_count) AS favor_count30
  69. , sum(appraise_good_count) AS appraise_good_count30, sum(appraise_mid_count) AS appraise_mid_count30
  70. , sum(appraise_bad_count) AS appraise_bad_count30, sum(appraise_default_count) AS appraise_default_count30
  71. FROM dws_sku_action_daycount
  72. WHERE dt >= date_add('2020-03-29', -30)
  73. GROUP BY sku_id
  74. ) new
  75. ON new.sku_id = old.sku_id
  76. LEFT JOIN dwd_dim_sku_info ON new.sku_id = dwd_dim_sku_info.id;

 优惠券主题宽表(预留)

在这里插入图片描述

活动主题宽表(预留) 

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/561830
推荐阅读
相关标签
  

闽ICP备14008679号