Hive----建表,删除数据,添加数据

1.Hive的直连数据库(mysql)模式
最常用的模式
2.Hive数据类型(data_type)
**基本类型(primitive type):**与mysql相同
array_type: Array<data_type>
map_type: MAP < primitive_type, data_type >
**struct_type:**STRUCT < col_name : data_type [COMMENT col_comment], …>

在这里插入图片描述
3.内部表和外部表
内部表:CREATE TABLE [IF NOT EXISTS] 表名
对于内部表,元数据与表中的数据都会被删除
外部表:CREATE EXTERNAL TABLE [IF NOT EXISTS] 表名 LOCATION hdfs路径
对于外部表,删除表时只会删除元数据,不会删除hdfs 的数据

4.Hive建表
create table person(
id int comment ‘主键’,
name string comment ‘名字’,
interest array comment ‘爱好’
)

row format delimited
fields terminated by “,” //字段之间
collections terminated by “-” //集合元素之间
map keys terminated by “:”
lines terminated by “\n”; //行与行之间

5.表分区
单分区:create table day_table (id int, content string) partitioned by (day string);
按天分区,在表结构中存在int,content,day三列
双分区:create table day_hour_table (id int, content string) partitioned by (day string, hour string);
按天和小时分区,在表结构中新增加了 day和hour两列

6.删除数据
truncate from person where id=1
无法使用delete 删除数据
7.添加数据
(1)加载文件load
load:(可以copy/move)

LOAD DATA INPATH 文件路径 INTO TABLE 表名

copy:load的是本地的数据
move:load的是hdfs上的文件,不适用local

(2)insert
适用于将大表中的数据拆分到小表中
insert overwrite 表示覆盖
insert into 表示追加

create table person2_1(
id int,
name string
);

create table person2_2(
id int,
likes array
);

from person
insert overwrite table person2_1
select id,name
insert into person2_2
select id,likes;

person表中一些列的数据添加到person2_1中,将另外一些列的数据添加到person2_2中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值