如何修改hive的分割槽
hive讀寫模式:
hive分割槽的意義是避免全表掃瞄,從而提高查詢效率。預設使用全表掃瞄。
[partitioned by (columnname columntype [comment 'column comment'],
...)
]
1、hive的分割槽名區分大小寫
2、hive的分割槽欄位是乙個偽欄位,但是可以用來進行操作
3、一張表可以有乙個或者多個分割槽,並且分割槽下面也可以有乙個或者多個分割槽。
4、分割槽字段使用表外字段
分割槽的方式:使用日期、地域等方式將資料分散開
分割槽的本質:在表的目錄或者是分割槽的目錄下再建立目錄,分割槽的目錄名為指定字段=值(比如:dt=2019-09-09)
create table if not exists part1(
id int,
name string
)partitioned by (dt string) row format delimited fields terminated by ' '
;
載入資料
load data local inpath '/home/hivedata/t1' overwrite into table part1 partition(dt='2019-09-09');
load data local inpath '/hivedata/user.txt' into table part1 partition(dt='2018-03-20'
);
查詢語句
select
*from part1 where dt='2018-03-20'
create table if not exists part2(
id int,
name string
)partitioned by (year int,month int) row format delimited fields terminated by ' '
;
載入資料
load data local inpath '/home/hivedata/t1' overwrite into table part2 partition(year=2019,month=9)
;load data local inpath '/home/hivedata/t' overwrite into table part2 partition(year=2019,month=10)
;
查詢語句
select
*from part2 where year=2019 and month=10;
show partitions 表名;
alter table part1 add partition(dt='2019-09-10');
alter table part1 add partition(dt='2019-09-13'
) partition(dt='2019-09-12');
alter table part1 add partition(dt='2019-09-11'
) location '/user/hive/warehouse/qf1704.db/part1/dt=2019-09-10'
;
alter table part1 partition(dt='2019-09-10'
) rename to partition(dt='2019-09-14'
);
--錯誤使用
alter table part1 partition(dt='2019-09-14'
)set location '/user/hive/warehouse/qf24.db/part1/dt=2019-09-09'
;--正確使用,決對路徑
alter table part1 partition(dt='2019-09-14'
)set location 'hdfs://hadoo01:9000/user/hive/warehouse/qf24.db/part1/dt=2019-09-09'
;
alter table part1 drop partition(dt='2019-09-14');
alter table part1 drop partition(dt='2019-09-12'
),partition(dt='2019-09-13'
);
靜態分割槽:載入資料到指定分割槽的值。
動態分割槽:資料未知,根據分割槽的值來確定需要建立的分割槽。
混合分割槽:靜態和動態都有。
set hive.exec.dynamic.partition=true
set hive.exec.dynamic.partition.mode=strict/nonstrict
set hive.exec.max.dynamic.partitions=1000
set hive.exec.max.dynamic.partitions.pernode=100
strict:嚴格模式必須至少乙個靜態分割槽
nostrict:可以所有的都為動態分割槽,但是建議盡量評估動態分割槽的數量。
使用案例:
create table dy_part1(
id int,
name string
)partitioned by (dt string)
row format delimited fields terminated by ' ';
load data local inpath '/home/hivedata/t1' overwrite into table dy_part1 partition(dt='2019-09-09');
set hive.exec.mode.local.auto=true;
insert into table dy_part1 partition(dt)
select
id,name,
dtfrom part1;
混合分割槽:
create table if not exists dy_part2(
id int,
name string
)partitioned by (year int,month int)
row format delimited fields terminated by ' '
;set hive.exec.mode.local.auto=true;
set hive.exec.dynamic.partition.mode=strict;
insert into table dy_part2 partition(year=2019,month)
select
id,name,
month
from part2
where year=2019
;
hive.mapred.mode
nonstrict
the mode in which the hive operations are being performed.
in strict mode, some risky queries are not allowed to run. they include:
cartesian product.
no partition being picked up for a query.
comparing bigints and strings.
comparing bigints and doubles.
orderby without limit.
set hive.mapred.mode=strict;
select
*from dy_part1 d1
join dy_part2 d2
;
set hive.mapred.mode=strict;
select
*from dy_part1 d1
where d1.dt='2019-09-09';
不行select
*from dy_part1 d1
where d1.id > 2
;select
*from dy_part2 d2
where d2.year >= 2019
;
select
*from log3
order by id desc
;
(bigint和string比較)comparing bigints and strings.
(bigint和double比較)comparing bigints and doubles.
hive是乙個嚴格的讀時模式。 寫資料不管資料正確性,讀的時候,不對則用null替代。
mysql是乙個的寫時模式。 寫的時候檢查語法,不okay就會報錯。
load data local inpath '/home/hivedata/t' into table t_user;
insert into stu(id,***) value(1,abc)
;
hive修改 表 分割槽語句
新增分割槽 alter table table name add partition partcol value1 location loc1 示例alter table table name add if not exists partition dt 20130101 location user...
hive 分割槽 hive 分割槽概念 0323
1 hive 分割槽表 在hive select查詢中一般會掃瞄整個表內容,會消耗很多時間做沒必要的工作。有時候只需要掃瞄表中關心的一部分資料,因此建表時引入了partition概念。分割槽表指的是在建立表時指定的partition的分割槽空間。hive可以對資料按照某列或者某些列進行分割槽管理,所...
HIVE動態分割槽
一 前段時間因為導表需求 從一張表中查詢出資料,按日期分割槽overwrite 到指定分割槽表中 在hive裡面研究了一下自動分割槽。步驟 1 建好所需分割槽表 2 設定分割槽引數?1 2 3 4 sethive.exec.dynamic.partition true 可通過這個語句檢視 sethi...