産業用モノのインターネットと産業用ビッグデータのサービス領域を支援:ガソリンスタンドのテーマ別分析【26】

07: サービスドメイン: 石油ステーションのテーマ分析

  • 目標ガソリンスタンドのニーズ分析をマスターする

    • ステップ1: 要件
    • step2: 分析
  • 埋め込む

    • 要件: ガソリンスタンドのテーマ指標の結果を異なる次元で統計

      画像-20211004095550115

    • 分析する

      • 指標:ガソリンスタンド数、新規ガソリンスタンド数

      • 寸法

        • 日付の次元: 日、週、月
        • ガソリン スタンドのディメンション: タイプ、州、都市、地域
        • 顧客のディメンション: タイプ、都道府県
      • データシート

        • ファクトシート

          • fat_oil_station: 石油ステーション ファクト テーブル

            select
                os_num,--油站个数
                current_new_os_num --新增油站个数
            from fact_oil_station;
            
          • 寸法表

            • dim_oilstation: オイル ステーションの寸法表

              select
                  id,--油站id
                  company_name,--公司名称
                  province_name,--省份名称
                  city_name,--城市名称
                  county_name,--区域名称
                  customer_classify_name,--客户名称
                  customer_province_name--客户省份
              from dim_oilstation;
              
            • dim_date: 時間ディメンション テーブル

              select
                  date_id,--天
                  week_in_year_id,--周
                  year_month_id --月
              from dim_date;
              
  • 分析を実現する

    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;--客户省份;
    
  • まとめ

    • ガソリンスタンドのニーズ分析をマスターする

08: サービスドメイン:ガソリンスタンドのテーマ実現

  • 目標:ガソリンスタンドのテーマテーブルの寸法インジケーターの構築を実現する

  • 埋め込む

    • テーブルを構築する

      -- 创建油站主题表
      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';
      
    • 構築する

      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;
      
  • まとめ

    • ガソリンスタンドのテーマテーブルのディメンションインデックス構築を実現

おすすめ

転載: blog.csdn.net/xianyu120/article/details/132062705