Helping the Industrial Internet of Things and the Service Domain of Industrial Big Data: Thematic Analysis of Petrol Stations 【26】

07: Service Domain: Petroleum Station Theme Analysis

  • Goal : Master the needs analysis of the topic of gas stations

  • path

    • step1: Requirements
    • step2: Analysis
  • implement

    • Requirements : Statistics of the results of the theme indicators of gas stations in different dimensions

      image-20211004095550115

    • analyze

      • Indicators : number of gas stations, number of new gas stations

      • dimension

        • Date dimensions: day, week, month
        • Gas station dimensions: type, province, city, region
        • Customer dimension: type, province
      • data sheet

        • fact sheet

          • fact_oil_station: oil station fact table

            select
                os_num,--油站个数
                current_new_os_num --新增油站个数
            from fact_oil_station;
            
          • dimension table

            • dim_oilstation: oil station dimension table

              select
                  id,--油站id
                  company_name,--公司名称
                  province_name,--省份名称
                  city_name,--城市名称
                  county_name,--区域名称
                  customer_classify_name,--客户名称
                  customer_province_name--客户省份
              from dim_oilstation;
              
            • dim_date: time dimension table

              select
                  date_id,--天
                  week_in_year_id,--周
                  year_month_id --月
              from dim_date;
              
  • Realize analysis

    select
    
           a.os_id,--油站id
    
           sum(a.os_num),--油站数量
    
           sum(a.current_new_os_num),--新增油站数量
    
           b.date_id,--天
    
           b.week_in_year_id,--周
    
           b.year_month_id, --月
    
           c.company_name,--公司名称
    
           c.province_name,--省份名称
    
           c.city_name,--城市名称
    
           c.county_name,--区域名称
    
           c.customer_classify_name,--客户名称
    
           c.customer_province_name--客户省份
    
       from fact_oil_station a
    
       join one_make_dws.dim_date b on a.dt = b.date_id
    
       join one_make_dws.dim_oilstation c on a.os_id = c.id
    
       group by
    
           b.date_id,--天
    
           b.week_in_year_id,--周
    
           b.year_month_id, --月
    
           c.company_name,--公司名称
    
           c.province_name,--省份名称
    
           c.city_name,--城市名称
    
           c.county_name,--区域名称
    
           c.customer_classify_name,--客户名称
    
           c.customer_province_name;--客户省份;
    
  • summary

    • Master the needs analysis of the topic of gas stations

08: Service Domain: Gas Station Theme Realization

  • Goal : Realize the construction of dimension indicators for the theme table of gas stations

  • implement

    • build table

      -- 创建油站主题表
      drop table if exists one_make_st.subj_oilstation;
      create table if not exists one_make_st.subj_oilstation(
          sum_osnum bigint comment '油站数量'
          ,sumnew_osnum int comment '新增油站数量'
          ,dws_day string comment '日期维度-按天'
          ,dws_week string comment '日期维度-按周'
          ,dws_month string comment '日期维度-按月'
          ,oil_type string comment '油站维度-油站类型'
          ,oil_province string comment '油站维度-油站所属省'
          ,oil_city string comment '油站维度-油站所属市'
          ,oil_county string comment '油站维度-油站所属区'
          ,customer_classify string comment '客户维度-客户类型'
          ,customer_province string comment '客户维度-客户所属省'
      ) comment '油站主题表'
      partitioned by (month String, week String, day String)
      stored as orc
      location '/data/dw/st/one_make/subj_oilstation';
      
    • Construct

      insert overwrite table one_make_st.subj_oilstation partition(month = '202101', week='2021W1', day='20210101')
      select
          sum(oil.os_num) sum_osnum,                          --油站数量
      	sum(oil.current_new_os_num) sumnew_osnum,           --新增油站数量
          dd.date_id dws_day,                                 --日期天
      	dd.week_in_year_id dws_week,                        --日期周
      	dd.year_month_id dws_month,                         --日期月
          dimoil.company_name oil_type,                       --油站类型
      	dimoil.province_name oil_province,                  --油站省份
      	dimoil.city_name oil_city,                          --油站城市
          dimoil.county_name oil_county,                      --油站区域
      	dimoil.customer_classify_name customer_classify,    --客户类型
          dimoil.customer_province_name customer_province     --客户省份
      --油站事务事实表
      from one_make_dwb.fact_oil_station oil
      --关联日期维度表
      left join one_make_dws.dim_date dd on oil.dt = dd.date_id
      --关联油站维度表
      left join one_make_dws.dim_oilstation dimoil on oil.os_id = dimoil.id
      where dd.year_month_id = '202101'and dd.week_in_year_id = '2021W1' and  dd.date_id = '20210101'
      --按照维度字段分组
      group by dd.date_id, dd.week_in_year_id, dd.year_month_id,  dimoil.company_name, dimoil.province_name, dimoil.city_name, dimoil.county_name, dimoil.customer_classify_name, dimoil.customer_province_name;
      
  • summary

    • Realize the dimension index construction of the theme table of gas stations

Guess you like

Origin blog.csdn.net/xianyu120/article/details/132062705