Hive常用分割槽操作命令20180805

2021-08-22 07:18:35 字數 2297 閱讀 5247

環境:hadoop-2.7 , hive 2.1

操作hive資料倉儲中的表有個前提,就是被操作的表必須是有分割槽的。需要在建表的時候指定分割槽,具體如何建立有分割槽的表,請看我的另一篇文章 《在hive中建立分割槽表,再關聯到hdfs有關位置,而不需匯入資料到hive表》

for d in 「4 5」; do hive -e 「alter table machine_logs.uniform_id add if not exists partition (dt=『2018-08-0$d』)」;echo ------ ; done

logging initialized using configuration in file:/etc/hive/2.5.0.0-1245/0/hive-log4j.properties

oktime taken: 3.087 seconds

------

[root@gn-386277d7-master-1-001 ~]# hive -e "show partitions gz_logs.uniform_payment;"

… (省略)

dt=2018-07-29

dt=2018-07-30

dt=2018-07-31

dt=2018-08-01

dt=2018-08-02

dt=2018-08-03

dt=2018-08-04 5

hive -e "alter table gz_logs.uniform_payment drop if exists partition (dt='2018-08-04 5')"

logging initialized using configuration in file:/etc/hive/2.5.0.0-1245/0/hive-log4j.properties

dropped the partition dt=2018-08-04 5

oktime taken: 4.271 seconds

[root@gn-386277d7-master-1-001 ~]# hive -e "alter table gz_logs.uniform_payment add if not exists partition (dt='2018-08-04')"

logging initialized using configuration in file:/etc/hive/2.5.0.0-1245/0/hive-log4j.properties

oktime taken: 2.624 seconds

[root@gn-386277d7-master-1-001 ~]# hive -e "alter table gz_logs.uniform_payment add if not exists partition (dt='2018-08-05')"

logging initialized using configuration in file:/etc/hive/2.5.0.0-1245/0/hive-log4j.properties

oktime taken: 3.022 seconds

…(省略)

dt=2018-07-29

dt=2018-07-30

dt=2018-07-31

dt=2018-08-01

dt=2018-08-02

dt=2018-08-03

dt=2018-08-04

dt=2018-08-05

前面都是單獨新增乙個分割槽的,批量修復表的歷史分割槽使用msck

在hive shell中使用msck repairt table db_name.table_name;

或者在linux命令列使用hive –e 「msck repairt table db_name.table_name;」

或者,某個表有多個分割槽,分割槽對應到hdfs目錄層次為 /pid/cid/dt

# 分別為此表pid為00、10、20...90且cid=5 新增7月1號和2號的分割槽,例如/20/cid=5/dt=2018-07-01

for p in

do hive -e "alter table orders.active add if not exists partition (pid=$p, cid='5', dt='2018-07-01');

alter table dawn_v3.stat_active add if not exists partition (p=$p, cid='5', dt='2018-07-02');"

done

Hive常用操作命令

建立資料庫 create database db name create database if not exists db name 建立乙個不存在的資料庫final 檢視資料庫 show databases 選擇性檢視資料庫 show databases like f.檢視某乙個資料庫的詳細資訊...

Hive操作表分割槽

建立分割槽表語句,使用關鍵字partition a 單分割槽建表語句 create table table name id int,content string partitioned by dt string 單分割槽表,按天分割槽,在表結構增加了dt列。以dt為資料夾區分 b 雙分割槽建表語句 ...

hive 二 hive常用命令操作

三 常用命令 四 常用資料型別 這節將介紹hive常用命令操作,包括資料庫操作 表操作 資料操作等。hive的採用了類sql的語法,也稱為hql。2.1 以互動方式執行命令bin hive此時可以在命令列中輸入set hive.cli.print.current.db true 可以顯示當前選中資料...