Thursday, May 8, 2014

hive命令

hive命令:
1、创建表:
create external table beifen_rld (userid BIGINT)
partitioned by (data_date STRING)
row format delimited
fields terminated by '\t'
stored as textfile;

hive> create external table user_click_stat (userid BIGINT, winfoid BIGINT, charge double, click BIGINT, wordid BIGINT)
    > partitioned by (data_date STRING)
    > row format delimited
    > fields terminated by '\t'
    > stored as textfile;

2、增加partition:
alter table beifen_pld add partition (data_date=20140318)
location '/beifen_pld/20140318';

hive> alter table user_click_stat add partition (data_date = 20140505)                  
    > location '/user_click_data/20140505';

3、查询并插入:
from
    ( from beifen_pld select * where data_date='$date') tmp
        insert overwrite table beifen_rld partition(data_date='$date')
select userid;

hive> from
    > ( from user_click_stat select userid, count(winfoid) as winfoid_num, sum(charge) as charge, sum(click) as click
    > where data_date='20140505' group by userid) tmp
    > insert overwrite table user_click_sum partition(data_date = '20140505')
    > select *;



No comments:

Post a Comment