栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

cube数据立方体模型

cube数据立方体模型

 多维立方体建表语句
-- 多维分析数据立方体,建表
DROp TABLE IF EXISTS dws.mall_app_tfc_cube;
CREATE TABLE dws.mall_app_tfc_cube
(
    appid              string,
    appversion         string,
    carrier            string,  -- 运营商
    devicetype         string,  -- 手机型号
    nettype            string,
    osname             string,
    osversion          string,
    releasechannel     string,
    resolution         string,
    province           string,   -- 省
    city               string,   -- 市
    region           string,   -- 区
    ses_enter_page_id  string, -- 入口页面id
    ses_exit_page_id   string, -- 退出页面id
    ses_is_jump        int   ,  -- 1:是跳出会话  2:不是跳出会话

    pv_cnt             bigint,  -- 访问页面数
    uv_nct             bigint,  -- 去重访客总数
    ses_cnt            bigint   -- 访问的总时长
)
    PARTITIonED BY (dt string)
    STORED AS ORC
    TBLPROPERTIES ('orc.compress'='snappy')
;
数据计算方式


-- 计算
INSERT INTO TABLE dws.mall_app_tfc_cube PARTITION (dt='2022-02-12')
SELECT
    appid
     ,appversion
     ,carrier
     ,devicetype
     ,nettype
     ,osname
     ,osversion
     ,releasechannel
     ,resolution
     ,province
     ,city
     ,region
     ,ses_enter_page_id
     ,ses_exit_page_id
     ,ses_is_jump
     ,count(if(eventid='pageView',1,null)) as pv_cnt
     ,count(distinct guid) as uv_cnt
     ,count(distinct sessionid)  as ses_cnt
FROM dws.mall_app_tfc_wt
WHERe dt='2022-02-12'
GROUP BY
    appid
       ,appversion
       ,carrier
       ,devicetype
       ,nettype
       ,osname
       ,osversion
       ,releasechannel
       ,resolution
       ,province
       ,city
       ,region
       ,ses_enter_page_id
       ,ses_exit_page_id
       ,ses_is_jump
    GROUPING SETS (
       (),
       (province,city,region),
       (province,city),
       (province),
       (devicetype),
       (osname),
       (ses_enter_page_id),
       (ses_exit_page_id),
       (appid),
       (appid,appversion),
       (carrier),
       (carrier,nettype),
       (nettype)
    );

使用方式 coalesce升级版的nvl

-- cube表的取数示例
-- 各退出页面下的pv数,uv数,会话数
select
    ses_exit_page_id
     ,pv_cnt
     ,uv_nct
     ,ses_cnt
from dws.mall_app_tfc_cube
where dt='2022-02-12'
  and ses_exit_page_id is not null
  and coalesce(
        appid
    ,appversion
    ,carrier
    ,devicetype
    ,nettype
    ,osname
    ,osversion
    ,releasechannel
    ,resolution
    ,province
    ,city
    ,region
    ,ses_enter_page_id
    ,ses_is_jump
    )  is null
;


-- 各手机型号下的pv数,uv数,会话数
select
    devicetype
     ,pv_cnt
     ,uv_nct
     ,ses_cnt
from dws.mall_app_tfc_cube
where dt='2022-02-12'
  and devicetype is not null
  and coalesce(
        appid
    ,appversion
    ,carrier
    ,nettype
    ,osname
    ,osversion
    ,releasechannel
    ,resolution
    ,province
    ,city
    ,region
    ,ses_enter_page_id
    ,ses_exit_page_id
    ,ses_is_jump
    )  is null
;

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/745613.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号