HIve学习:Hive分区修改
生活随笔
收集整理的這篇文章主要介紹了
HIve学习:Hive分区修改
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
文章目錄
- 什么是Hive的分區
- 分區意義
- 分區技術
- 分區方法和本質
- 創建一級分區表
- 創建二級分區表
- 如何修改Hive的分區
- 查看分區
- 添加分區
- 分區名稱修改
- 修改分區路徑
- 刪除分區
- 分區類別
- hive的嚴格模式
- 笛卡爾積
- 分區表沒有分區字段過濾
- order by不帶limit查詢
- bigint和string比較
- bigint和double比較
- 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;如何修改Hive的分區
查看分區
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');分區類別
靜態分區:加載數據到指定分區的值。
動態分區:數據未知,根據分區的值來確定需要創建的分區。
混合分區:靜態和動態都有。
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, dt from 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的嚴格模式
<property><name>hive.mapred.mode</name><value>nonstrict</value><description>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.</description></property>笛卡爾積
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 ;order by不帶limit查詢
select * from log3 order by id desc ;bigint和string比較
(bigint和string比較)Comparing bigints and strings.bigint和double比較
(bigint和double比較)Comparing bigints and doubles.hive讀寫模式:
Hive是一個嚴格的讀時模式。 寫數據不管數據正確性,讀的時候,不對則用NULL替代。
mysql是一個的寫時模式。 寫的時候檢查語法,不okay就會報錯。
總結
以上是生活随笔為你收集整理的HIve学习:Hive分区修改的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kafka笔记:kafka原理简介以及架
- 下一篇: 2020年终总结一下吧