HiveQL:数据操作(四)

向管理表中加载数据:

hive> load data local inpath '/home/zkpk/test' overwrite  into table testpar partition (day='0925');//0925分区内的数据会先删除

 

通过查询语句向表中插入数据:

hive> insert into table testpar

    > partition (day='0926')

    > select * from test;

 

hive> select * from testpar;

 

hive> insert into table testpar

    > partition (day='0922')

    > select * from test

    > where age >20;

 

hive> from test

    > insert into table testpar

    > partition (day='0921')

    > select * where age>22;

 

hive> from test ts

    > insert into table testpar

    > partition (day='0920')

    > select * where ts.age>20

    > insert into table testpar

    > partition (day='0919')

    > select * where ts.name='张三';

 

===动态分区插入====

在test表中添加一列day

hive> alter table test add columns(day string);

 

[zkpk@master ~]$ vi test

[zkpk@master ~]$ cat test

1 张三 20 0921

2 李四 22 0922

3 Jarrey 25 0923

加载数据:

hive> load data local inpath '/home/zkpk/test' overwrite into table test;

动态分区(下面两种方式实现的效果是一样的):

hive>  set hive.exec.dynamic.partition=true;

hive>  set hive.exec.dynamic.partition.mode=nonstrict;

hive>  set hive.exec.max.dynamic.partitions.pernode=1000;

 

hive> insert into table testpar

    > partition(day)

    > select * from test;

 

hive> insert into table testpar

    > partition(day)

    > select id,name,age,day from test;

 

单个查询语句中创建表并加载数据:(注意关键字as)

hive> create table newtest

    > as select id,name,age from test

    > where name='李四';

 

hive> select * from newtest;

 

=======导出数据==========

hadoop fs –cp source_path target_path

cp

scp -r /jdk  slave://home/zkpk/

 

Sqoop工具(T15)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值