hive基础操作

1:创建普通表

drop table telephonedata;
create table IF NOT EXISTS telephonedata(
telephone string,
upPackageNum int,
updata int,
downPackageNum int,
downdata int
)
row format delimited fields terminated by ‘\t’ stored as textfile;

load data inpath ‘/dtable/telephonedata_log2.log’ overwrite into table telephonedata;

select * from telephonedata limit 1000;

SELECT T.* FROM (SELECT TELEPHONE,SUM(UPPACKAGENUM) UPPACKAGENUM,SUM(UPDATA) UPDATA,SUM(DOWNPACKAGENUM) DOWNPACKAGENUM,SUM(DOWNDATA) DOWNDATA FROM TELEPHONEDATA GROUP BY TELEPHONE) T ORDER BY DOWNDATA DESC;

2:创建外部表

drop table telephoneext;
create external table td_ext(
telephone string,
uppackagenum int,
updata int,
downpackagenum int,
downdata int
)
row format delimited fields terminated by ‘\t’ stored as textfile
location ‘/user/table/telephonedata’;

3:创建分区表

create table test_partition (id int,name string,no int)partitioned by (dt string) row format delimited fields terminated by ‘\t’ stored as textfile ;

load data local inpath ‘/test/partition1.txt’ overwrite into table test_partition partition (dt=’2016-05’);
load data local inpath ‘/test/partition2.txt’ overwrite into table test_partition partition (dt=’2016-06’);

select * from test_partition where dt=’2016-06’;
select count(1) from test_partition where dt=’2016-06’;

4:保存处理后的数据

create table sel_table as
SELECT T.* FROM (SELECT TELEPHONE,SUM(UPPACKAGENUM) UPPACKAGENUM,SUM(UPDATA) UPDATA,SUM(DOWNPACKAGENUM) DOWNPACKAGENUM,SUM(DOWNDATA) DOWNDATA FROM TELEPHONEDATA GROUP BY TELEPHONE) T ORDER BY DOWNDATA DESC;

5:导出到本地文件系统

insert overwrite local directory ‘/test/sel_table’
select * from sel_table;

6:导出到HDFS中

insert overwrite directory ‘/test/sel_table’
select * from sel_table;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值