Hive表分区

新建一个有一个分区dt的表baseinfo。

hive> create table baseinfo(
    > id int,
    > name string
    > )partitioned by (dt string) row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile; 
OK
Time taken: 0.132 seconds

在linux下面建立一个文件/baseinfo.txt,文件内容为

1    qiu

2    liu

将文件中的内容导入baseinfo表中,设置分区的值为当前日期'2014-03-03'。

hive> load data local inpath '/baseinfo.txt' overwrite into table baseinfo partition(dt = '2014-03-03');
Copying data from file:/baseinfo.txt
Copying file: file:/baseinfo.txt
Loading data to table hbmsdb.baseinfo partition (dt=2014-03-03)
Deleted hdfs://hadoop00:9000/user/hive/warehous/hbmsdb.db/baseinfo/dt=2014-03-03
OK
Time taken: 0.442 seconds

在linux下面建立一个文件/baseinfo2.txt,文件内容为

3 zheng

4 yang

将文件中的内容导入baseinfo表中,设置分区的值为当期日期‘2014-03-04’。

hive> load data local inpath '/baseinfo.txt' overwrite into table baseinfo partition(dt = '2014-03-04');                                                      
Copying data from file:/baseinfo.txt
Copying file: file:/baseinfo.txt
Loading data to table hbmsdb.baseinfo partition (dt=2014-03-04)
OK
Time taken: 0.189 seconds

查看分区

hive> show partitions baseinfo;                                                                         
OK
dt=2014-03-03
dt=2014-03-04
Time taken: 0.054 seconds

 查看数据

hive> select * from baseinfo;
OK
1       qiu     2014-03-03
2       liu     2014-03-03
3       zheng   2014-03-04
4       yang    2014-03-04
Time taken: 0.141 seconds
hive> select * from baseinfo where dt = '2014-03-03';
OK
1       qiu    2014-03-03
2       liu    2014-03-03
Time taken: 0.149 seconds


通过查询将内容保存在本地文件系统上

hive> insert overwrite  local directory '/home/hive' select * from baseinfo;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值