Hive是建立在 Hadoop 上的数据仓库基础构架。它提供了一系列的工具,可以用来进行数据提取转化加载(ETL),这是一种可以存储、查询和分析存储在 Hadoop 中的大规模数据的机制。
在CLI下的测试:
1.创建表结构 ,一下hql放到一个文件夹下下文件名:adl_en_list_fdt0.sql
CREATE TABLE adl_en_list_fdt0
( stat_date string COMMENT '统计时间'
,member_id string COMMENT '账号'
,company_id bigint COMMENT '公司ID'
)
COMMENT ‘会员表'
PARTITIONED BY(hp_stat_date STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\005'
STORED AS SEQUENCEFILE;
alter table adl_en_list_fdt0 add partition (hp_stat_date='2012-09-01');
alter table adl_en_cust_cgs_diag_fdt0 add partition (hp_stat_date='2012-09-02');
alter table adl_en_cust_cgs_diag_fdt0 add partition (hp_stat_date='2012-09-03');
执行hive -f adl_en_list_fdt0.sql 则表创建
2.查看表结构、分区、数据
查看表结构:DESCRIBE adl_en_list_fdt0
查看分区:SHOW PARTITIONS adl_en_list_fdt0
查看2012-09-02分区数据:select count(*) from adl_en_list_fdt0 where hp_stat_date = '2012-09-02' ;
3.数据准备。
在oralce中创建表membertest , 表结构和hive上的表结构一样。
将oracle上的数据导入hive上,用hivetools工具
每次修改修改oracle上的数据,覆盖掉hive上原有的数据。
4. 执行目标表的perl脚本,将perl脚本放到文件夹下, tdl_en_diag_fdt0_tmp0.pl 中
$sql_comment = "insert overwrite table tdl_en_diag_fdt0_tmp0 .pl";
$sql=" insert overwrite table tdl_en_diag_fdt0_tmp0
SELECT a.company_id
,case when a.service_type_id in ('cgs','twgs','hkgs') THEN 'cgs' else 'tp' end as service_type_id
,b.reply_in72h_ab_30d_rate
FROM idl_en_basic_fdt0_h a
left outer join adl_eff_itera_fb_fdt0 b
on a.company_id = b.company_id
and b.hp_stat_date = '".$l_stat_date."'
where a.hp_dw_end_date > '".$l_stat_date."'
and a.dw_begin_date <= '".$l_stat_date."'
and a.is_admin = '1'
and a.member_status = 'enabled'
and a.company_id is not null
and a.admin_member_id is not null
;";
执行:perl tdl_en_diag_fdt0_tmp0 .pl d "to_date('20120630','yyyymmdd')"