Hive crud

 hadoop fs -put test.data /user/hive/warehouse/test.db/lzq

将数据放到表中,这种表在warehouse中的被称为内部表

而外部表可以存放在hdfs的任意位置

在mysql中存放的是其元数据,创建的sql语句表信息等


create table xxx(id int,name string)

row format delimited 以一行为分割

fields terminated by ',' ;字段以什么分割


create external table ext(id int,name string)

row format delimited

fields terminated by '\t'

stored as textfile

location '/lz'

创建外部表

查看表desc extended ext 详细查看

desc formatted ext;更美观的查看


//加载本地文件到数据库表中

hive>  load data local inpath '/root/test2.data' into(overwrite) table ext;

hive> dfs -ls /; 可查看dfs

内部表和外部表的区别是,drop table xx

内部表数据会被删除,而外部表数据则不会被删除



//创建分区表

create table sz(id int,name string)

partitioned by (conutry string ) //根据什么分区,此字段不可在用原表中的

row format delimited

fields terminated by ',' ;

 load data local inpath '/root/test.data' into table sz partition(country='ch'); //表示以ch为一个分区

load data local inpath '/root/test2.data' into table sz partition(country='ja')//

altertable sz add partition(count='us');

alter table sz drop partition(count='us');

show partitions sz;

表示以ja分区

查询发现分以两个目录存放 count=ch


select * from sz;会把所有的数据查询出来,包括伪字段,country



保存select查询结果的几种方式

1 将结果保存到一张新的hive表中

create table t_tmp

as

select * from t_p;

2将结果保存到一张已经存在的hive表中

insert into t_tmp

select * from t_p;

3将结果保存到制定文件目录(可以是本地可以是hdfs)

insert overwrite local directory 'xxx'  必须是overwrite into会报错

select * from p;


load或是insert 加上local是本地,不加默认是hdfs


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值