幸运28源码下载hive数据分析

最近在参与某toB项目,幸运28源码下载Q2152876294 论坛:diguaym.com
数据需离线统计出并推送至线上业务库,其中用hive做的离线分析。总结写下常见问题及心得吧。

一.流程类工作简介:数据统计工作主要分为四个步骤:指标统计、批量脚本、数据格式、异常流程;

step1. 指标统计:通过创建表存储每个指标的值,例如用hive表loan_apply_rate存储申请通过率;复杂度在于:指标值多,且指标定义可能不明确;

step2. 批量脚本:将step1创建的各张表综合成批量执行的perl脚本;复杂度在于:若执行时间长,会影响业务方使用,可自行迭代出大小适中的perl脚本;

step3.数据格式:新建一张总表,该表存储所有的指标值;并且将step2生成的表转化成业务方期望的数据格式。示例如下:

step4.异常流程:包括批量脚本父子任务执行顺序异常,今日统计的数据异常时数据回滚或重新统计等,数据去重以及数据备份等;

二.hive统计遇到的问题和常见函数

1.指定为月末:两种方案:

 1.1.case

when split(statistics_date,'-')[1] in ('1','3','5','7','8','10','12') then concat(statistics_date,'-31')
when split(statistics_date,'-')[1] in ('4','6','9','11') then concat(statistics_date,'-30')
when cast(split(statistics_date,'-')[0] as int)%4=0 and split(statistics_date,'-')[1] in ('2') then concat(statistics_date,'-29')
when cast(split(statistics_date,'-')[0] as int)%4!=0 and split(statistics_date,'-')[1] in ('2') then concat(statistics_date,'-28')

end as new_statistics_date

1.2. date_sub(concat(substr(concat(substr(created_date, 1, 7), '-01'), 1, 7), '-01'), 1)

2.常用函数:instr; months_between; select row_number()over(partition by cash_id order by modified_date desc) as rn

from table_a;collect_set/collect_list(得到的是array<String>类型);clollect_ws可以合并collect_set(如collect_ws(',',collect_set()))

猜你喜欢

转载自blog.51cto.com/13943056/2165343
今日推荐