美文网首页
长表开发模式样例

长表开发模式样例

作者: lwmxa | 来源:发表于2020-01-01 22:17 被阅读0次

三段式开发:

一、开头

====step:0====

drop table if exists platform_temp.sr_dw_commodity_item_info_base_${dt};

create table platform_temp.sr_dw_commodity_item_info_base_${dt}

(

  `commodity_id` bigint,

  `attr_key` string,

  `attr_value` string

)

PARTITIONED BY

(

  `step` string

)

;

说明:

建立类似长表的临时分区表,作为中间过渡层,以便独立开发各个指标,最后汇总。

临时分区表为了支持并发刷数据,拼接了日期参数在表名中。

二、中间

====step:1====

drop table if exists platform_temp.sr_dw_commodity_item_info_base_category_01_${dt};

create table platform_temp.sr_dw_commodity_item_info_base_category_01_${dt}

as

select ……; --宽表

====step:1====

drop table if exists platform_temp.sr_dw_commodity_item_info_base_category_02_${dt};

create table platform_temp.sr_dw_commodity_item_info_base_category_02_${dt}

as

select ……; --宽表

====step:2====

insert overwrite table platform_temp.sr_dw_commodity_item_info_base_${dt} partition(step='category_info')

select

    commodity_id,

    'category_info' as attr_key,

    category_info attr_value

from

(

    select ……

    from

        platform_temp.sr_dw_commodity_item_info_base_category_01_${dt} t1

    left join

        platform_temp.sr_dw_commodity_item_info_base_category_02_${dt} t2

    on ……

)tt

;

====step:1====

insert overwrite table platform_temp.sr_dw_commodity_item_info_base_${dt} partition(step='item_sku')

select

    commodity_id,

    split(index,'=:=')[0] as attr_key,

    split(index,'=:=')[1] as attr_value

from ……;

说明:

1.中间层可以建立很多常规的临时宽表作为过渡表方便数据处理;

2.中间层每个step分区作为一个指标集开发空间,互相独立可以设置为并发执行;

3.一张宽表的多个字段提取需要用到列转行,拼接处理时用到符号“=:=”,因为可能处理的是一个字符类型的字段,其中很可能包含如“=”、“#”等简单字符,在split处理时会分隔异常。

三、结尾

====step:3====

insert overwrite table platform_dw.platform_dw_sr_dw_user_item_info partition(dt='${day}',label='base')

select

    user_id,attr_key,attr_value

from

    platform_temp.sr_dw_user_item_info_base_${dt} t1

left semi join

(

    select user_id from platform_dw.platform_dw_sr_dw_user_main

    where dt='${day}'

) t2

on t1.user_id = t2.user_id

where nvl(trim(attr_value),'')<>''

;

insert overwrite table platform_dw.platform_dw_sr_dw_feature_log partition(dt='${day}',label='base')

select

   attr_key,

   count(*) as coverage,

   from_unixtime(unix_timestamp()) as update_time

from

(

    select attr_key,user_id from platform_dw.platform_dw_sr_dw_user_item_info

    where dt='${day}'and label='base'

) t

group by attr_key

;

说明:

1.因为中间表和目标表都是长表,所以不限制分区就可以直接取到所有中间结果,不用关联,性能高效。

2.将临时分区表中的数据主键关联各大维度的主表,限制记录数后直接插入到开发层长表的指定label分区中。

并过滤掉无意义的数据:

  1> 在宽表中为null值的字段,经过列转行后生成的指标名为null的记录。

  2> 字段值本身为空字符串'',或字段值只包含多个空格的记录

3.基于过滤后的数据,统计任务生成的指标覆盖了多少主键,并记录下更新时间,插入日志表中。

相关文章

  • 长表开发模式样例

    三段式开发: 一、开头 ====step:0==== drop table if exists platform_...

  • HTML

    CSS(Cascading Style Sheets) 层叠式样式表,又称级联式样式表 ,简称样式表。 HTML...

  • 2018-10-31接口测试&接口测试用例

    学习内容 接口测试用例式样

  • 《商业模式新生代》读书笔记(二)

    式样:建筑中的式样就是将原型和原型的再现抽象为建筑设计的概念。 五个商业模式式样: 非绑定式商业模式 长尾式商业模...

  • 单例模式的优势比较

    单例模式的优势比较: 单例模式各种实现方式样例:https://github.com/iluwatar/java-...

  • CSS

    CSS, Cascading Style Sheets, 层叠式样式表。 语法 外部样式表(External St...

  • CSS的加载方式及其使用方法

    CSS (cascading style sheets):层叠样式表,又称级联样式表、串接样式表、阶层式样式表,一...

  • word论文排版常用方法技能

    这里以word2016版为例,内容包括: 设置显示“导航窗口” 设置“显示所有格式标记” 创建格式样式 导入格式样...

  • CSS

    1、css样式一共3中使用方法 ——内联式样式表 行样式 只能操作1个标签,细节灵活 ——嵌入式样式表 div{c...

  • (一)Android中的单例模式

    作为一个Android开发的老司机,或者刚入行的司机,我觉得你还是有必要学习下Android的单例模式,毕竟单例模...

网友评论

      本文标题:长表开发模式样例

      本文链接:https://www.haomeiwen.com/subject/rongoctx.html